Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Kyoto Cabinet (a key-value store) for my project. The specific type of DB I'm using is DirDB which creates a lot of files in a directory to store the key-value pairs. The server I'm running this project on has ext4 filesystem. The problem I'm encountering is that the I/O latency increases as the number of files in the directory increases. Also, when the directory has too many files (say over 1 million files), when I try to delete the whole folder, it takes forever (already more than 5 hours and still running). Can someone explains why I/O latency increases as the number of files increases and why rm takes forever to delete the folder?

share|improve this question

migrated from Jun 9 '13 at 17:19

This question came from our site for professional and enthusiast programmers.

The simplest example of delays is that, obviously, the time to list the entire directory will vary with how big the directory is.

Secondly, depending on the filesystem settings, ext4 uses either linked lists, or a hashed b-tree for directory lookups. You need only look up how those two data structures work, to get some idea of the differences that incorrect configuration might make. The short version is that linked lists are pretty slow, and only suitable for small directories, whereas that hashes are much faster, and much better suited to large directories.

Processing a linked list means going through each and every item in the list, because, most of the time, only item n-1 knows where item n is, so you must read item n first.

Processing a hash tree involves calculating a number in memory, and jumping directly to details based on that number. Although it may have to do this a few times for big directories, it's much faster than processing every node.

Anyway, if you really want to understand the details, all the documentation is available online. You could start here, for instance:

share|improve this answer
how do I find out the current setting I'm using? I highly suspect that I might be using linked list based directory lookup. – Awaken Jun 17 '13 at 9:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .