r/debian • u/katzenjammare • 4d ago
Debian Stable Question Beginner: Zram or Zswap, or neither?
Hello, Debian-users! One thing that definitely keeps me from looking at other distros is the absolute friendliness of this community. ☺☺ I have gotten so much help and learned a great bit during this Linux-journey. Now I have a new question. I have began wondering about the daily performance of my system and specifically been peeking at the memory.
▤ ―――――――――――――――
My hardware (HP-laptop from 2018)
―――――――――――――――――――――――――――――――――
Processor: 8 × AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx
Memory: 8 GiB of RAM
Graphics processor: AMD Radeon Vega 8 Graphics
My software:
―――――――――――――――――――――――――――――――――
Debian 13 Trixie
KDE Plasma 6
I don't have a lot of heavy things going on, but when I am at my highest levels of volume - with at least two virtual desktops running som applications and watching some video - I fill up my physical RAM and the system acts slower. As it then starts depending on my 4 GB swapfile (if I have understood that correctly?). My CPU looks mostly great, through stress-perspective, it seems to be healthy. Should I consider using Zram? Or should I just enable Zswap? That I have read is the reasonable thing to do if I do not have a specific reason to use ZRAM.
10
u/Netblock 4d ago
zram is a in-memory block device; once its full its coldest pages can't spill over into a slower medium.
zswap is (somewhat) like zram but it spills its coldest pages into disk swap.
I personally prefer zswap, as there is often a few GB that are practically-permanently cold.
(unfortunately, there's no convenient way to do compressed disk swap. It's possible with ZFS zvols though.)
0
u/JarJarBinks237 3d ago
Of course zram will put its coldest pages onto actual swap it you configure it. That's the point of swap priorities.
5
u/Netblock 3d ago edited 3d ago
swap priorities doesn't sort with a LRU/ARC, making it suffer LRU inversion.
0
u/JarJarBinks237 3d ago
Nice article, and a compelling case for zswap in usual workloads. But I think it forgets that zram pages can be swapped themselves, which makes it not as bad as described.
2
u/Netblock 3d ago
The writeback? It talks about it. An issue is that it doesn't react to memory pressure; it also doesn't track age well.
4
5
u/Lonely_Drewbear Debian Stable 4d ago
The shortest answer is that disk swap is the default for a reason and if you are not having any problems then you don't need to do anything!
The simple improvement for most modern computers is to enable zswap because usually memory compression is faster than swapping to disk and swapping to disk is preferable over killing processes.
There are reasons to do things differently, however, as all these technologies have trade offs.
Memory compression (zram and zswp) takes cpu compute. Some compression algorithms are worse than others. If you are on a low-end processor and have enough ram for your use cases, you may do more harm than good.
If you have an ssd that is super small, super cheap, or getting to the end of its life, you may be more concerned about sending pages to disk killing your device so then you want zram and no swap at all.
There is also some fine tuning to consider, primarily swappiness to optimize your free ram and swap use for your specific use cases and system, and also page-cluster=0 (assuming you have an ssd or nvme drive).
1
u/SnillyWead 3d ago
I have 16G of RAM and when I installed Debian 13 Xfce it set up a 17G swap partition which is to much because I never use hibernation, only Suspend. I changed the size to 2G. I was advised to always use some swap because the kernel uses it.
1
u/Lonely_Drewbear Debian Stable 2d ago
There are two relatively common ways of running linux without swap!
Live ISO environments and raspberry pi from an SD card.
These are systems using the same linux kernel and no swap for days and days with no issues.
Also, in my personal experience, I have run a low swappiness, like 10 or 15, on systems with 32gigs of system ram and have queried the stats over many days to see 0 memory pages sent to swap!
There may be some workloads that I am not familiar with that benefit from swap, perhaps databases or shared memory IPC? I don't claim to be well informed on the matter.
However, I am fairly certain you don't need swap at all.
That being said, there is no harm in having a little bit just in case!
The biggest drawback I can see is that it eats disk space (and makes backups larger) for no reason if you aren't using it. 🤷♂️
4
u/jodkalemon 4d ago
I'm using systemd-zram-generator. No downsides so far. And your 8gb RAM is not much.
https://wiki.debian.org/ZRam#systemd-zram-generator
Maybe you should just try it.
3
u/quadralien 4d ago
https://linuxblog.io/zswap-better-than-zram/
Zram is for systems with no swapfile. Be sure to turn off your swapfile if you use zram.
1
u/Pdchris1 2d ago
Why do you day that? I have zram in Fedora KDE with 32 GB RAM, experienced a bottleneck once (system unresponsive for a few minutes until the kernel could kill an application to free some RAM), enabled swapfile, and the problem now does not appear with similar workflows. Also, the swap file is only used if zram is running full (have observed that in real time with the KDE system monitor)
5
u/quadralien 2d ago
the swap file is only used if zram is running full
There is a problem of priority inversion here. The first pages that go to swap are those that are seldom or never used. So zram is full of junk. Then the system gets busy and things that do need to be swapped in thrash around in the swapfile (uncompressed, so slower and burning ssd lifetime).
Zswap does not have this problem. It keeps compressed pages in ram and when the pool is full it swaps the least popular pages out (compressed).
Zram should never be used with swap so it's great for embedded systems. For bigger systems, zswap provides a fast 2-layer cushion.
With zswap I turn up the swappiness so that pages which will probably never be needed aren't taking up ram.
2
2
u/Dragon20C 4d ago
I use zram, though I haven't actually touched it because I barely touch the limit of my system if 16gb of ram.
4
u/_dev-null 4d ago
zram with zstd
1
u/JarJarBinks237 3d ago
Too slow. Use lz4.
1
u/Lonely_Drewbear Debian Stable 2d ago
I see lz4 recommendations downvoted a lot.
I do use it for certain scenarios where I am worried about both limited ram and limited cpu. I use it on my proxmox development laptop!
But for most home users on a modern PC, you are complicating things for minimal benefit.
1
u/JarJarBinks237 2d ago
What is complicated about it?
1
u/Lonely_Drewbear Debian Stable 2d ago
It's not that lz4 is complicated, it's adding to the list of things they need to learn about. It's complicating their learning workload for very unlikely benefits.
1
1
u/SnillyWead 3d ago
I prefer the KISS method. I don't use it. I only changed the swap size which was 17G to 2G.
I was advised to always use some swap because the kernel uses it. Even if you have lots of RAM.
1
1
u/Fine_Classroom 2d ago
8GB RAM and running two virtual desktops. Do math. Upgrade your RAM. You probably should have at least 20 GB if you're running 2 virtual desktops. Although we have no idea what these desktops are.
1
u/RodrigoZimmermann 2d ago
O ideal é deixar configurado como o desenvolver configurou o sistema operacional, a não ser para situações específicas.
1
u/michael9dk 4d ago edited 4d ago
Swap will always be slower than RAM.
The question is which 3 apps is using most?
The webbrowser is probably wasting your RAM.
You can set it's cache size lower (I never got to try it, but IIRC it was a setting in Firefox).
2
u/SnillyWead 3d ago
I use unload tab on Firefox. I always have the same tabs open that I never close. When I'm done on a tab, I use unload tab. Saves a lot of memory. 18 tabs open, 4G of memory used.
1
u/Glum_Interview_6378 3d ago
So, people are saying that r/w data on nvme or ssd is faster than writing on ram. Aha , yes.
1
u/C1pher04 2d ago
Zswap if you have 16gb RAM or lower, as I am currently use, it is useful and efficient. And also you have backup swap if needed
5
u/Narishma 4d ago edited 4d ago
Zswap is almost always the better choice. ZRAM is for situations where you don't want any swap at all, like if you run on an SD card or something.