brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: zramctl shows the compressed swap that lives in your RAM

Linux
~/tips/tip-linux-zramctl-compressed-swap

zramctl

Lists zram devices and sets up compressed swap in memory.

Many distros now set up zram for you, and then free just shows some swap without saying that it is a compressed block of memory. zramctl shows the details.

Without arguments it lists the zram devices that exist:

zramctl

On a machine without zram devices it prints nothing. Where zram swap is active you get one line per device, and -o picks which columns to show. zramctl --help lists the available column names.

Creating a device by hand follows the example in the man page. It finds the first unused zram device, initializes it with a size, and then you format and enable it as swap. The first command prints the device it picked, so use that name for the next two:

sudo zramctl --find --size 1024M
sudo mkswap /dev/zram0
sudo swapon /dev/zram0

To undo it, switch the swap off first and then reset the device:

sudo swapoff /dev/zram0
sudo zramctl --reset /dev/zram0

The -a option (--algorithm) picks the compression algorithm. The settings of a zram device can only be changed after a reset, so choose the algorithm together with the size when you create it.

Use the device name that --find printed, not automatically zram0, otherwise you may touch a device the system already uses. The commands also need root, and a bad --reset on a device that is in use for the system swap is something to avoid. zram trades CPU time for memory, so it helps on a small machine, but it is not extra RAM.

Further reading: zramctl(8) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link