11/26/96, 4Fax #2480 Why Numbers From "du -sk" and "df" Disagree Special Notices Information in this document is correct to the best of our knowledge at the time of this writing. Please send feedback by fax to "AIXServ Information" at (512) 823-4009. Please use this information with care. IBM will not be responsible for damages of any kind resulting from its use. The use of this information is the sole responsibility of the customer and depends on the customer's ability to evaluate and integrate this information into the customer's operational environment. About This Document This document describes why numbers from "du -s" and "df" Disagree and is applicable to AIX version 3.2, 4.1 and 4.2. On AIX versions prior to 4.1 df reports its statistics in 1024 byte units and du reports in 512 byte units. On AIX 4.1 and later both df and du default to 512 byte units. The following discussion uses 4.1.2 df and du thus all units are in 512-byte blocks. THE PROBLEM When you execute "du -s /filesystem_path" and subtract this value from the total block count as reported by df to get a free block value, the calculation yields a value that is greater than df's free block value. For example: % du -s /tmp 12920 /tmp % df /tmp Filesystem 512-blocks Free %Used Iused %Iused Mounted on /dev/hd3 57344 42208 26% 391 4% /tmp - = 57344 - 12920 = 44424 44424 is greater than 42208. The reason for this discrep- ancy has to do with the implementation of du and df. DU -SK du -sk transverses the file tree adding up the number of blocks allocated to each directory, symlink, and file as reported by the stat() system call. This is how du arrives at its total value. DF df looks at the file system disk block allocation maps to arrive at its total and free values. WHY THE NUMBERS DO NOT ADD UP The file system allocates some of the disk blocks in the file system to record its data; this data is referred to as meta data. Meta data is not visible to most user level pro- grams. Examples of meta data are inodes, disk maps, indirect blocks, and super blocks. du is an example of a user level program that is not aware of file system meta data. While df looks at the file system disk allocation maps, and is aware of file system meta data. df obtains the true file system statistics whereas du only sees a partial picture. For example, an empty 4 MB JFS file system created with frag=4096 and nbpi=4096 has the fol- lowing meta data allocated: 1 4k block for the LVM 2 4k super blocks 2 4k blocks for disk maps 2 4k blocks for inode maps 2 4k blocks for .indirect 32 4k blocks for inodes ------------------------- 41 4k blocks for meta data on an empty 4M file system # df /foo 8 /foo The 8 512 byte blocks reported for du on this empty file system are the blocks used by the root directory. In order to get du's output to match df's output we must add in the meta data. First, convert 42 4K blocks to 512 byte units: 41 * 8 = 328 328(meta data) + 8(from du) = 336 so there are 336 512-byte blocks allocated on this empty file system, thus: 8192(total blocks) - 336(used from du + meta data) = 7856 This does match the output from df's free column. This cal- culation was easy to perform on an empty file system. However, on a non-empty file system, the meta data for file indirect blocks comes into play and such calculations are very tedious and impractical. In conclusion du -s produces a value that reflects the number of disk blocks that are allocated to file and direc- tories. df reports on the actual allocation state of the file system. The true allocation state includes both user data (files and directories) plus meta data. Reader's Comments Please fax this form to (512)823-4009, attention "AIXServ Information". Use this form to tell us what you think about this document. If you have found errors in it, or if you want to express your opinion about it ( such as organization, subject matter, appearance) or make suggestions for improvement, this is the form to use. If you need technical assistance, contact your local branch office, point of sale, or 1-800-CALL-AIX (for information about support offerings). These services may be billable. Faxes on a variety of subjects may be ordered free of charge from 1-800-IBM-4FAX. Outside of U.S call 415-4539 using a fax machine phone. When you send comments to IBM, you grant IBM a nonexclusive right to use or distribute your comments in any way it believes appropriate without incurring any obligations to you. Note: If you have a problem report or item number, supplying that number may help us determine why a procedure did or did not work in your specific situation. Problem Report or Item #: Branch Office or Customer #: Be sure to print your name and fax number below if you would like a reply: Name: Fax Number: _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ _________________________________________________________________________________ END OF DOCUMENT (diff.between.du.df.cmd, 4Fax # 2480)