KlipperWrt icon indicating copy to clipboard operation
KlipperWrt copied to clipboard

[dev] consider zram / zswap

Open ihrapsa opened this issue 3 years ago • 2 comments

This is a kind of swap that resides on RAM in a compressed form. It will make swapping and ram usage more efficient and it will increase the lifespan of the sd card as well.

Resources: https://openwrt.org/packages/pkgdata/zram-swap https://openwrt.org/packages/pkgdata/kmod-zram https://forum.openwrt.org/t/retracted-compressed-memory-this-project-is-officially-retracted-take-note-about-its-future/49076 https://forum.openwrt.org/t/mounting-swap-on-zram-with-discard/48451 https://forum.openwrt.org/t/possible-to-use-zswap/8916/6 https://stackoverflow.com/questions/24467604/swapon-failed-trying-to-enable-zram

Interesting read: https://haydenjames.io/linux-performance-almost-always-add-swap-part2-zram/ https://ikarus.sg/using-zram-to-get-more-out-of-your-raspberry-pi/

Building: kmod-zram kmod-lib-lzo (this is selected by default) kmod-lib-lz4 kmod-lib-zstd Kernel config: zswap zbud z3fold

Enabling zswap: either: opkg install zram-swap - will allocate half of ram size to zram0 echo 1 > /sys/module/zswap/parameters/enabled; in /etc/rc.local (if not enabled by default in kernel) or

##inside rc.local

swapoff /dev/zram0;
echo 1 > /sys/block/zram0/reset;
echo lzo > /sys/block/zram0/comp_algorithm              
echo 60M > /sys/block/zram0/disksize;
echo 1 > /sys/module/zswap/parameters/enabled;       #seems to be enabled by default
mkswap /dev/zram0;
swapon -p 5 /dev/zram0;

~#echo lz4 > /sys/module/zswap/parameters/compressor; #echo z3fold > /sys/module/zswap/parameters/zpool; #echo 20 > /sys/module/zswap/parameters/max_pool_percent; #echo 75 > /proc/sys/vm/swappiness;~

ihrapsa avatar Jun 24 '21 20:06 ihrapsa

Updated to my KlipperWRT, will review the performance in next few days.

thomsonOZ avatar Sep 06 '21 11:09 thomsonOZ

Updated to my KlipperWRT, will review the performance in next few days.

hmm... Thanks, but actually I configured KlipperWrt as default with zram-swap. I tried experimenting with different compression algorithms and ram sizes as well as zswap (which seems to be a more efficient way of using ram) but that zram-swap package/script configures everything depending on the amount of ram you have and I stuck with that. If you manage to get better performance with a different configuration please share 🙂

ihrapsa avatar Sep 06 '21 11:09 ihrapsa