Welcome! Log In Create A New Profile

Advanced

zswap and lz4 compression

Posted by renojim 
zswap and lz4 compression
December 03, 2017 10:51PM
I finally decided to see what zswap is all about and in the process I learned a few things and stumbled upon using lz4 instead of the default lzo compression. Why do I want lz4? No idea. I just found references to it and thought if other people think it's useful than who am I to question them? :-)

The first thing I learned is that you may think you're using zswap and you really aren't:
root@debian:~# dmesg | grep zswap
[    8.253409] zswap: loaded using pool lzo/zbud
So zswap is being used, right? Wrong!
root@debian:~# cat /sys/module/zswap/parameters/enabled
N
It appears that zswap is always loaded by the kernel, but it's only used if explicitly enabled in the cmdline:
root@debian:~# dmesg | grep -i zswap
[    0.000000] Kernel command line: console=ttyS0,115200 root=/dev/sda1 rootdelay=10 rootfstype=ext3 mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data) zswap.enabled=1
[    8.376189] zswap: loaded using pool lzo/zbud
root@debian:~# cat /sys/module/zswap/parameters/enabled
Y

You have to modify your U-Boot variables. There's probably many ways to add the zswap.enabled=1 parameter, but here's how I did it.
root@debian:~# fw_printenv usb_set_bootargs
usb_set_bootargs=setenv bootargs console=$console root=$usb_root rootdelay=$usb_rootdelay rootfstype=$usb_rootfstype $mtdparts $usb_custom_params
For me, the usb_custom_params wasn't being set to anything, so I just used that:
fw_setenv usb_custom_params 'zswap.enabled=1'
I could just have easily modified the usb_set_bootargs variable. After making the change and rebooting, you should see the results shown earlier from dmesg and cat /sys/module/zswap/parameters/enabled.

Now that zswap is really enabled, let's get it to use lz4 instead of lzo:
fw_setenv usb_custom_params 'zswap.enabled=1 zswap.compressor=lz4'
Add the appropriate modules:
echo lz4 >> /etc/initramfs-tools/modules
echo lz4_compress >> /etc/initramfs-tools/modules
Have to update initramfs:
update-initramfs -u
One guide I saw said that at this point all you have to do is reboot, but that's not true for us. You must remake uInitrd. Look at bodhi's great instructions for the specific command for your kernel and hardware. Here's an example (I'm using a fairly old kernel):
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs-4.8.3-kirkwood-tld-1 -d initrd.img-4.8.3-kirkwood-tld-1 uInitrd
That should be it! Reboot:
sync
sync
reboot
Now check the dmesg output:
root@debian:/boot# dmesg | grep -i zswap
[    0.000000] Kernel command line: console=ttyS0,115200 root=/dev/sda1 rootdelay=10 rootfstype=ext3 mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data) zswap.enabled=1 zswap.compressor=lz4
[    8.376189] zswap: loaded using pool lz4/zbud
root@debian:/boot# cat /sys/module/zswap/parameters/enabled
Y

What have we accomplished? I'm not really sure. I'd like to find a way to prove that something was gained like something that used to run out of memory, but doesn't now or something that's noticeably faster with zswap and lz4.

Another command I saw mentioned was this:
cat /proc/swaps
Filename                                Type            Size    Used    Priority
/media/WD4TB/swapfile                   file            1048572 4044    -1
It shows the swap file I'm using (is it still necessary?), but no mention of zwap.

Anyway, any comments and/or questions would be appreciated.
-JT
Re: zswap and lz4 compression
December 03, 2017 11:25PM
JT,

Really easy to test.

- Run vmstat command before and after enabling zswap.
- Use a very memory intensive app such as xfce or lxde desktop to trigger a lot of swapping.

I've posted here how to enable and test this, but forgot to add it to the wiki :)

But good job laying it all out (in more details than I did).

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: zswap and lz4 compression
December 03, 2017 11:29PM
Re: zswap and lz4 compression
December 04, 2017 01:35AM
Quote

bodhi

> I've posted here how to enable and test this, but
> forgot to add it to the wiki :)
>
> But good job laying it all out (in more details
> than I did).

JT,

If you could, run some tests like I suggested using vmstat. And then update your posts with test results.

I'd like to add your post to the Wiki thread after you've done that.

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: zswap and lz4 compression
December 04, 2017 01:40AM
Will do. I searched for zswap here when I started, but there seemed to be stuff spread out all over the place.

-JT
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 2 plus 19?
Message: