views:

318

answers:

1

When I use the statvfs command on a Linux machine to get the available free space on a mounted file system, the number I get is slightly different than what is reported by df. Is there some reason for this?

For example, one on machine I have with a 500G hard drive, I get the following output from df:

# df --block-size=1 --no-sync
Filesystem           1B-blocks      Used Available Use% Mounted on
/dev/md0             492256247808 3422584832 463828406272   1% /
tmpfs                2025721856         0 2025721856   0% /lib/init/rw
varrun               2025721856    114688 2025607168   1% /var/run
varlock              2025721856      4096 2025717760   1% /var/lock
udev                 2025721856    147456 2025574400   1% /dev
tmpfs                2025721856     94208 2025627648   1% /dev/shm

A call to statvfs gives me a block size of 4096 and 119344155 free blocks, so that there should be 488,833,658,880 bytes free. Yet, df reports there are 463,828,406,272 bytes free. Why is there a discrepancy here?

+1  A: 

Since your discrepancy is close to 5% [1], which is the default percentage allocated for root, there is a possibility that you compare the df result with the ->f_bfree of statvfs and not with ->f_bavail, which is what df uses.

[1]: (488833658880 - 463828406272)/492256247808 = 0.0508

ynimous
Ahh...I see. Yes, using f_bavail the numbers are the same. Thanks a lot for the information.