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.
I didn't find a way to enable compcache/ramzswap in
/etc/fstab which is strange.