Quantcast
Channel: Linux Device Hacking
Viewing all articles
Browse latest Browse all 3178

zswap and lz4 compression (no replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 3178

Trending Articles