Nerd For Tech
Published in

Nerd For Tech

Dynamically Increase SWAP (ZRAM) Size in Linux

Out-of-memory? No problem!

Source: GIPHY & Creazilla

Introduction

Swap memory is useful, but no one likes it when it’s slow. Swap in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space.

Fedora particularly has been using swap-on-zram by default for years and comes by default on Fedora Workstation. ZRAM creates a block device in RAM where pages that would otherwise be written to swap (disk/ssd) are instead first compressed, then stored. This allows for much faster I/O of swap, and also the data compression provides a great amount of memory savings.

The zram device, typically /dev/zram0 has a size set at create time during early boot, by zram-generator per its configuration file. The memory used is not preallocated. It’s dynamically allocated and deallocated, on-demand. Due to compression, a full /dev/zram0 uses half as much memory as its size.

The system will use RAM normally up until it’s full, and then start paging out to swap-on-zram, same as a conventional swap-on-drive.

Dynamically increase swap size on-demand

If you are using Fedora Linux, you should already have zram0 setup and running. You can run the following command to verify:

Now, edit the zram-generator configuration file located at /usr/lib/systemd/zram-generator.conf

And increase the SWAP size as desired, e.g: increase it 1x the RAM size.

Finally restart the service to take the new configuration in effect.

Verify that the swap size has increased by running the following commands:

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

Why programming languages? (On the languages of machines and people)

Intro to Algorithms: Chapter Four, the Maximum Sub-Array Problem

Stand Up To Imposter Syndrome: Attend a Hackathon

Part 1. Asynchronous actions within AWS Step Functions without servers

How SSD VPS can Enhance Your E-Commerce Website

UPCOMING CHANGES TO THE INVERSE PLATFORM

BigTips: INFORMATION_SCHEMA Views in BigQuery

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Puru Tuladhar

Puru Tuladhar

Make Complex Simple (https://tuladhar.github.io)

More from Medium

How to Configure SSH Jump Server | Ezeelogin

PiHole, Docker and Google Nest adventures 👩‍💻

Setup Gitlab Backup into S3 Bucket

Developing apps with docker