Note · Operations
What log rotation hides
The disk was full, but the log directory looked fine. The current file was small, the rotated files had been compressed, and the retention policy said everything older than a week was gone. The space was being held by a filename that no longer existed.
On Unix, deleting a file does not necessarily free its blocks. It removes the directory entry and decrements the link count. If a process still has the file open, the inode and its data remain until the last descriptor is closed. A log rotation tool that renames a file and creates a new one can leave the old writer pointing at the renamed file. A tool that copies and truncates avoids the rename problem but can still leave a writer with an unexpected view of the file.
The quickest way to find the invisible space is to ask the kernel which processes are holding deleted files:
lsof +L1
# or, when lsof is not available:
find /proc/*/fd -lname '*deleted*' -ls 2>/dev/null
If the answer is a long-running process with an open descriptor to a deleted log, the fix is usually to make the process reopen its log file, either with a signal or through the service manager. The exact signal depends on the application; some use SIGHUP, some expect a restart, and some need an explicit reopen command.
There is a second, quieter problem: rotation can make a log look empty at exactly the moment you need it. The file is new, the interesting lines are in the compressed archive, and the timestamp you are searching for is split across two files. If the rotation is not coordinated with collection, the gap can be invisible until an incident review asks for a time range.
I now treat rotation as part of the write path, not a cleanup job that runs afterward. Check who has the file open, confirm that the writer can reopen it, and verify that the collector reads both the current file and the archived one. The disk usage is only the most visible symptom.