HOW TO ENABLE VIRTUAL MEMORY ON LINUX TO IMPROVE PERFORMANCE

Linux offers virtual memory support known as SWAP that is very common and reliable among the Linux systems. This feature is for the computers with limited or minimum system resources that are being used for other processes as well. The ZSWAP is a kernel feature in 3.8 version that compresses the swap cache and makes it possible for the system to never slow down as the SWAP file deals with the IO of HDD and if continuously used, it may result in performance drop down of the hard disk.

Setting up ZSWAP ON LINUX

The ZSWAP actually compresses the SWAP file and improves the performance of the Linux system. It is very easy to setup ZSWAP on Linux, all you need is to follow a few simple steps to enable SWAP.

For Debian/UBUNTU

It is an optional Linux kernel parameter so it is not found in the settings, you need to work with the bootloader to enable ZSWAP. While using the Ubuntu, you need to use GRUB so to access the Grub configurations. It is necessary to back up the Grub configurations so if anything goes wrong, you can easily reverse back to the previous settings. It is a command line argument.

To backup Grub, get the root access using su or sudo -s command in the terminal. In the Root shell, use the CP command to make a backup of the Grub configuration file.

cp /etc/default/grub /etc/default/grub.bak

Enabling Zswap in Ubuntu

When the Grub configurations are backed up, you need to open it in the Nano to edit.

nano -w /etc/default/grub

In the Nano editor, find the GRUB_CMDLINE_LINUX_DEFAULT.

It has different command-line arguments including quiet splash and various others. All you need is to add an additional argument at the end.

zswap.enabled=1

Ubuntu Zswap Grub Configuration File

Use Ctrl + O to save the file and exit using Ctrl + X hotkeys. Update the Grub bootloader using command sudo update-grub

Reboot the Ubuntu so the changes take effect.

Disabling Zswap in Ubuntu

Open the terminal and go to root using su or sudo -s command. Delete the Grub file using rm command

rm /etc/default/grub

Restore backup that you previously created

cd /etc/default/

mv grub.bak grub

Update the grub to roll back the changes.

sudo update-grub

For Fedora or OpenSUSE

The Fedora uses RPM and Redhat tools which means that you can enable the Zswap as you update in Ubuntu using GRUB.

Enable Zswap in Fedora or OpenSUSE

Backup the Grup, get root access using su command and backup the grub using

cd /etc/default

cp grub grub.bak

Enable Zswap using Grub configuration file command.

nano /etc/default/grub

Find the code in Grub configuration file for GRUB_CMDLINE_LINUX_DEFAULT= or GRUB_CMDLINE_LINUX=

Now add ‘zswap.enabled=1’ at the end of the code before quotation marks. Use Ctrl + O to save and Ctrl + X to exit. Update the bootloader using grub2-mkconfig command

grub2-mkconfig -o /boot/grub2/grub.cfg

Enable zSwap in OpenSUSE

Disable Zswap for Fedora or OpenSUSE

Gain root with the su command.

su -

move into /etc/default/ using cd command

cd /etc/default

now delete the Grub file with rm command

rm grub

Restore the Grub backup file with mv command

mv grub.bak grub

Update Grub with grub2-mkconfig command

grub2-mkconfig -o /boot/grub2/grub.cfg

For Arch Linux

If you are using Arch Linux, you also enable Zswap by installing the package and enabling it using system init system.

sudo pacman -S systemd-swap

or

sudo systemctl enable systemd-swap

Reboot the computer so that changes take effect.

Leave a Reply

Your email address will not be published. Required fields are marked *