> ## Content Index
> Fetch the complete content index at: https://www.ctrl.blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to resize ZRAM (compressed swap) managed by systemd/zram-generator
- URL: https://www.ctrl.blog/entry/how-to-systemd-zram-generator/
- Published: 2020-11-13T04:45:00.000Z
- Updated: 2026-08-23T22:11:04.000Z
- Description: zram-generator’s default configuration uses 50% of RAM or 8 GB. You may want to increasing these limits if you’re throttled by low memory or swap performance.
- Author: Daniel Aleksandersen
- Tags: Fedora Linux, Linux

Fedora Linux 33 was released last week with some [interesting changes](https://fedoraproject.org/wiki/Category:ChangeAcceptedF33?ref=ctrl.blog) like switching the default file system to BtrFS, handing DNS resolution over to [systemd-resolved](https://www.ctrl.blog/entry/systemd-resolved/), and enabling ZRAM instead of a swap partition by default. I’ll focus on the latter feature in this article.

ZRAM is a Linux kernel subsystem for handling compression of volatile memory (RAM). Compression sacrifices some processor time in exchange for more space-efficient utilization of your available RAM. ZRAM acts like a traditional storage drive backed swap partition, except that it lives entirely in your system RAM. The exact compression ratio you can expect depends on what you’re keeping in memory.

Fedora Linux uses `systemd/zram-generator` to manage the creation of the virtual ZRAM device during system boot. This is handled through a `systemd` service called `systemd-zram-setup@zram0.service`. This service is enabled by default in new installations and on upgrade from earlier versions of Fedora Linux.

If you have a swap partition *and* ZRAM enabled, the system will prefer swapping out memory to the ZRAM device before falling back to the slower swap partition. Note that you can’t hibernate into [something that only exists in memory](https://www.ctrl.blog/entry/linux-hibernate-tmpfs/). Hibernation still isn’t officially supported by Fedora Linux so this wasn’t a concern for their decision to switch to ZRAM by default. However, I’ve updated my [tutorial on enabling hibernation in Fedora Linux](https://www.ctrl.blog/entry/fedora-hibernate/) with more details.

The default configuration of the `systemd/zram-generator` will create a ZRAM device of 50 % of the physical volatile memory up to 8 GB (whichever is smaller). My typical workload involves a lot of text processing and data that compresses well, so I wanted to increase the size of the ZRAM device. My primary computer has 32 GB of physical volatile memory and 16 processor threads, so it should have plenty of backing resources to spare. I also wanted to increase the ZRAM device size on my servers and virtual private servers (VPS).

To increase the size of your ZRAM device, create the file `/etc/systemd/zram-generator.conf` and include the below configuration example. (You can also leave an empty file in this path to disable ZRAM.)

```ini
[zram0]
zram-fraction=0.5
max-zram-size=4096
```

The limits given above matches the default limits (50 % of available memory or 8 GB in MB). Change the limits to your preference. Keep in mind that the system can become unstable if you set it too high. I suggest staying with the default factor of 0.5 and increasing the max size to match your available system memory. For example, set `max-zram-size=8192` if you have 16 GB of RAM.

You can experiment with different settings to discover what works best for you. Check out the [zram-generator.conf manual page](https://github.com/systemd/zram-generator/blob/master/man/zram-generator.conf.md?ref=ctrl.blog) for more configuration options like how to change the default compression algorithm.

I followed my own advice on my primary desktop computer. However, I set the limits fairly high on my low-memory budget VPSes. These servers run under constant high-memory pressure, but I was able to effectively double their available memory with ZRAM. Constant memory constraints is the hallmark of budget VPSes. I’m a bit annoyed with myself for not exploring compressed RAM earlier.

You can recreate the ZRAM device immediately without a reboot if you have enough physical memory to hold an uncompressed copy of all your currently compressed memory. The commands `free` and `zramctl` can help you determine the current memory pressure and compression ratio. Run the command `systemctl restart systemd-zram-setup@zram0.service` to recreate the ZRAM device without rebooting. However, the safest and quickest option is probably to save your work and reboot.

The configuration file at `/etc/zram.conf` is a legacy file that is no longer used.

**Update** (2021-05-03): Fedora Linux 34 changed the default maximum zram size from 4 GB to 8 GB, and from 25 % to 50 % of physical RAM. The `swap-create@zram0.service` was also renamed to `systemd-zram-setup@zram0.service`.

#### Sources

- [Changes/Scale ZRAM to full memory size](https://fedoraproject.org/w/index.php?title=Changes/Scale%5FZRAM%5Fto%5Ffull%5Fmemory%5Fsize&oldid=602477&ref=ctrl.blog), revision 602477, 2021-01-27, Wiki, Fedora Project
- [Changes/SwapOnZRAM](https://fedoraproject.org/w/index.php?title=Changes/SwapOnZRAM&oldid=590520&ref=ctrl.blog), revision 590520, 2020-10-13, Wiki, Fedora Project
- [zram-generator man page](https://github.com/systemd/zram-generator/blob/0b49fad8cbcbbef1c7711ca046a6b83ba50ed8f2/man/zram-generator.md?ref=ctrl.blog), commit 0b49fad8cb, 2020-06-19, Ahelenia Ziemiańska, systemd/zram-generator project, GitHub
- [zram-generator.conf man page](https://github.com/systemd/zram-generator/blob/0b49fad8cbcbbef1c7711ca046a6b83ba50ed8f2/man/zram-generator.conf.md?ref=ctrl.blog), commit 0b49fad8cb, 2020-06-19, Ahelenia Ziemiańska, systemd/zram-generator project, GitHub
- [zram: Compressed RAM-based block devices](https://www.kernel.org/doc/html/latest/admin-guide/blockdev/zram.html?ref=ctrl.blog), commit 56e6b3b0b3, 2020-02-06, The Linux kernel user’s and administrator’s guide, Linux Kernel Project