Experimenting with Compressed Swap

| Comments

The Intel X25 has once again encouraged me to find something very interesting. I've been reading a bit about the X25’s “endurance management” feature. It sounds as though the drive switches to some sort of slower write strategy if the average writes per day continually exceed an average of 20 GB per day.

My laptop doesn't tend to swap at all most of the time. Even under my heaviest memory usage, when I have multiple test virtual machines running, I only seem to dip about 200 MB or so into my swap.

Testing Out compcache

Ubuntu 9.04 seems to ship with an older version of compcache. I decided to build my own modules from the latest tarball. The instructions of the website were very straightforward, and I had things up and running in no time.

So far I have not compiled a kernel with the 'swap free notify' patch applied. It does look like it would be very useful, since it would allow compcache to free up unused swap space much faster.

For testing purposes I disabled my original swap partition. I initialized a ramzswap device with the default size (25% of total memory) and activated it. Here is what free showed before I tried to fill up more memory than I ever would in practice:

             total       used       free     shared    buffers     cached
Mem:       3310124    3105004     205120          0     194312    1777532
-/+ buffers/cache:    1133160    2176964
Swap:       827524          0     827524

swapon -s shows:

Filename                            Type            Size    Used    Priority
/dev/ramzswap0                          partition   827524  0       100

I fired up six QEMU machines with memory sizes between 384 and 512 MB for a total of 2432 MB.

Here is what free looked like after letting the machines boot up and settle down for a bit:

             total       used       free     shared    buffers     cached
Mem:       3310124    3293424      16700          0       1768      86740
-/+ buffers/cache:    3204916     105208
Swap:       827524     600916     226608

At this point, cached data dropped from 1.7 GB down to under 100 MB and the poor little laptop was pushing 600 MB into swap. The rzscontrol program can show us some interesting statistics about the swap space that is in use:

OrigDataSize:     575584 kB
ComprDataSize:    157969 kB
MemUsedTotal:     159260 kB

rzscontrol is showing that 575 MB of data is currently swapped out and it is only taking up 159 MB of RAM. If that ratio holds steady, I could fill that 800 MB swap space and only eat up a little over 200 MB of RAM.

I even got a little meaner and started running memtest86+ in the virtual machines to make sure I wasn't getting extra special results because of zeroed out pages. I couldn't get the compression ratio to drop past 3:1.

I also tried a similar experiment using physical swap… It brought my laptop to a crawl. When swapping to compcache it didn't feel any different than when I'm not swapping at all.

Compcache, Suspend to Disk, and Swap Files

I am currently running compcache on my laptop. I don't plan to use it as my only swap space, though. I activated my old swap partition with a lower priority than my compcache swap space:

Filename                            Type            Size    Used    Priority
/dev/ramzswap0                          partition   827524  0       100
/dev/sda1                               partition   4000176 0       1

I haven't done much testing with how this will behave. I'm hoping it won't reach for the physical swap space until the ramzswap device fills up. I don't believe I will be that lucky, though. Compcache has an option to let you back a ramzswap device with a physical swap device. When I tested this, dstat was showing disk activity on my swap partition the whole time swap was in use. This was pretty much what I expected based on the documentation.

Suspend to disk seemed to “Just Work” as long as I have my old swap partition activated. Ubuntu uses swsusp to suspend to disk, which means that it can't suspend to a swap file. I was hoping I could just create a swap file for those rare occasions when I actually need to suspend to disk instead of to RAM.

Comments