How to use a compressed ramdisk (ramzswap)? Huge speed gain
Since I don't use my laptop's CD-drive I want to put a small (8 GB) SSD into the CD-drive slot (I'll use a caddy similar to this one). I want to use compressed btrfs on the SSD and put all the data on the big HDD. I want to avoid unnecessary spin-ups. I want the system to be fast... I want to minimize wearing of the SSD.
What tricks are there to use a compressed ramdisk wisely (using but not overusing it)? How to enable it? What values are sensible?
Also see this post (I split my questions up).
For Natty and up just use zramswap. I've already baked sane defaults and automatic setup in there. In fact, it adapts to your system automatically and I really doubt you'll achieve better results by manual setup.
Update: In Natty it doesn't work that way.See this question.
I'll answer my question myself, but for now just for Lucid (10.04) since that's what I'm on right now. The speed gains are really astonishing. Whenever ram became scarce on my system (2 GB, shared graphics, some programs in background, big chromium session) my laptop started to swap often. Just that swapping usually meant near complete standstill (mouse stutters, greyed out apps etc). vm.swappiness
is at 100 so swap is used before it's too late, but stil I had minute long waits till the laptop responded again.
tl;dr: When the PC starts swapping the speed stays the same. Nice!
To try it: do sudo modprobe ramzswap disksize_kb=524288 memlimit_kb=196608
This creates a 512 MB compressed swap with a limit on used ram of 192 MB. Note that the ram will only be eaten when the swapfile is actually used. Do sudo swapon /dev/ramzswap0
to enable it. Open several tabs or several ram heavy apps (OOo, gimp, blender) and watch free -m
and sudo swapon -s
. Your ramzswap should show up and get filled at no noticable speedloss.
To enable it permanently: do sudo nano /etc/initramfs-tools/initramfs.conf
and search for COMPCACHE_SIZE=""
and replace it with COMPCACHE_SIZE="512 M"
or whatever size of uncompressed swap you wish to have. For example "30 %"
is also possible.
Profit.
I didn't find a way to enable compcache/ramzswap in /etc/fstab
which is strange.