Why does `df` lie about free space

Jerry McAllister jerrymc at clunix.cl.msu.edu
Wed Mar 17 06:57:55 PST 2004


> 
>   That's an old problem, but yesterday I was working with 1.4G UFS2-slice 
> reported by `df` to have 400kb of free space. Alternative calculations (e.g. 
> writing a random file until kernel says no inode's free) give a result of 
> more that 100M (!) unused. Thats about 7% of the whole size!
>   That could a harmless bug, but some applications (PostgreSQL is!) uses 
> statfs to get free space info. Posetgres dies saying can't write his *.pid 
> cause FS is full (but it has 100M inodes free)...
>   So whats wrong with `df` (e.g. statfs/fstatfs)?

Nothing.  The thing that is wrong is that you do not understand disks.

Disk space and inodes are almost completely unrelated concepts.
If you look at the df man page, you might notice that if you
do a df -i it will report the number of inodes as well as the
amount of disk space.   Those are under columns labeled iused, ifree
and %iused.

Disk space is just that, the amount of disk storage used and available
but inodes are table entries.   When you originally newfs a file system
it creates a table with a certain number of entries.  One of those entries
is used for each file, directory and symlink that is created - no matter
how big the file is.  It is essentially a list of the files on the file
system along with a bit of information on how to find the file and dates
and such.   So, if you create a lot of tiny files, you are likely to run 
out of inodes long before you run out of space on the disk.  On the other 
hand, if you create even just one huge file, you could use just one inode 
and still use up all of the disk space.

In addition to this, there are things such as reserves and different
ways of measuring amounts of disk used that mean that different
utilities report disk usage somewhat differently.  

All of this is well documented in the handbook, various published FreeBSD 
guides, plus there are FAQs on it so better start studying before you go to 
claiming that something is not working correctly.

////jerry



More information about the freebsd-questions mailing list