Warning: THE VOID WIKI IS DEPRECATED. It is no longer being maintained, contains outdated and incorrect information, and will eventually be shut down. Please refer to the Void Handbook, https://docs.voidlinux.org/, for the official documentation. If you can't find the information you're seeking, please raise an issue at https://github.com/void-linux/void-docs/issues

Zram -

From Void Linux Wiki
Revision as of 11:51, 12 September 2017 by Tactica (talk | contribs) (→‎External links: Converted explicit man page ref to man template.)
Jump to navigation Jump to search

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-logo.png 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.

External links