Linux Performance – Part 3: No Swap Space
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 zero and what that means.
Removing Swap
Swap space typically adds flexibility. When memory runs low, the kernel can move some data from RAM to disk-based swap. For resource-constrained systems, swap is very beneficial.
But in certain environments with plenty of free RAM and workloads tightly tuned for memory, removing swap can give you predictable performance, reduce disk I/O overhead and keep applications in active memory.
Removing swap completely on Linux
Removing swap on Linux typically involves a few steps. First, turn it off in the running system by entering:
swapoff -a
Then edit the /etc/fstab
file and remove or comment out any entries that refer to a swap partition or swap file. This prevents swap from being enabled the next time the server reboots.
Disabling swap eliminates one of the safety nets against unexpected memory demands.
If you use a dedicated swap partition, you can optionally reclaim or repurpose that partition after it’s disabled. If you use a swap file, remove (or rename) the file once it’s no longer in use.
Remember to ensure your system has enough RAM to handle its workload before going swap-free!
Setting the Swappiness Parameter to Zero
Swappiness controls how aggressively the kernel moves application pages to swap. Setting it to zero means pages stay in memory as long as possible. To change the swappiness parameter at runtime, enter:
echo 0 >/proc/sys/vm/swappiness
This setting takes effect immediately, but is temporary and won’t survive a reboot. To make it permanent, open or create a file in /etc/sysctl.d/
(or edit /etc/sysctl.conf
) and add:
vm.swappiness=0
Finally, apply the setting:
sysctl -p
From that point forward, swappiness remains zero after every reboot.
I recommend using swappiness=0
as the safer baseline. Avoid removing swap completely unless you are certain your environment can meet all memory demands without a swap safety net.
When swappiness is zero (swappiness = 0
), the kernel will try to reclaim memory from cache before moving application pages to disk. This avoids early swapping and ensures if your system has enough memory, pages stay in RAM, free from swap-induced latency.
Depending on the application, this can give you a performance boost if your workload benefits from maximum in-memory data and can cause issues if memory demand unexpectedly exceeds capacity.
When Does No Swap Help?
Three benefits of removing swap or setting swappiness to 0. First, systems with plenty of memory for apps and disk caching — like big database servers or high-performance computing clusters — get very little benefit from having swap. These systems have so much unused RAM that paging to disk never happens anyway.
Second, if your workload is stable and well-defined — like a production environment that’s been well-tuned, and memory usage is predictable — the risk of OOM is very low. In this case, disabling swap eliminates the overhead of unnecessary disk paging.
Third, latency sensitive or near real-time processes suffer from unpredictable I/O delays whenever the kernel swaps. By keeping data in physical memory, you eliminate this source of jitter and for more consistent performance.
Also see: Are you measuring Linux web server memory usage correctly?
When Does No Swap Hurt?
Do not remove swap or set swappiness to 0 if your system has low available memory.
Running a completely swapless system removes the safety net if RAM usage spikes unexpectedly. Hitting the memory limit without swap can result in the kernel’s OOM killer terminating critical processes. For hardware with limited memory or high variability in workload memory demands, you should rely on swap space or alternative solutions like ZRAM to avoid system instability.
Also see: Free vs. Available Memory in Linux.
Conclusion
This wraps up our look at instances of where you should “almost always add swap space”, as well as when “no swap” is beneficial.
Previous articles
- Linux Performance: Almost Always Add Swap Space — Part 1.
- Linux Performance: Almost Always Add Swap Space — Part 2: ZRAM.
- Running Out of RAM on Linux? Add Zram Before Upgrading!
Removing swap may seem risky, but for certain servers or applications with ample memory and predictable usage, it can boost performance and predictability. Setting swappiness = 0
effectively prevents application pages from being swapped to disk, ensuring that disk I/O remains minimized in normal operations. Keep a close eye on memory usage and be prepared to reintroduce swap if demand changes.
As always, monitor your system metrics, run tests, and adjust your approach based on real-world data.
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…
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.
On my 32gb Ryzen Desktop I’m running Linux with a 1gb swap partition.. it might be a bit small for swap
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:

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.