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.

Thanks!

share|improve this question
add comment

2 Answers 2

up vote 6 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
    
The important question is "Given 16GiB of RAM, no swap, Linux's broken RSS limit support, and my tendency to trigger memory leaks in Firefox, BasKet 1.0.x, and things I'm hacking on, how can I pin a known set of dependencies in memory so a memory leak can't evict them and trash my sub-second application start times?" –  ssokolow Jul 20 at 11:06
    
@ssokolow I think the answer would involve cgroups. But it won't necessarily make for a better user experience: you'll have some stuff being faster but other stuff will be slower. –  Gilles Jul 20 at 13:33
    
@Gilles Except when I'm running four or five modern.ie VMs in parallel for testing or I trigger a memory leak, my memory footprint never rises above roughly 6GiB out of my 16GiB of RAM. I just want to make sure that things like vim, gVim, Leafpad, urxvt+bash, and urxvt+zsh always start in under a second. Pinning them and their dependencies shouldn't use much RAM. –  ssokolow 2 days ago
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 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. (Looks like I were wrong.)

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

[edit] removed second "ionice" as suggested in the comment.

share|improve this answer
1  
No need to use ionice twice. Processes inherit their priority from their parents. Child processes are so common on Unixy OSes that anything else would be ineffective. Try this and you'll see what I mean: ionice -c 3 find /bin -exec ionice \; | uniq (The second ionice without arguments just queries the currently-set priority) –  ssokolow Jul 20 at 5:36
add comment

Your Answer

 
discard

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.