What is zRAM and why this how-to (in few words)?
The goal of this how-to is to provide an almost out-of-the-box setup, with no file modification, few commands and easily revertible.
This page is not dedicated to full zRAM coverage and tuning, there are some other resources linked at the bottom of this topic.
By default zRAM is not activated in OpenMandriva Lx, but it has some benefits to use it.
zRAM allows to compress the RAM. Since the compression/decompression of RAM takes less time than the use of the hard disk in the form of virtual memory (known as the “swap disk”), this makes it possible to increase the responsiveness of a Linux system.
Also, as having a swap avoid full memory crash or hang, there are performance benefits using zRAM swap.
zRAM can exist alongside classic swap (file or partition): a classic case can be to use zRAM for almost all memory pages management and classic swap for hibernation and hybrid sleep. What is important is to give the higher priority to zRAM (swapon -s
to see it, higher number means higher priority). By default zRAM has a higher priority in OpenMandriva Lx if installed.
example:
Filename Type Size Used Priority
/swapfile file 16051516 0 -2
/dev/zram0 partition 4012028 853872 16383
If you simply want to use zRAM without having all the explanations, just read the following paragraph (Summary of the commands to execute) else read the detailed steps below.
Summary of the commands to execute
In case you’re in hurry, here are the commands. Detailed steps are below.
Open Konsole (or another terminal) and run
sudo dnf install zram-init
sudo modprobe zram
sudo systemctl start zram_swap.service
sudo systemctl start zram_tmp.service
sudo systemctl start zram_var_tmp.service
sudo systemctl enable zram_swap.service
sudo systemctl enable zram_tmp.service
sudo systemctl enable zram_var_tmp.service
Detailed steps
Summary
With few commands and a package including some convenient scripts, we will
- activate zRAM module
- setup a zRAM swap (used to get more stabilty and performance)
- Add an extra layer of performance by using zRAM instead of tmpFS for /tmp and instead of local drive for /var/tmp)
Note: you can have both zRAM swap and traditional swap (partition or file), latter being used for storing not (or hardly) used memory pages, especially after long uptime, and even activate hibernation. There is another topic dedicated to swap.
Module activation
install zram-init
sudo dnf install zram-init
It will install several services and a new configuration file for zRAM kernel module at /etc/modprobe.d/zram.conf (which you can edit to tune your preference, if you know what you’re doing) . The module will automatically be enabled at boot. To activate it immediately, run
modprobe zram
optional: check module activation
Check that the module is activated with
lsmod| grep zram
which should provide that kind of output
zram 36864 4
services activation
Three new services are provided, each of them can be tuned by editing the files in /lib/systemd/system/
:
- zram_swap.service
- zram_tmp.service
- zram_var_tmp.service
Please refer to our systemd documentation if you want to know how to start/stop and enable/disable services.
Activate zRAM swap
sudo systemctl start zram_swap.service
sudo systemctl enable zram_swap.service
Optional: check swap is activated
swapon -s
which should provide that kind of output
Filename Type Size Used Priority
/dev/zram0 partition 4012028 0 16383
use zRAM for /etc and /var/etc
Optional: check configuration before
If you run df -h you should see that you have several drives on a temporary filesystem (tmpFS), and especially /tmp
…
tmpfs 2,0G 24K 2,0G 1% /tmp
…
Run the commands
Start and enable services
sudo systemctl start zram_tmp.service
sudo systemctl start zram_var_tmp.service
sudo systemctl enable zram_tmp.service
sudo systemctl enable zram_var_tmp.service
Optional, check configuration after
by running df -h, you should now see that both /tmp and /var/tmp are mounted on /dev/zram
…
/dev/zram1 2,0G 24K 2,0G 1% /tmp
…
/dev/zram2 2,0G 24K 2,0G 1% /var/tmp
…
Revert: unactivate and uninstall
Reverting mainly means stopping and disabling the services
sudo systemctl stop zram_swap.service
sudo systemctl stop zram_tmp.service
sudo systemctl stop zram_var_tmp.service
sudo systemctl disable zram_swap.service
sudo systemctl disable zram_tmp.service
sudo systemctl disable zram_var_tmp.service
You may also want to disable the zram module. You should uninstall zram-init and in case you made some tuning also delete the modprobe zram conf file.
sudo dnf remove zram-init
sudo rm /etc/modprobe.d/zram.conf
reboot.