3

I understand there's often a some discrepancy between du and df but when I du my ramdisk it occupies 13G, whereas df shows it's using 16GB. This seems quite a big difference. Is this normal?

[root@zserver2 ramdisk]# du -h .
...
13G .

[root@zserver2 ramdisk]# df -h
Filesystem            Size  Used Avail Use% Mounted on
...
none                   16G   16G     0 100% /home/stuff/ramdisk

The ramdisk is defined in fstab and defaults to 50% of my 32GB ram:

# cat /etc/fstab
...
none             /home/stuff/ramdisk   tmpfs   mode=774,uid=500,gid=501  0     0
Ian
  • 311

2 Answers2

4

Most likely some files were deleted from the ramdisk while some processes still have an open filehandle on them. An easy way to check this is with lsof /home/stuff/ramdisk, files that are open but no longer on the filesystem will be marked with '(deleted)'.

For example here I deleted the file '/dev/shm/test', while it is still opened by a python script:

% df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
shm             512M  257M  256M  51% /dev/shm
% du -h /dev/shm
84K    /dev/shm
% lsof /dev/shm
COMMAND     PID     USER   FD   TYPE DEVICE  SIZE/OFF  NODE NAME
[...]
python    39756 adaephon    5r   REG   0,13 268435456 44790 /dev/shm/test (deleted)
Adaephon
  • 4,456
0

you could

  • have files that were deleted on the ramdisk, but are still opened by some processes or threads ? [once those process/threads exit, the OS will really free those inodes and thus df will report 3gb less than before]

  • have lots of things in a directory/file not reachable by du ? [paranoid ? could be some rootkit or hidden nastyness ...]

and I'm sure there will be other possibilities popping in my head [ metadata on the filesystem? is it journalled? do you have LOTS of files ? does "du" ignore things in a "lost+found" directory or its equivalent on whatever FS you are using? etc.]

  • another possibility: a bug in "du -h" making it sum things with too much approximation (and if you have many files, discrepancy adds up) ? very unlikely though, du probably uses a sane algorithm ^^ – Olivier Dulac Nov 19 '13 at 20:37