Zram swap
5.1
Zram makes a swap device in RAM, compressed: when memory runs short, the kernel moves idle pages there instead of killing a program. It helps a lot on old machines and 32-bit systems with little memory, where a web browser alone can fill the RAM.
On a live system: already there
A live SliTaz runs from RAM and most machines bring no swap, so the system sets up a zram swap of half the RAM at boot by itself, when no other swap is active. Check it with:
cat /proc/swaps
To boot without it, add nozram to the boot options (noswap leaves
out every swap).
On an installed system
An installed system does not set it up by itself. As root, add these
three lines at the end of /etc/init.d/local.sh, which runs at every
boot:
modprobe zram
echo 256M > /sys/block/zram0/disksize
mkswap /dev/zram0 > /dev/null && swapon -p 100 /dev/zram0
Run them once by hand, or reboot, then check with cat /proc/swaps:
/dev/zram0 shows up with priority 100, and free -m shows the swap.
cat /sys/block/zram0/comp_algorithm lists the compression methods of
the kernel, the one in use between brackets.
How big?
The size is how much swapped data zram can hold. That data is kept compressed, so it uses less real RAM than its size, often a third to a half, but compressing costs some CPU time. On old machines, don't make it too big. A rule of thumb:
- 512M of RAM or less: about half of the RAM (256M on 512M);
- 1G to 2G: half of the RAM;
- 4G: 1G to 2G;
- 8G and more: rarely needed.
Change the 256M in the commands, and in /etc/init.d/local.sh, to the
size you want.
Turn it off again
swapoff /dev/zram0
echo 1 > /sys/block/zram0/reset
rmmod zram
To stop it at boot as well, remove the three zram lines from
/etc/init.d/local.sh.
Troubleshooting
"sh: write error: Device or resource busy" when setting the size:
zram0 is already set up, and dmesg shows "zram: Cannot change disksize
for initialized device". On a live system that is the swap SliTaz made
at boot: there is nothing to do. Otherwise turn it off as above, then
set it up again.
Not there after a reboot: check that the lines are at the end of
/etc/init.d/local.sh, and look at the messages:
dmesg | grep zram