Swap or not to Swap?

Hi everyone whats your stance on swap? I currently have on my arch linux install 8 GB of RAM and when I was doing my install I was going to use swap on zram however on all my machines I’ve never noticed any slowdowns or the need for swap. The apps simply just don’t use it I think maybe once or twice it’s used under 500 MB of the swap file :rofl:

Currently my PC boots in using approx 511 MB I use XFCE as my desktop environment and when I start doing recording or web browsing I tend to use no more than say 2 GB of RAM which doesn’t clear as linux still gives that process space in the RAM unless it is never needed then you can release it.

Screenshot_2022-03-15_17-56-38
Screenshot_2022-03-15_17-59-52

If your RAM usage is barely 8GB, then swap isn’t needed.

Swap is mandatory when you want to have hibernate capability.

1 Like

It seems he makes some good points on why using a swap is beneficial to the well-running of a system regardless the amount of RAM. Perhaps more advanced users can find the time to read the article and comment on it.

I have 20GB swap on my 40GB RAM laptop, and 16 on my 16GB laptop. I use it for hibernation mostly.

I went with 20 in my one laptop because normally day to day I normally run 8-15GB use at a clip. It’s a swap file though so I guess if it’s ever not enough I could bump it.

Edit - I know there’s at least one or two fairly heavily covered topics on this here as well.

Red Hat is always a good source for technical advice.

Summary:

  • Systems without swap can make sense and are supported by Red Hat
  • configuring an amount of 20% of the RAM as swap is usually a good idea

My 2 cents:

I use swap on all my systems. Even on my high end PC with 64 GB of RAM I do have 12 GB of swap as zram.
And if I do not use zram, e.g. on my laptop, I prefer swap files.

1 Like

Just a thought on how to think of the reasons for swap. If you think of the system as scheduling and controlling its use, then you could picture it knowing that swap exists as a fallback, so it can be more aggressive with memory use - because the consequences are fewer if the results are off. If there is no swap, the system has to make sure that overruns don’t happen, which can be less optimal for performance.

If you want the story in better form - read the links above! :grin:

(I am aware that this is not a precise description - but it might do as a shorthand image)

I don’t have any issues without swap and I don’t use hibernation so :man_shrugging:

Ive been using swap file and i have no issues. Personally i don’t even think i need swap unless you are going to use suspend and or hibernate.

I’m not big on hibernation and or suspend. On some hardware it works well on others not so much. I don’t particularly want to use it if the graphics won’t come back to life from either. If it works well sure and you have a use. I don’t care about it really.

1 Like

Never used sleep before Linux, forgot it ever existed, but the speed it goes to sleep and turns back on… uff, can be real nice(more useful on Windows though). I just get 16GB Swap for hibernate(16GB RAM) everytime, though i barely ever used hibernate, sleep i use all the time.

I had an issue with VLC having to be restarted on Pop OS when returning from sleep as it would only play audio, currently that’s not a problem on EoS for me.

The only reason not to have any swap space is to test the system to see if works by removing one of the primary designs features of virtual memory. Why hamper the system by purposefully disabling one of the features of running an operating system designed to use virtual memory? For fun? For sport?
Maybe, if you are installed on a 32Gb (or less) primary storage device, not allocating some swap space gives and extra 1-2Gb of space for file storage. Even in that case, if you are running on a tiny SSD, you probably cannot afford more than 4Gb of ram, so swap space is even more important to have.
Why is this even a concern? Are people here starving for a couple of Gb’s of space? Really? :face_with_raised_eyebrow:

2 Likes

This is probably an edge case but I have 2 “systems” - Raspberry Pi headless server with 8GB memory and a system on USB flash drive. I use the later on my work computer (16GB memory) when I want a personal computer on a business trip.
The issue in both cases is slow disk I/O and flash memory wear. Both of them run good enough without swap.

It already sounds like a sorcery to me… :mage:

no swap over here. no hibernation just suspend and generally i prefer to just fully power off my machines if i’m not using them for long periods anyway. otherwise i have plenty of memory on both my machines so i didnt setup a swap partition on either. i suppose i could setup a swap file but im not really sure that it’s at all necessary for me.

There are two principle reasons that the existence of swap space is desirable.

First, it expands the amount of memory a process may use. Virtual memory and swap space allows a large process to run even if the process is only partially resident. As “old” pages may be swapped out, the amount of memory addressed may easily exceed RAM as demand paging will ensure the pages are reloaded if necessary.

The casual reader1 may think that with a sufficient amount of memory, swap is unnecessary but this brings us to the second reason.

A significant number of the pages referenced by a process early in its life may only be used for initialisation and then never used again. It is better to swap out those pages and create more disk buffers than leave them resident and unused.

:thinking:

https://www.kernel.org/doc/gorman/html/understand/understand014.html

1 Like

I use swap partition. I have never understood that quoted text (part). If I have unused memory and very rarely anything is written to the swap. That’s why I changed the swappiness value to favor more memory. Maybe even the SSD disk will be saved from “unnecessary” writing. Swap is then a fallback.

1 Like

I never cared to worry about this. Log files get written more often than swap is used. Heck, your browser writes more useless data to its cache folder than swap writes. If you find that swap writing is enough to be valid concern where it might affect the lifetime of an SSD, get more ram. Unless you happen to be writing more than a few hundred GBs to swap regularly, the lifetime of your SSD is not going to notice the difference. And, if you are writing more than a few hundred GBs to swap regularly, you would have been driven mad by the performance drop and bought more ram long ago. :rofl:

If you dont have Swap and run into a high memory pressure situation your system will plain crash if it has nowhere to put things besides main memory. You should definitely have swap space.

My swap setup is 32GB Ram → 4GB Zram → 8GB Disk Swap

I dont remember what my swapiness is atm but you need it to swap fairly early so that it will swap in time before OOM.

An example. I want to say it was about 6 months ago there was a bug with Inkscape that had caused it to eat all my RAM. I didnt realize it at first and thought it was an unstable system for hardware reasons. The problem was that i only had a couple GB of swap and swapiness set very low so the system wasnt able to swap in time allowing me to stop the situation and recover the system before it crashed.

1 Like

I use Inkscape from time to time, and for doing very basic things, it would crash quite often. I wonder if this might have anything to do with it on my end, because I love Inkscape, but it is frustrating to use when it crashes before I can even save my work that I have to do it over again.:thinking:

How exactly do I check my SWAP? And if it’s low, how can I increase it ?

Edit: I have 16GB of Ram, and when I installed EndeavourOS, I installed “Swap to File” as my option I believe.

you can use

swapon -status

to check your current swap

all your swap altering needs should be met here https://wiki.archlinux.org/title/Swap

No no, I know that. I’m just one of “those” who think unused memory is wasted memory. :laughing:

Heck, your browser writes more useless data to its cache folder than swap writes.

Not mine. Cache in ram. (unused memory is wasted memory etc)

1 Like
[scott@endeavourOS ~]$ swapon -status
Filename				Type		Size		Used	Priority
/swapfile                               file		524284		0	-2
[scott@endeavourOS ~]$ 

Looks like outta 16GB of ram, I only have about 524MB of Swap to File. No clue if that is fine or if it should/needs to be higher.