All articles

Diagnose Linux inode exhaustion

5 minutes read


Linux publication

Share this article

𝕏✉

Illustration for Diagnose Linux inode exhaustion

No space left on device does not always mean the filesystem ran out of data blocks. Many filesystems also maintain a finite pool of inodes, the records used to represent files and directories. A workload that creates huge numbers of tiny files can exhaust that pool first.

Compare blocks and inodes

Run both views against the path that failed:

df -h -- /var/lib/app
df -i -- /var/lib/app
findmnt --target /var/lib/app

df -h reports space in human-readable units. df -i reports inode totals, usage, and availability instead. Supplying a path makes df report the filesystem containing that path.1

If block usage looks comfortable but IUse% is at or near 100 percent, file count is the likely constraint. findmnt confirms that you are investigating the intended filesystem rather than a parent mount.

See the counters move

This lab creates 200 empty files under a temporary directory:

lab=$(mktemp -d)
stat --file-system --format='free_blocks=%f free_inodes=%d' "$lab"

i=1
while [ "$i" -le 200 ]; do
  : > "$lab/file-$i"
  i=$((i + 1))
done

stat --file-system --format='free_blocks=%f free_inodes=%d' "$lab"

The filesystem interface exposes free block and free inode counters separately. Exact allocation details depend on the filesystem, but the two resources are not interchangeable.2

Remove the lab when finished with trash "$lab" if trash is installed.

Locate high file counts

Once inode pressure is confirmed, count files by parent directory on that filesystem:

find /var/lib/app -xdev -type f -printf '%h\n' \
  | sort \
  | uniq -c \
  | sort -n \
  | tail -n 20

-xdev prevents the scan from crossing into other mounted filesystems. The result points toward directories worth examining, but it is not a complete tree aggregate: a file contributes to its immediate parent only.

Common causes include abandoned cache entries, session files, mail queues, extracted package trees, and log rotation that creates files faster than retention removes them. Confirm ownership and retention policy before changing anything.

[!CAUTION] A full find can be expensive on a filesystem that already contains millions of entries. Run it with low priority, narrow the starting directory, or use filesystem-specific accounting when production latency matters. Never delete unfamiliar files solely because their directory ranks highly.

Sources and further reading
  1. GNU Coreutils: df invocation
  2. statfs(2)