KatInterview

Explaining Disk Usage Discrepancies Between df and du

System DesignModel answer
MediumModel answerSystem Designlinuxoperating-systemsstorage

Last updated

Analyze why df and du report different disk space utilization on Linux systems and walk through a step-by-step troubleshooting process.

You are an SRE on call for a high-traffic production system. An alert triggers showing that the primary partition (/) on a database worker node has reached 98% storage capacity according to df -h.

When you log into the machine and execute du -sh /*, the total calculated space across all top-level directories is vastly smaller than the space marked as used by df.

Address the following:

  1. Underlying Architecture: Explain how df and du retrieve space allocation data at the kernel and VFS/filesystem levels, and why their data sources differ.
  2. Root Causes: Identify the primary operating system mechanisms and scenarios that lead to large discrepancies between these commands.
  3. Investigation Workflow: Outline a non-disruptive, step-by-step diagnostic process to pinpoint the exact source of missing space on a running system.
  4. Remediation & Hazards: Describe how to reclaim storage safely without causing service downtime or data corruption, highlighting commands or actions to avoid.

Hints

Hint 1

Consider what happens to a file's underlying blocks when a path entry is deleted via unlink() while a process still maintains an active file descriptor.

Hint 2

Think about how mounting a block device over a non-empty directory affects file visibility during directory tree walks.

Hint 3

Differentiate between the used block count reported by superblock structures and total disk capacity adjusted for reserved system blocks.