I am trying to see whether an Atomic Distro would work for me and this is the next hurdle I am having trouble with. After using ZRAM on a regular system, I decided that a swap-file would be a better choice. I had no problem disabling swap on regular Fedora since removing the specified package is sufficient. On the other hand, on an Atomic distro, this method is not ideal (I think).
I am aware that it is achievable with rpm-ostree; however, I wanted to ask it here since if I start to modify packages, where will it end… Also I assume that creating a swap-file should be straightforward since /var and /etc are writable.
I’d be interested in understanding your use case.
I think it’s always been the other way round for most use-cases.
zram prevents systems hangs where disk swap will not wen the system is under memory pressure.
The issue I have is the fact that my Laptop has 8GB of soldered RAM and Swap on ZRAM has always limited what I can do with the memory. The most annoying issue I had was the fact that firefox would randomly start consuming all the available RAM, freezing the system which had eventually leads kernel to kill firefox. While I could still retrieve my old tabs and no other app was crashing, it was taking 5-10 minutes for kernel to kill firefox, meanwhile rendering the system unusable, and I imagine that it would lead me to loose unsaved work on firefox.
I do acknowledge that swap on ZRAM would help preserving the health of a SSD; however, I believe that swap is meant to increase the amount of memory you have so that the system would not crash or would be in a position to crash. I do not think that swap on ZRAM does this. I understand that swap-file would have a worse performance than ZRAM; but, personally, I have not noticed any freezes or glitches. I am currently using a 10GB swap-file and have not had the issue I mentioned above since. I hope I can do the same setup on Kinoite without modifying the base image.
Looks very efficient and it works. Since there is a package called zram-generator-defaults, would this modification break after an update or would the symlink not be affected?
Swap does not alter the amount of memory the system has.
Swap can alter the amount of data that can be swapped out to storage from the usable memory and swapped back in when needed.
Zram for swap provides storage in compressed format for the data that has been swapped out while physical swap does not get compressed when written.
On a btrfs swap file there is an inherent delay with every single write. Btrfs does Copy on Write (COW) so there is much additional over head with writing to swap on a btrfs swap file.
For efficiency and to greatly reduce wear on the SSD when using physical swap I would choose to shrink the btrfs partition slightly then add a new dedicated partition to use as swap, which avoids the overhead and wear of swap on btrfs.
I am using an encrypted setup with Btrfs on top of LUKS which makes the resizing extremely difficult. Plus I wish the swap to be encrypted as well and going this route makes the setup way flexible since I can modify swap allocation according to my needs. Also does not swap-file setup for btrfs disable COW on the swapfile since COW is not supported for swap-files? Does the overhead still persist just because the FS has that feature?
Swap increases the amount of memory that the kernel can commit to processes.
When physical RAM runs out and the kernel needs memory it will start to swap out pages to swap.
But the speed of the swap is critical to avoiding hangs or worse.
Swapping to an HDD is very slow, even swapping to an SSD is slow.
Which is where zram swap comes to the rescue, it is very fast and in extensive testing avoids many of the situations when a hang would happen.
You could look to tuning zram to set it’s limits to a low enough amount that you
are happy. See man zram-generator.conf for details.
Having both zram and SSD swap is also a useful setup.
This is actually the reason why you were experiencing hang ups with Firefox + ZRAM. If you r cpu is a little older ~2016 this could prove to be more difficult to handle. Also lower core counts and instruction sets on older processors would be bottlenecked here in certain scenarios.
My CPU is an AMD Ryzen 5 7520U with 4 cores. While it might be a bit old, I believe the release year is 2022. In addition, after the freezing and the forced termination of Firefox, I get the notification of it being terminated by the kernel due to consuming too much memory. In addition, I have been using a swap-file setup for 3 weeks and had not gotten the same issue since. I cannot understand why would my CPU be the problem in this situation.
Yes, you are right, swap must increase the amount of memory the kernel can use; however, when its with Swap on ZRAM, you use the actual memory to try to increase the memory you have. While the compression would allow you to allocate more memory, the amount of memory expansion you have with ZRAM is not comparable to amount of memory you can expand with a large swap-file.
Yes; but, its ultimately the kernel’s responsibility to manage Swap and RAM so that the performance is not affected. I am aware that Swap is not a substitution for RAM; but, I need a good amount of it so that my system would not hang.
The problem I have with ZRAM is the fact that its actually consuming some amount of my very limited memory that I can utilize for running other tasks. I believe that ZRAM is great for computers with high amount of RAM like >=16GB since they can spare some of the extra memory to make swap faster. I believe that Fedora must prefer swap-files or partitions for computers that have <= 8GB of RAM since it affects the stability of the system.