I was wondering where and in what form a list of files and directories is stored on the ext4 filesystem. The problem is that whenever I try to access a certain directory for the first time since boot through Nautilus, Krusader, or whichever file manager - it may show it very slowly. Since I see that it accesses my HDD, I presume that it is caused by slow HDD. So, I was thinking about precaching the whole file list of my system at boot time and store it in RAM cache so it wouldn't be unloaded during the runtime of my system (Ubuntu 14.04 in my case).

Is it possible to precache and preserve in cache the list of files and directories of the whole filesystem?

I thought that it could be done with vmtouch, but I just don't know what to target.


It's actually scanning the list of files that's slow. Something like this should do:

find /home >/dev/null &

That is, it will pre-cache the files in /home. But it will keep your disk busy for a while, it will cache both interesting and uninteresting subdirectories, and some subdirectories might still be purged from cache before you actually need them. It probably isn't worth it.

  • hmmmm, actually this might be a workaround solution... – Highstaker May 5 '15 at 8:14

In order to show you a directory, these file managers need to at least scan the list of file names in the directory and the file types and other metadata. These are the same calls that ls -l makes. In addition, some file managers may inspect the contents of the file to give you more precise information about what's in them, like the file utility. They may also build previews for certain file types (e.g. images), and may try to extract icons from a few file types that have an icon bundled.

If you find that this is too slow, try to configure them to display less information.

To pre-read just the file names and metadata, run

find ~ -type f >/dev/null

To pre-read the beginning of files as well, run

find ~ -exec file {} + >/dev/null

I don't recommend this. It will take a long time and store a lot of information in memory that will never be used (because you won't access all your files today). Trying to second-guess OS cache algorithms is usually counterproductive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.