Linux Performance: Almost Always Add Swap Space — Part 3: No SWAP

Read the full article: Linux Performance: Almost Always Add Swap Space — Part 3: No SWAP

Previous articles covered traditional swap and alternative methods like ZRAM to improve Linux memory management and performance. However, sometimes removing swap altogether can sometimes work well, especially in systems with plenty of RAM dedicated to critical workloads. This article looks at scenarios where disabling swap makes sense, then walks through setting the swappiness parameter to… continue reading.

I just played a bit with zswap and zram.

These provide a way to compress data in ram that was not being used for a while, so hopefully save on wear on the ssd.

I am playing with a few distros on VirtualBox VMs, and My host machine has 16gb ram and an ssd

I really don’t want to hit the ssd.

I chose to have the swap be on a file, which may be nice for wear leveling on the ssd.

I allocated 8gb ram to my vm, and then did the default setup for zswap.

I am using Manjaro. Zram was not used so I didn’t have to disable it. It may be backwards…

1 Like

Welcome to our community. Thanks for taking the time out to share what you have been experimenting on.

Nice setup! You’re on the right track. zswap compresses pages before they hit your swapfile, thus reducing SSD writes. While zram is a compressed swap device in RAM and doesn’t touch disk at all.

If you would not like to use SSD at all for swapping, then the best approach would be to remove the swapfile and use 2 to 4 GB of memory for zram. Increase if needed, but remember, due to 3:1 to 4:1 compression ratio (zstd Algorithm), reserving 4 GB of zram results in ~ 8 GB additional memory.

If you prefer to keep a swapfile and just want to minimize SSD wear, then zswap makes more sense here. Manjaro sometimes enables zram, by default, so make sure not to be running both.

Setting vm.swappiness between ~ 10 and 100 can help delay or encourage swapping that suits your workload.

Also see the article, comments and zswap vs. zram comparison table here:

While it probably wouldn’t “hurt” anything if I used zram or altered “vm.swappiness”, the simple fact of the matter for me is that I don’t run gobs of programs at the same time, I currently have 8 GB RAM on my system and with the most frequently used distribution, I only exceed 1 GB actual usage when I momentarily have several browser tabs open.
For instance, with Ungoogled Chromium and four tabs open and only a simple roxterm open otherwise, my headroom is plentiful.
Even when I jump into CachyOS or EndeavourOS, which consume additional memory, I’ve STILL not hit a danger spot; besides, if I did, I’d just reboot, or in the worst case, hit the power button and move to one of several other multi-boot distros I happen to have available.
This isn’t the first time I’ve done this; when I was in a UNIX development group in the mid nineties, I’d use my own workstation with no swap because, again, I wasn’t approaching full memory; besides, any SUPER big stuff I’d just run on one of the department servers; my workstation was a USER workstation.
The three parts in this series have certainly made us aware that frequent swapping requires moving processes OUT of memory into much slower drives; the use of zram can lessen that, but it begs the question - unless you’re running out of space, why swap at all? Also with the price of memory, unless the system has no more room, just get more memory!

Do any of you have anything compelling to say to convince me, other than for “curiosity” or “play time” why to do anything with swap?

By the way, when I decided to get rid of my swap file and/or swap partition, one reason I did so was that I noticed, day after day, … ZERO swap use; I haven’t been sorry; oh, I can’t “hibernate” - don’t miss that either.

1 Like

On my 32gb Ryzen Desktop I’m running Linux with a 1gb swap partition.. it might be a bit small for swap :confused: but I saw with 32gb ram is pretty useless, as soon I don’t do some intensive work such as 3d animation or rendering…

The only thing keep me a little alarm are the virtual machines: but I saw using 32gb ram, again, and configuring the software using only ram for run virtual machines instead swap, I’m able to turn on all my virtual machines without touching a single byte of swap.. (I currently have 8gb ram Windows 10 and a a 6gb ram Debian stable virtual machines).. they both fit without problems on my ram.

This is pretty outstanding!

I have 15 "pinned’ tabs that must open every time I launch the browser. Including email, AI, analytics, observability, remote backup management, proxy services like Cloudflare, CRM, personal, etc, etc.

Then on top of that maybe it’s ADHD or just my way of work flow but I always seem to have 3 or 4 main things I need to get done. Then I also have the blog and forums open. So right now this is on the low end of tabs I usually keep open:
image

System uptime right now is low because I booted into Windows 11 yesterday. However, swap usually only get used after a few days of uptime:

Zram is useful for me because once a page is selected for swapping, Zram will compress and store it in RAM so keeps the direct memory access in use for more active or higher priority tasks.

This is my desktop PC, so it sleeps (GNOME calls that Suspend). But I don’t use hibernation, as I tested with Kill A Watt a while back and the power draw is basically nothing during suspend.

Then I have Google Drive sync’d via Gnome online account and and so over time as I access files remotely it uses a ton of RAM there as well.

I like this approach because even if I nuke my system, everything important is stored remotely. I sync most home/user/ folders to drive for both desktop and laptop. This also allows me to continue working on files across desktop, laptop, and mobile.

I think those are probably the main reasons why my memory usage is high. On first boot its also < 1G at least until I resume tabs lol.

That’s precisely why one size doesn’t fit all. People wonder why there are so many variations and distribution options; your experience compared to mine is suggesting a few of the reasons

Thank you for your details.

2 Likes

Well said. Very true. We all end up with a tailored solution that best meets each use case.