If you have an ext3 filesystem with large directories (tens of thousands, maybe even less than that), then turning on indexed directories can give a
very nice performance boost. This page presents two ways of doing this.
In either case, you need to start out with command. After you run this command, then existing directories will
remain not indexed, but all new directories should be indexed.
# tune2fs -O dir_index /dev/hdXY
Then you'll need to do one of the following:
The fsck method, which will require some filesystem unavailability, but will take care of all your directories at
the same time:
# umount /dev/hdXY
# e2fsck -D -f /dev/hdXY
The redo-dirs method, which is surprisingly fast, but does have some windows where a
needed directory (very brief window) or file (can be long if your directories are truly huge, but you may be
surprised by the definition of "huge" in this situation ) is missing. It works by, for each
directory fed to the program, renaming it to something temporary, creating a new directory with the original name,
and then moving everything from the original directory (now with a temporary name) to the new directory, and
finally removing the original directory, which is now empty. As a result, all the files end up in an indexed
directory with the same content as before. This method has an additional advantage: you can do just some of your
directories if you want.
# cd /mount/point/of/hdXY
# find $(pwd)/[A-z]* $(pwd)/.[A-z]* -type d -print0 | ~/bin/redo-dirs
BUGS!
redo-dirs does not yet make any effort to preserve owner or group. It'll be easy to add though, if there's a need.
It also makes no effort to preserve ACL's or Linux extended attributes.