Install and Configure ZRAM using zram-generator
Note that zram is not compatible with hibernation unless combined with a swap device.
If you are here just to have a quick install method you may skip to this section.
Install zram-generator
Execute:
sudo pacman -Syu zram-generator
Configure zram-generator
Create file /etc/systemd/zram-generator.conf
with contents:
[zram0]
zram-size = ram * 2
compression-algorithm = zstd
swap-priority = 100
fs-type = swap
Instructions on how to create the file
Use either of the following methods.
Create/Edit main configuration file `/etc/systemd/zram-generator.conf` by hand
To create or edit the /etc/systemd/zram-generator.conf
file you will need elevated privileges.
Execute:
sudoedit /etc/systemd/zram-generator.conf
If you have not set SUDO_EDITOR
then you can define the variable with your favorite editor.
Execute:
SUDO_EDITOR=micro sudoedit /etc/systemd/zram-generator.conf
OR
Run this one-line command
Execute:
printf '[zram0]\nzram-size = ram * 2\ncompression-algorithm = zstd\nswap-priority = 100\nfs-type = swap\n' | sudo tee /etc/systemd/zram-generator.conf
zram-generator
should now create a zram swap device double the size of available physical memory.
Extra Notes
-
Notice the arithmetic in
zram-generator.conf
forzram-size
. You can likewise use/2
to create zram half the size of physical memory. Or*1
for equal the amount of physical memory. -
Due to compression multiples of RAM should be safe even higher than
*2
or 2 times the size of physical RAM.*2
may be considered a conservative maximum.
Disable zswap
zswap
is a similar tool that compresses swap cache. It is incompatible with zram
.
Add the option zswap.enabled=0
to your kernel parameters.
Instructions on how to add the boot option
Use either of the following methods.
Edit main configuration file `/etc/default/grub`
To edit the CMDLINE
lines of /etc/default/grub
you will need elevated privileges.
Execute:
sudoedit /etc/default/grub
If you have not set SUDO_EDITOR
then you can define the variable with your favorite editor.
Execute:
SUDO_EDITOR=/usr/bin/micro sudoedit /etc/default/grub
Assuming no other options then it would appear as:
GRUB_CMDLINE_LINUX="zswap.enabled=0"
Save and close the file.
OR
Create drop-in configuration file `/etc/default/grub.d/disable-zswap.cfg`
Execute:
sudo mkdir -p /etc/default/grub.d && printf 'GRUB_CMDLINE_LINUX+="zswap.enabled=0"' | sudo tee /etc/default/grub.d/disable-zswap.cfg
Execute:
sudo update-grub
OR:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Reboot & Check
After installing, configuring zram-generator
and disabling zswap
:
REBOOT
After reboot you may check the status of swap.
Instructions on how to view zram/swap usage
Execute:
swapon
AND/OR
Excute:
zramctl
Quick Install Instructions
If you are absolutely sure you want zram, to disable zswap, and that I know whats best, then you can just enter these commands.
Click to show
Simply execute the following:
sudo pacman -Syu zram-generator
printf '[zram0]\nzram-size = ram * 2\ncompression-algorithm = zstd\nswap-priority = 100\nfs-type = swap\n' | sudo tee /etc/systemd/zram-generator.conf
sudo mkdir -p /etc/default/grub.d && printf 'GRUB_CMDLINE_LINUX+="zswap.enabled=0"' | sudo tee /etc/default/grub.d/disable-zswap.cfg
sudo grub-mkconfig -o /boot/grub/grub.cfg
After a reboot you should have zram up to 2x, double, your physical memory.
More Information
Kernel Documentation
zram: Compressed RAM-based block devices — The Linux Kernel documentation
Online Manual for zram-generator
zram-generator(8) — Arch manual pages
Online Manual for zram-generator.conf
zram-generator.conf(5) — Arch manual pages
Online Manual for zramctl
zramctl(8) — Arch manual pages