Debian – ext4 used space (not -m option, not deleted files)

debiandfdisk-usageext4linux

I'm a bit puzzled about the way ext4 reports used space. On a new Debian wheezy (testing) installation, I consistently got about 1GB extra space used with a 60GB SSD, when compared to du. I then network booted that computer and mounted the SSD. The network booted OS (Debian squeeze) shows only 180MB extra space used on the SSD. The journal is 128MB, so there's not much extra beyond that anymore.

What is the extra used space reported by df, when it's not space reserved for root or deleted files? Using Google mostly results in those usual causes, which I have ruled out. And why does that amount differ on the same filesystem when mounted on different operating systems? I tested this by re-installing, and the extra usage was again ~1GB on the wheezy installation, and 180MB when I network booted and mounted that SSD.

On XFS and btrfs, the extra reported usage seems negligible. I realize that the filesystem needs some overhead, but it's inconvenient when that overhead is mixed up with the real usage.

Here are some detailed outputs.

df

$ df -m on wheezy
Filesystem              1M-blocks  Used Available Use% Mounted on
rootfs                      57132  1567     52703   3% /
udev                         7899     0      7899   0% /dev
tmpfs                        1581     1      1581   1% /run
/dev/mapper/ssd-kvmhost     57132  1567     52703   3% /
tmpfs                           5     0         5   0% /run/lock
tmpfs                        3162     0      3162   0% /tmp
tmpfs                        3162     0      3162   0% /run/shm

du

$ du -sm /
592     /

tune2fs shows Inode count to be 3670016 and size 256, which indeed explains almost all of the used space. I just don't understand why this isn't subtracted from Size, since the inodes are statically reserved. Counting it as space and then always counting it as used doesn't make much sense.

Here's the output for the very same filesystem, from the network booted Debian squeeze:

aufs                      7905        46      7859   1% /
tmpfs                     7905         0      7905   0% /lib/init/rw
udev                      7900         1      7900   1% /dev
tmpfs                     7905         1      7905   1% /dev/shm
172.17.172.127:/storage/private/tftp/debian-live-6.0.3-amd64-lxde-desktop
                         24737     17448      7289  71% /live/image
tmpfs                     7905        46      7859   1% /live/cow
tmpfs                     7905         0      7905   0% /live
tmpfs                     7905         1      7905   1% /tmp
/dev/mapper/ssd-kvmhost
                         56337       772     52703   2% /mnt

And just for confirmation, du -sm / on the network booted OS:

592     /

Maybe the older kernel wisely doesn't count the statically reserved inode space as usable, and thus doesn't have to show it as used? The difference is 795MB in both Size and Used, almost all of the space needed for the inodes. What's the 180MB then? If that is also static, wouldn't it be optimal to also subtract that from Size? Then df could actually show real usage, like other filesystems seem to do.

The way I see it, if my filesystem needs a static amount of overhead, then it just provides less usable space than some other filesystems for the same amount of absolute space. Shouldn't df reflect that, and also show how much of the usable space I have used?

Best Answer

ext[234] by default reserves 8192 inodes per 128 mb block group, which takes 2mb, per group, which works out to close to 1gb for a 60 gb filesystem. There should be no difference when you mount the drive in another system. It looks like they may have changed the way the kernel reports used space between wheezy and squeeze, though I have not yet found a commit indicating this was done on purpose.

Related Question