Zram, https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html, is a Linux kernel module that creates a compressed block device in RAM. This device can be used as swap space or a general-purpose RAM disk. By compressing data in memory, zram allows your system to store more data in RAM, reducing the need to swap to slower disk storage and improving overall responsiveness.
In particular, zram
- Increases effective RAM capacity by compressing data.
- Reduces disk I/O and wear, especially useful on SSDs.
- Improves performance on systems with limited memory.
If you’re looking to boost your Linux system’s performance, especially on machines with limited RAM, zram is a powerful tool worth exploring.
In this post, I’ll show how to set it up on both Arch Linux and Ubuntu.
Installing zram
On Arch Linux
Install the zram generator package:
1 2 |
sudo pacman -S zram-generator |
On Ubuntu
Install the systemd zram generator:
1 2 |
sudo apt install systemd-zram-generator |
Configuring zram
Create a configuration file to set up your zram device. For example, to allocate half of your system’s RAM to zram and use the efficient zstd
compression algorithm, run:
1 2 3 4 5 |
cat <<-EOF | sudo tee /etc/systemd/zram-generator.conf [zram0] zram-size = (ram / 2) compression-algorithm = zstd EOF |
After saving the configuration, reboot your system to activate zram.
By default, zram will have the precedence over an existing swap partition.
You can use the command zramctl
to see the status of zram and swapon
to show your swap partitions (zram’s one will be /dev/zram0
).
Thanks for the information. I’ve been using zram-tools on Debian systems and zram-generator on Arch systems. But I didn’t realize that zram-generator also was available on Debian systems.
Wonderful and very useful article as always. On a completely different note is there any chance we get a small series exploring the go language? I have been experimenting with it and albeit a bit convoluted at times It Is quite a fantastic language.
I’m afraid “go” never attracted me…
It certainly makes sense as you from what I can gather are very Deep on the Java ecosystem. In my biased experience I found go works great but I do not love oop heavy software architecture (besides your Metodologie di programmazione course!).
Thanks for the kind reply (maybe When I Will have to write my thesis I wont propose something in go 😉 )