Enabling zram

TL;DR:

modprobe zram num_devices=$(nproc) && \
sleep 1; \
for i in $(eval echo zram{0..$(( $(nproc) -1))}); do \
zramctl -t 1 -a lzo $i -s $(( 4096 * 1024 * 1024 / $(nproc) )); \
mkswap /dev/$i; \
swapon /dev/$i -p 1; \
done && \
sysctl vm.swappiness=100 && \
echo 0 > /proc/sys/vm/page-cluster

Oneliner to enable zram on embedded systems. This uses nproc to initialize one swap file per cpu.
‘4096’MB is the used size.
The eval is used to enable dynamic bash ranges. Lzo compresses typically 4:1.
I use the same size as my physical memory.

Leave Comment

Your email address will not be published. Required fields are marked *