Delete empty directories to reclaim inodes

Première publication : 2013-09-12

I was facing a situation on a server of ours ; the inode usage of one of our partitions was dangerously high (93%) and growing steadily.

This partition is quite big (~ 1 TB) and contains mainly a lot of pictures and their thumbnails. Here, a lot is about 50 millions pictures (originals and thumbnails).

Those pictures are stored by ID, partitioned to have no more than 999 sub-directories at each level. If a picture has the ID 1234567, it is stored (with its thumbnails) at /srv/images/001/234/556/picture.jpg.

The problem is that when my app is deleting a picture, it deletes the files but doesn’t clean after itself, leaving a lot of empty directories. That’s why, we are using only 73% of the available disk space, but 93% of available inodes.

It occurred to us that a directory in the filesystem (ext3 for us) is consuming 2 inodes. Thanks to Evolix (our wonderful hosting partner) we’ve ran a quite simple command to delete those useless directories :

$ find -mindepth 1 -type d -empty -delete

With a watch 'df -i | grep /srv' we quickly saw the number of available inodes growing again.