[CentOS] Disk usage for small files in ext3 in CentOS 5

Wed Mar 11 22:08:13 UTC 2009
Robert Nichols <rnicholsNOSPAM at comcast.net>

Filipe Brandenburger wrote:
> Hello,
> 
> I noticed something unusual today.
> 
> If I "du" a small file (couple of bytes) in CentOS 5, it tells me the
> file is using 8kb, while I was expecting 4kb which is the block size
> I'm using.
> 
> I tried this on several CentOS 5 machines, both x86_64 and i386:
> 
> $ echo test >test.txt
> $ ls -l test.txt
> -rw-rw-r-- 1 filbranden filbranden 5 Mar 11 17:24 test.txt
> $ du -h test.txt
> 8.0K	test.txt

Odd.  I'm not seeing this on CentOS 5.2:

   $ echo test >test.txt
   $ ls -ls test.txt
   4 -rw-rw-r-- 1 rnichols rnichols 5 Mar 11 16:57 test.txt
   $ du -h test.txt
   4.0K    test.txt
   $ stat test.txt
     File: `test.txt'
     Size: 5               Blocks: 8          IO Block: 4096   regular file
   Device: 341h/833d       Inode: 4325491     Links: 1
   Access: (0664/-rw-rw-r--)  Uid: (  500/rnichols)   Gid: (  500/rnichols)
   Access: 2009-03-11 16:57:18.000000000 -0500
   Modify: 2009-03-11 16:57:18.000000000 -0500
   Change: 2009-03-11 16:57:18.000000000 -0500
   $ df .
   Filesystem           1K-blocks      Used Available Use% Mounted on
   /dev/hdb1            487397840 320075816 142902824  70% /xstore
   $ su - -c "tune2fs -l /dev/hdb1" | egrep 'features|size'
   Password:
   Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery sparse_super large_file
   Block size:               4096
   Fragment size:            4096
   Inode size:               128

Everything exactly as expected.

-- 
Bob Nichols     "NOSPAM" is really part of my email address.
                 Do NOT delete it.