Different behaviour running under strace?

Cameron Simpson cs at zip.com.au
Fri Mar 6 21:33:49 UTC 2015


On 05Mar2015 16:52, Tom Horsley <horsley1953 at gmail.com> wrote:
>On Fri, 6 Mar 2015 08:27:03 +1100
>Cameron Simpson wrote:
>
>>   - _after_ a fast straced df, is un unstraced df slow again?
>>     (thinking about cached answers to call, caches in the OS, possibly quite
>>     briefly)
>
>I was yesterday, but today the strace'ed version hung as well and I
>was able to find and unmount some slow filesystems.
>
>I don't know why "df -l" even stat()s an NFS mountpoint at all, it
>could certainly look at /proc/mounts and find the local only
>filesystems and utterly ignore the network systems, but
>it apparently doesn't do that (because I certainly see the stat
>calls when I strace it).

Interesting. The RHEL5 host I tested definitely did _not_ statfs() its NFS 
mounts when invoked with -l. Its df comes from coreutils-5.97.

NB: the RHEL5 one reads /etc/mtab (a regular file), not /proc/mounts.

>Judging from the strace it gathers all the info first, then
>formats it for output, so when it hangs, it prints nothing.

Charming. Sounds buggy to me.

[...] Ok, fetched coreutils 5.97 (RHEL5 version) and 8.23 (latest version).  
This diff in df.c is huge, so let's just look at the 8.23 version, which should 
be close to if not identical with Fedora.

The get_dev() call honours the -l flag, returning immediately without work if 
the -l is supplied. HOWEVER, the caller, filter_mount_list(), stat()s _every_ 
mount point regardless. That will be where your slowness is come from. There's 
even a comment near the top of filter_mount_list suggesting that they know it 
does excessive work.

So, yes, modern GNU df unconditionally stat()s all your mounted filesystems.

Suggestion: see if this:

  df /

stats only /. Repeat for other local filesystems as a test. Then write a tiny 
shell script for "df -l" that reads /etc/mtab and reports only non-NFS mounts.

Cheers,
Cameron Simpson <cs at zip.com.au>

Share your knowledge. It is a way to achieve immortality. - The Dalai Lama


More information about the users mailing list