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.
  • Then you'll need to do one of the following:
    1. 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
    2. 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!


    Hits: 2345
    Timestamp: 2024-12-26 06:53:10 PST

    Back to Dan's tech tidbits

    You can e-mail the author with questions or comments: