make zram use lz4 compression algorithm
5,191
This works:
# initialize the devices
for i in $(seq ${NRDEVICES}); do
DEVNUMBER=$((i - 1))
echo lz4 > /sys/block/zram${DEVNUMBER}/comp_algorithm
echo $mem > /sys/block/zram${DEVNUMBER}/disksize
mkswap /dev/zram${DEVNUMBER}
swapon -p 100 /dev/zram${DEVNUMBER}
done
Note: it seems you need to define the compression algorithm before zram size. Set swapon -p
to priority level 100
to use zram actively as it improves performance.
Related videos on Youtube
Author by
Sirajus Salekin
Updated on September 18, 2022Comments
-
Sirajus Salekin over 1 year
Ubuntu 18, trying to make
zram
to uselz4
compression.Tried modifying
/usr/bin/init-zram-swapping
file#!/bin/sh ........... ........... for i in $(seq ${NRDEVICES}); do DEVNUMBER=$((i - 1)) echo $mem > /sys/block/zram${DEVNUMBER}/disksize echo lz4 > /sys/block/zram${DEVNUMBER}/comp_algorithm # <= added this line mkswap /dev/zram${DEVNUMBER} swapon -p 5 /dev/zram${DEVNUMBER} done
But, after reboot
zramctl
still shows I'm usinglzo
algortihmNAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram3 lzo 466M 2.9M 614.2K 1M 4 [SWAP] /dev/zram2 lzo 466M 2.9M 631.2K 1M 4 [SWAP] /dev/zram1 lzo 466M 2.9M 536.1K 1020K 4 [SWAP] /dev/zram0 lzo 466M 3M 610K 1M 4 [SWAP]
I also tried adding adding it in
rc.local
, but it throwsdevice already in use warning
, because as far as I know, the change needs to be done beforemkswap
andswapon
runs. -
Modestas over 5 yearsYes, it seems you need to define the compression algorithm before zram size. Set swapon -p to 100 swapiness to use zram actively as it improves performance.
-
Sirajus Salekin over 5 yearsthanks, i will check after going home. Too excited if this works :D
-
Tomofumi about 4 yearsIMHO I don't understand why you use
swapon -p 100
here, rather thansysctl vm.swappiness=100
? -
Modestas about 4 yearsTomofumi I don't know. Please tell if you find out.
-
nrc over 2 yearsswapon -p 100 indicates the priority amongst swap partitions. You may have for example, a priority 10 zram swap and a priority 20 hdd swap partition. swappiness is instead the threshold of free memory at which point the system starts to use the swap.