Re: Any clue why "df -m" vs. "du -xsAm" get such different results for the tmpfs in question (403 MiBytes vs. 101 MiBytes)?

From: Stefan Esser <se_at_FreeBSD.org>
Date: Thu, 09 Jun 2022 08:23:00 UTC
Am 08.06.22 um 21:54 schrieb Mark Millard:
> # df -m | egrep "(^Filesystem|^tmpfs)"
> Filesystem   1M-blocks   Used  Avail Capacity  Mounted on 
> tmpfs             1024    403    620    39%    /usr/local/poudriere/data/.m/main-CA7-bulk_a-default

> So the comparison is with the line that lists Used as 403 (MiBytes):

> # du -xsAm /usr/local/poudriere/data/.m/main-CA7-bulk_a-default/ref/.p
> 101	/usr/local/poudriere/data/.m/main-CA7-bulk_a-default/ref/.p

> # du -xsm /usr/local/poudriere/data/.m/main-CA7-bulk_a-default/ref/.p
> 68	/usr/local/poudriere/data/.m/main-CA7-bulk_a-default/ref/.p

> Why 403 vs. 101 ?

Hi Mark,

have you checked for unlinked but still open files on that tmpfs?

My quick test with /tmp on tmpfs did not show any anomalies:

# du -xsm /tmp
730	/tmp

# df -m /tmp
Filesystem 1M-blocks Used Avail Capacity  Mounted on
tmpfs          16384  733 15650     4%    /tmp

I do not know of a simple way to check for blocks allocated by files
that are open but have been unlinked, though. (I did not get any usable
results from lsof, fstat, and pstat - may  be I have missed a tool that
grabs that information from the kernel.)

The best I could get is this pstat output:

se       sleep      89643 text /         25349 -r-xr-xr-x    8592  r
se       sleep      89643 ctty /dev        157 crw--w----   pts/0 rw
se       sleep      89643   wd /tmp          2 drwxrwxrwt   51584  r
se       sleep      89643 root /             4 drwxr-xr-x      47  r
se       sleep      89643    0 /dev         67 crw-rw-rw-    null  r
se       sleep      89643    1 -        137245 -rw-r--r--       5  w
se       sleep      89643    2 /dev        157 crw--w----   pts/0 rw

This is for a sleep with stdout redirected to a file on tmpfs and the
file then deleted while the sleep command has it open. As long as it
had not been deleted, pstat showed that it resided in /tmp:

se       sleep      89643    1 /tmp     137245 -rw-r--r--       5  w


But you can compare the number of inodes reported by "df -i ." and
the number of files found by "find . | wc". Run these commands as root
in order to not miss files that are not accessible to a non-privileged
user ...

Regards, STefan