Concerns For Swap on ZRAM

Hey fedora community, I am reaching out to hear opinions/experiences of fedora users who use the default partitioning for the encrypted setup. I am concerned whether having 8GB of RAM would cause any issues for me. I sometimes need to run a Windows or Linux VM with 4GB of RAM allocation and I do not know whether swap on ZRAM would cause running out of memory. Should I use the default layout with btrfs+zram or should I consider a layout like ext4+swapfile.

First, the choice of btrfs vs ext4 seems like a separate decision to a swapfile vs zram.

That being said, there is no one right answer here. It really depends on the specific workload. However, keep in mind that if you use disk based swap and the active processes need more memory than you have available, the machine might not crash, but it will be slow. On the other hand, zram is compressed swap in ram.

My advice would be to try the default setup. If for some reason that doesn’t work for your use case, it is easy enough to switch to a swapfile after the fact. You could also try zswap in that scenario.

2 Likes

I gave out both use cases specifically since according to my research I need to create a separate subvolume since swapfile needs copy on write to be disabled and creating another subvolume feels like a big headache. Also, what is zswap?

That is a very, very small headache. It requires copying and pasting a handful of commands and takes only a couple of minutes.

Short answer: It uses a compressed memory cache backed by physical swap.
Long answer: zswap - ArchWiki
Longer answer: zswap — The Linux Kernel documentation

1 Like

Go with the default.
It will work, and just in case it does not, it will be easier to get support.

1 Like

I second @dalto’s approach, just go with zram and add a 10GB swapfile to your system (doesn’t really matter if fs is btrfs or ext4).

That way, once zram is full, it can swap to disc and everything will become slow but won’t crash. You also want to monitor memory usage, as systemd-oomd may terminate processes as memory fills up and I had several cases where the daemon thought it was a good idea to kill my vm. Since that day, I have disabled that daemon.

The best would be to add another 8GB of RAM to the machine if possible, because 4GB for the host and 4GB for a VM isn’t enough these days, especially if you want to use browsers with a few tabs open on the host and/or VM.

EDIT: offtopic, but fun.
I have several browser tabs, where a single tab consumes > 4GB of RAM, but of course, everything is about use case.

1 Like

Yeah unfortunately, RAM is soldered so HP does not want me to have more RAM. In terms of having both a swapfile and zram, can the kernel alternate between them? Also if I how should I create the subvolume for swap? If I create it while the system is online (inside root), would it make a difference in backups, how should I approach it?

If you want both, in most cases, zswap is a more suitable solution than zram.

sudo btrfs subvolume create /swap
sudo btrfs filesystem mkswapfile --size 4g --uuid clear /swap/swapfile
sudo swapon /swap/swapfile

Replace 4g with the size of swap file you would prefer.

You don’t need to do anything special. You can create a swapfile in a normally running system. It doesn’t even require a reboot.