Zram -
zram (also called zRAM, and formerly known as compcache) is a feature of the Linux kernel that provides virtual memory with compression. Check the Wikipedia article about it to find out why you might be interested in using this instead of a regular swap partition depending on your hardware.
Setting up zram on Void Linux
To begin with, ensure the zram kernel module is loaded on boot:
echo "zram" > /etc/modules-load.d/zram.conf
Most people recommend creating one disk per processor core. This is specified as an option when the kernel module is loaded, here's an example for a 4 core system:
echo "options zram num_devices=4" > /etc/modprobe.d/zram.conf
Now that the number of disks has been set, we must also specify their size. This could be done in /etc/runit/core-services/03-zram.sh
or in /etc/rc.local
. Add the following lines to either file, adjusted to however many disks you created earlier. The size you select also depends on your system needs and available RAM. This example adds 4GB zram swap to a system.
# set sizes for zram drives zramctl --find --size 1G zramctl --find --size 1G zramctl --find --size 1G zramctl --find --size 1G # make it swap mkswap /dev/zram0 mkswap /dev/zram1 mkswap /dev/zram2 mkswap /dev/zram3 # activate swapon /dev/zram0 swapon /dev/zram1 swapon /dev/zram2 swapon /dev/zram3
The compression in the zram disks is usually better than 2 to 1, so it may be good to limit the total zram disk memory to less than double your physical RAM.