Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have the current scenario:

  • 16GB or RAM. For the most part, around 10~12GB unused

  • Almost never install/remove software, this is a mature system

  • Only reboot like once a week, so (re-)boot time is irrelevant

  • /usr is around 8GB

  • HDD is slow, and no budget to change that in the near future

  • Mounting /tmp as tmpfs in fstab did wonders for performance

And I just had this crazy idea:

Is it possible to, somehow, use my RAM to "store" /usr?

In that that, when starting up, it reads current /usr content from HDD and copy it to a tmpfs and mount that as /usr?

If possible, also flushing the (perhaps updated) contents back to HDD when shutting down? Or maybe allowing me to easily "temporarily switch back to HDD" when eventually needed to install/remove new software or updates?

Any approach is welcome, ready-to-use commands will be highly regarded.


share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

This is possible, but pointless. The kernel keeps a cache of data from the disk in RAM. The data that you used most recently is kept in RAM. You will naturally end up with the parts of /usr that you use often in RAM, and the parts you don't use won't be taking up any RAM.

If you want better reaction time when you start an application, you can seed the cache. A file is loaded into memory the first time you use it, and remains there until the memory is reused for something else. You can force a file to be loaded:

cat /path/to/file >/dev/null

For example, to preload all executables and libraries into RAM:

cat /bin/* /lib/* /usr/bin/* /usr/lib/* >/dev/null

This can take a while to complete, so you should do it in the background. You can put the following command in /etc/rc.local:

ionice -c 3 cat /bin/* /lib/* /usr/bin/* /usr/lib/* >/dev/null &

To also load all libraries in subdirectories of /usr/lib* it could be useful to run find:

ionice -c 3 find /bin /usr/bin /usr/lib* -type f -exec ionice -c 3 cat '{}' ';' > /dev/null &
share|improve this answer
Humm, nice approach, +1. But... how large is kernel's cache in a default Ubuntu install? Is it a fixed size or does it scale with available RAM? Any way (or point) to set it larger (or more agressive), as in "hey, see that 12GB free? Don't be shy, take 8GB for you!"? –  MestreLion May 12 '12 at 2:09
@MestreLion The cache uses all the RAM it can. The only setting is “don't be shy, take all available memory”. What you can configure is the relative propensity to swap application memory vs keeping more disk cache (/proc/sys/vm/swappiness), but that's only relevant on systems with relatively little RAM for what they're used for. –  Gilles May 12 '12 at 2:18
add comment
ionice -c 3 cat /bin/* /lib/* /usr/bin/* /usr/lib/* >/dev/null &

Won't run, because there are a lot of directories within the libs. try find:

ionice -c 3 find /bin /usr/bin /usr/lib* -type f -exec ionice -c 3 cat '{}' ';' > /dev/null &

Everything it produces goes to /dev/null so nothing will annoy you.

I think both ionice are required because find executes the commands in a own process. Please correct me if I'm wrong.

This line in rc.local should do the trick to the already chosen answer.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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