bug-fileutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: df command bug


From: Bob Proulx
Subject: Re: df command bug
Date: Wed, 21 Apr 2004 22:41:04 -0600
User-agent: Mutt/1.3.28i

Elangovan Govindan wrote:
> I was just using df command and compared the result
> for / file system. Here is my analysis

Thank you for your report.  But I don't think what you are seeing is a
bug.  I think it is normal behavior due to the minfree value of the
filesystem.

> For e.g when you add Used and Available space for /
> file system and compare total ; it seems does not
> match. Also when Used percentage is calculated, it
> shows wrong result when calculated manualy.

Here is an example:

  df -l /mnt/a
  Filesystem           1k-blocks      Used Available Use% Mounted on
  /dev/sda8             61156396  31912492  26137340  55% /mnt/a

  echo '31912492+26137340' | bc -ql
  58049832  # non-system space

  echo '(61156396-58049832)' | bc -ql  
  3106564   # system reserved space

  echo '(61156396-58049832)/61156396' | bc -ql
  .05079704173542208079  # percentage of minfree, 5% in this case

I have a 5% minfree reserved for system use.  That will not show up as
available space.

When the filesystem is created 5%-10% of the total disk space will be
reserved by the filesystem as 'minfree'.  This is available only to
root processes and not to non-root processes.  The amount of minfree
is dependent upon the defaults of the particular mkfs.  You probably
have 5% unless you changed it.  Also some disk space will be used by
Inodes in some filesystems.  On others it is dynamic.

Secondly the 'df' command is just returning data from the statfs(2)
call.

    struct statfs {
       long    f_type;     /* type of filesystem (see below) */
       long    f_bsize;    /* optimal transfer block size */
       long    f_blocks;   /* total data blocks in file system */
       long    f_bfree;    /* free blocks in fs */
       long    f_bavail;   /* free blocks avail to non-superuser */
       long    f_files;    /* total file nodes in file system */
       long    f_ffree;    /* free file nodes in fs */
       fsid_t  f_fsid;     /* file system id */
       long    f_namelen;  /* maximum length of filenames */
       long    f_spare[6]; /* spare for later */
    };

So disk is usually total - minfree - inodes - free but the command
does not compute it.  The df command is just reporting what the
filesystem has precomputed for those values.

Also remember that when approaching a completely full disk the
performance of the filesystem can degrade exponentially.  It is then
difficult for the filesystem to find free disk blocks and won't be
able to automatically produce defragmented physical layout.  A small
percentage of minfree is required to ensure reasonable performance.  I
believe this plus ensuring root having a little extra when users
filled the disk were the original reasons for minfree.  It used to be
10% but has been reduced to 5% in recent years because of the much
larger disk capacity.

> Filesystem           1k-blocks      Used Available
> Use% Mounted on       Used  + Available = total     DF o/p
> /dev/ram0                62941     46582     13109 
> 79% /                         46582 + 13109  = 59691  NOT EQUAL TO ( df =
> 62941     )
> /dev/md0                101018     77689     18113 
> 82% /boot              77689 + 18113 = 95802  NOT EQUAL TO (df
> =  101018    )
> 
> /dev/ntvg/_opt_apps     519488    280852    238636 
> 55% /opt/apps         280852 + 238636  = 519488 EQUAL TO (df
> = 519488   )

Your mail came through so mangled that I could not make too much sense
of it.  Sorry.  But hopefully my explaination above made sense.  And I
will assume that is the issue you were reporting.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]