Compressed Memory Swap

Here you can discuss every aspect of Debian. Note: not for support requests!

Compressed Memory Swap

Postby vbrummond » 2012-03-26 07:26

I found out compressed memory swap is built into Debian Wheezy. This is useful for workloads that swap occasionally or for machines with low memory. To test if this works you only need to run a few commands.

First log into a root terminal. To check if you have the zram module available and load it run:
Code: Select all
modprobe zram


Next create the device. In this case 50mb.
Code: Select all
echo $((50*1024*1024)) > /sys/block/zram0/disksize


Then you have to make the compressed memory device into a swap and mount it as higher priority than other swap devices.
Code: Select all
mkswap /dev/zram0

Code: Select all
swapon -p 10 /dev/zram0


You can check if it works by running:
Code: Select all
swapon -s


If it works the output should look like this:
Filename Type Size Used Priority
/dev/sda1 partition 2928636 0 -1
/dev/zram0 partition 51196 23924 10


In order to have this persistant upon reboots I just add the commands to /etc/rc.local such as this:
Code: Select all
modprobe zram &&
echo $((50*1024*1024)) > /sys/block/zram0/disksize &&
mkswap /dev/zram0 &&
swapon -p 10 /dev/zram0 &&
exit 0
Always on Debian Testing
vbrummond
 
Posts: 4468
Joined: 2010-03-02 01:42

Re: Compressed Memory Swap

Postby phenest » 2012-03-26 17:17

So many questions:
How big do I make the swap?
What are the performance gains?
Is there a performance loss due to compression?
Are there specific cases for needing this?

I'm not running Wheezy so I can't test any of this. Sounds interesting though.
ASRock H77 Pro4-M i7 3770K - 32GB RAM - Pioneer BDR-209D
User avatar
phenest
 
Posts: 1703
Joined: 2010-03-09 09:38
Location: The Matrix

Re: Compressed Memory Swap

Postby vbrummond » 2012-03-26 19:17

phenest wrote:So many questions:

I am not really an expert but i will try to answer from what I have read and experimented with.

How big do I make the swap?

I just use 50mb as an example, though the upstream tools to do this (so far not included in debian so I did it manually) use 25% of their ram. I would say the best answer might be somewhere in the middle such as 10% of your total ram.

What are the performance gains?

I really do not have numbers here, though it should take a memory contrained environment and offload some of that to the cpu for compression, and give you a bit more total ram.

Is there a performance loss due to compression?

Of course, it will take some cpu to do, but it is not constantly in effect. I suspect you will notice the effects of disk swapping far more heavily on a modern pc.

Are there specific cases for needing this?

Perhaps running gnome/kde on a netbook. Or embedded device. Having more memory available to run a virtual machine. I use it because I have spades of spare cpu power but I get memory constrained when running a large os in a virtual machine.

I'm not running Wheezy so I can't test any of this. Sounds interesting though.

I tested it in a virtual machine so it should work in Squeeze as well as long as you use the 3.2 kernel from backports.
Always on Debian Testing
vbrummond
 
Posts: 4468
Joined: 2010-03-02 01:42

Re: Compressed Memory Swap

Postby Shannon77 » 2013-08-28 10:54

All new features in Linux Kernel 3.2.
Shannon77
 
Posts: 2
Joined: 2013-08-28 10:49

Re: Compressed Memory Swap

Postby Danielsan » 2013-12-06 00:15

I thought it needed to put only this command in grub:
Code: Select all
GRUB_CMDLINE_LINUX_DEFAULT="zswap.enabled=1"


And after it will be totally automatic but isn't it?
User avatar
Danielsan
 
Posts: 532
Joined: 2010-10-10 22:36


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable