4

Ubuntu 18, trying to make zram to use lz4 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 rebootzramctl still shows I'm using lzo algortihm

NAME       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 inrc.local, but it throws device already in use warning, because as far as I know, the change needs to be done before mkswap and swapon runs.

1 Answer 1

7

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.

6
  • 2
    Yes, 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.
    – Modestas
    Oct 10, 2018 at 19:30
  • thanks, i will check after going home. Too excited if this works :D Oct 11, 2018 at 3:43
  • 2
    IMHO I don't understand why you use swapon -p 100 here, rather than sysctl vm.swappiness=100?
    – Tomofumi
    Mar 11, 2020 at 6:57
  • Tomofumi I don't know. Please tell if you find out.
    – Modestas
    Mar 21, 2020 at 21:03
  • swapon -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.
    – nrc
    Dec 17, 2021 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .