Mental model
POSIX/Linux cleanly splits a file's human name, metadata, and disk bytes across three separate structures: Directory Entries (dentries) simply map filenames onto integer Inode (Index Node) IDs; the Inode stores permissions (mode), owner (uid), link counts (nlink), timestamps, and physical disk Data Block / Extent pointers (containing zero filename!); and actual file payloads reside inside ext4 / XFS data blocks cached transparently through kernel Page Cache.
Learning outcomes
- Trace file lookups and deletion rules cleanly across dentries, inodes (
st_nlink+ open kernel FD refcounts), and ext4 Extent trees (faster than legacy indirect block maps). - Diagnose puzzling
"No space left on device (ENOSPC)"failures cleanly whendf -hshows20%used (inode exhaustion df -i 100%ordeleted open files held by running workers!). - Choose properly cleanly between
ext4(static format-time inode table, ultra-reliable journaling) andXFS(dynamic runtime inode allocation, parallel allocation groups for huge DB arrays).
Theory
Two legendary Linux operations mysteries confuse SREs and ML platform engineers alike until seeing the Inode link reference formula:
- "Disk 100% Full (
df -h), Yet Large File Delete Freed Zero Bytes (dushows tiny!)": An engineer ranrm /var/log/huge.logcleanly while a background worker still held that log file open! Becausermcallsunlink(), deleting solely the directory dentry (dropping st_nlink -> 0), the kernel preserves 100% of disk data blocks cleanly intact until the worker process closes that FD or restarts (lsof +L1reveals all deleted-yet-held zombie blocks instantaneously!). - "
ENOSPCWrite Failures With 200 GB Free (df -hat 30%)": Writing millions of tiny cache shards or chunk artifacts exhaustedext4's fixed format-time inode table (df -i = 100%) completely cleanly with plenty of raw disk blocks idle!
| Filesystem Primitive | Key Property | Practical Implication | Diagnostic Utility |
|---|---|---|---|
Hard Link (ln a b) | New dentry pointing directly cleanly to identical Inode # (st_nlink++) | Cannot cross distinct filesystem mounts or link directories; deleting a preserves b & data cleanly | Used cleanly in Nix/Docker layered deduplication (content stores) |
Symbolic Link (ln -s a b) | Independent tiny Inode holding literal pathname target string | Works across mounts/dirs cleanly; dangles (ENOENT) if a moves; beware symlink traversal attacks! | Clean deployment slot swaps (/current -> /releases/v2) |
ext4 Journaling (data=ordered) | Metadata journal (JBD2) writes data blocks cleanly ahead of metadata commit | Protects filesystem tree integrity cleanly after crashes; fixed df -i inode table set at mkfs.ext4 | Standard root / boot / container overlay volumes |
XFS (Allocation Groups) | Dynamically allocates fresh inodes anywhere free space exists; parallel AG locks | Avoids df -i pre-exhaustion & scales multi-thread concurrent DB writers smoothly | Ideal cleanly for huge petabyte NVMe data lakes & databases |
bash#!/usr/bin/env bashset -euo pipefail# 1. Diagnose BOTH block bytes (`df -h`) AND fixed inode table exhaustion (`df -i`)df -h /var/lib/datadf -i /var/lib/data# 2. Find deleted ("unlinked") huge files still pinned silently on disk by open running PIDs!lsof -nP +L1 | head -n 20# Inspect exact inode number, extent link count (Links: N), and block countstat /etc/hosts
Trade-offs
Deploying default ext4 (data=ordered) delivers mature crash consistency, instant lightweight checks (e2fsck), and strong mixed-file reliability cleanly across container hosts—provided teams avoid storing millions of tiny un-batched 1 KB files without tuning -i inode ratios upfront at mkfs (or packaging artifacts inside SQLite / Parquet / tar shards cleanly). Switching high-IOPS database volumes cleanly onto XFS gains lock-sharded Allocation Groups and dynamic inode scaling (never running out of df -i while bytes remain free), trading slightly heavier shrink limitations (XFS volumes cannot shrink offline cleanly, only expand!).
Failure modes and misconceptions
- Truncating vs Deleting Held Open Logs (
rm app.log): Removing a live active log without sendingSIGUSR1logrotate reopen (copytruncateorlogrotate postrotate) hides the filename cleanly fromls/duwhile filling root storage straight to100%crash! - Exhausting Fixed
ext4Inodes With Small Un-Batched Vector/Eval Shards: Dumping4 milliontiny JSON chunks directly onto defaultext4(1 inode per 16 KBformatted ratio) hitsENOSPCcleanly at5%byte occupancy cleanly. - Confusing Inode Deletion Guarantees Across Hard Links (
Docker layers): Deleting one tag/manifest path leaves shared underlying inode blocks intact cleanly whenever sibling hard links preservenlink >= 1. - Ignoring
stat()/ Symlink Race Attacks (O_NOFOLLOW): Writing temp files cleanly without resolving symlinks or checkingO_NOFOLLOWexposes privileged services cleanly to arbitrary file overwrites via malicious symlink drops cleanly.
Decision scenario
An embeddings staging server fails Kubernetes pod scheduling with No space left on device, yet df -h reads only 44% used! Checking df -i exposes 100% inode usage from 8.4 million tiny orphaned token cache JSONs on ext4, while another volume shows 99% df -h with du reporting just 12 GB due to a deleted-but-open uvicorn log file! Pack small cache fragments cleanly inside SQLite / RocksDB stores (or XFS), clean dangling caches, verify active deleted handles via lsof +L1 + signal reopen (logrotate), and add df -i alongside df -h alerts cleanly!