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.

My PC has 8 Gb of ram. Is there any way to make ubuntu use most of it? I mean rarely drop caches and keep once opened programms in ram longer, preload apps on boot, etc.

share|improve this question
    
Does Ubuntu drop caches or moves open programs to swap? –  mikewhatever Oct 4 '12 at 15:36
    
Do you have 64-bit or 32-bit version? –  Addison Montgomery Oct 4 '12 at 16:02
add comment

3 Answers

You could make a ramdisk for certain directories using tmpfs

For example for the ~/.cache/ directory, which google chrome and chromium use to cache data, the entry in /etc/fstab would be:

tmpfs /home/your_username/.cache tmpfs defaults,size=1024M 0 0

However, it should be noted that the contents get lost with each reboot.

Anther suitable directoriy might be /tmp. Note that you can specify the size of the tmpfs in absolute or relative (to your RAM) values:

Use 1G of your RAM:

tmpfs /tmp tmpfs nosuid,size=1G 0 0

or, use 10% of your available RAM:

tmpfs /tmp tmpfs nosuid,size=10% 0 0
share|improve this answer
add comment
up vote 1 down vote accepted

I've found the solution how to use RAM. Create the script with the following content:

find /home/user/.config/ /home/user/.gconf/ /home/user/.mozilla/ /usr/share/icons/current_icon_theme/ /usr/share/nautilus/ /usr/bin/nau* /usr/share/gnome* /usr/bin/gno* /usr/lib/ -xdev -type f -exec cat '{}' \; > /dev/null

I run this script after login. To do this just add the autostart application with this content:

sh -c "sleep 8; /path/to/the/script.sh" &

It takes about 40 seconds to complete. The programms load much faster.

share|improve this answer
1  
0 explanation? What does that line mean? I thought /dev/null was a sort of trash. Please elaborate :D –  sinekonata May 24 '13 at 1:48
add comment

Preloading should be easy enough -- since linux caches/buffers as much as possible, simply cat the libs/binaries you want to "preload" to /dev/null -- that should warm up the cache. Start a script like the following at boot:

#/bin/bash
PROGS=("/usr/bin/jiha" "/usr/bin/doho")
for i in "${PROGS[@]}"; do 
    cat $i > /dev/null
    for j in $(ldd "$i"); do  # this does not work -- need to filter ldd output (awk)
        cat $j > /dev/null
    done
done

This will waste a lot of time by cat'ing some libraries again and again, it is a bit more complicated to preload the needed libraries only once - but the impact depends on the length of the PROGS-array.

The rest (rarely drop caches, ...) is pretty much taken care of by the system by default -- it takes what it can use and let it go only if need be.

HTH

share|improve this answer
    
Will this negatively impact disk i/o? Also, is it significantly different from just installing preload? Interesting question & answer though, I'm in the same situation as OP and I've just never seen >50% RAM usage. –  Tom Brossman Oct 4 '12 at 16:18
1  
preload AFAIU will preload during operation based on programs/files opened by the user; this simple approach will prolong boot time, but speed up load-time of just the wanted apps, nothing more. –  Tom Regner Oct 4 '12 at 19:23
1  
buffered/cached portions of the ram are shown as free in most tools -- as they will be freed if needed; but linux will cache every file you access as long as it can. If the total amount of memory used in your machine, including buffers/caches, never reaches 50% -- you have too much RAM for what you do :-) –  Tom Regner Oct 4 '12 at 19:28
    
Good to know, thanks. Ram is so cheap any more I just get extra. Nice for running the occasional VM, but probably not necessary. –  Tom Brossman Oct 4 '12 at 19:32
    
Yes, it's nice not to run out of memory - absolutely worth it. Jumped to 8G on both machines (work/home) - just nice. –  Tom Regner Oct 4 '12 at 19:43
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.