output of cat /proc/sys/fs/inode-nr vs df -i
What's the difference between the output of
cat /proc/sys/fs/inode-nr
and
df -i
Both are documented at returning the number of inodes in use, but they return apparently unrelated numbers.
$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
devtmpfs 954448 464 953984 1% /dev
tmpfs 956943 1 956942 1% /dev/shm
/dev/xvda1 1310720 272395 1038325 21% /
/dev/xvdb1 1966080 26278 1939802 2% /tmp
tmpfs 956943 1 956942 1% /hdd1/mnt/data
$ cat /proc/sys/fs/inode-nr
199563 122925
Solution 1:
/proc/sys/fs/inode-nr
shows data about inodes in RAM (kernel cache), first currently allocated ones, and then free ones. The kernel uses inodes for many things, not just files. For example, network sockets are identified by inodes too.
See https://www.kernel.org/doc/Documentation/sysctl/fs.txt :
The file inode-nr contains the first two items from inode-state, so we'll skip to that file...
Inode-state contains three actual numbers and four dummies. The actual numbers are, in order of appearance, nr_inodes, nr_free_inodes and preshrink.
Nr_inodes stands for the number of inodes the system has allocated, this can be slightly more than inode-max because Linux allocates them one pageful at a time.
Nr_free_inodes represents the number of free inodes (?) and preshrink is nonzero when the nr_inodes > inode-max and the system needs to prune the inode list instead of allocating more.
df -i
shows inodes on disk, so whatever each filesystem manages to do with its specific set of inodes.
So both sets of numbers will always remain unrelated to each other.