Ask HN: Why is my directory with 300KB of files 60MB large?
Well, actually I know how the directory (on my ext4 partiton) got to be this way but I was interested in the technical details behind it. I was running many network simulations, each one generating a packet trace file. I was going to parse these offline but the simulations ended up making 163GB of small trace files before I ran out of disk space! [I have since changed my scripts to pipe the traces to the analyzer, eliminating the problem.] After deleting the traces, which took about 20 minutes, a `ls -la .` shows that the directory is 60MB large while containing just 300kB of files. I suspect that some remnants of the links to the trace files remain in the directory inode. Why weren't they removed? Will they get "garbage collected" in the future?
Thanks for your insights,
Jevin
4 comments
[ 2.2 ms ] story [ 19.8 ms ] thread1) `ls -la .` to show "hidden" files.
2) Some process is still running, and it has an open handle on some deleted file(s). Deleted file space is not reclaimed until all open handles are released.
All of the involved processes have long since terminated. I'm fairly sure the files are gone for good, I actually have free space on my drive! :)
eg. 100,000 files of 1 byte each taking 1 block of size 4KB would occupy ~390 MB on disk (instead of 100KB as one would assume).
1. e2fsck -D /your/partition
The -D option directs fsck to optimize the directories. Basically, it rebuilds the directory inode.
2. mkdir tmp && mv big_folder/* tmp/ && rmdir big_folder && mv tmp big_folder
This actually moves the files to a new, small directory, and deletes the old, big one before renaming back to the original name.
[1] This thread discusses the problem and some potential online solutions http://lkml.org/lkml/2009/5/14/362