I understand swap is like an extention to RAM and is mostly used when the amount of free memory is below a certain threshold – which can be set with
/proc/sys/. Swap can also be used for hibernation, like virtual memory on Windows.
I’ve come across this answer which tells a bit more about swap and how it can be used to reduce memory usage, or like disk cache:
Swap is useful because applications that aren’t being used can be
stored on disk until they are used. Then they can be "paged in" and
run normally again. While it is not in memory, though, the OS can use
that memory for something else, like disk cache.
But apart from these, what is swap used for? If I never (theoretically) run out of available memory, and don’t use hibernation, would there be any downsides to having no swap? Would there be any performance improvements? Longer disk lifespan?
It is always useful to have some swap just in case you need some extra free memory when memory pressure gets high. Also the kernel will swap out pages that have not been used for a while and this frees up more physical memory for caching file data and this should lead to better I/O performance. Finally, the underlying virtual memory subsystem behaves differently when swap is enabled and this can affect the way the kernel selects processes that need OOM'ing when memory is really tight.
Answered by Colin Ian King on November 21, 2021
If you have enough RAM and never use hibernation, swap is completely useless.
In theory if some RAM pages are sent to swap, there is more RAM available for cache and the most active applications, that can slightly improve performance.
But the process of swapping itself is slow.
If you have enough RAM, or even just enough, it is more useful to install
zram-config to improve performace a bit. It will create a compressed swap in RAM.
Answered by Pilot6 on November 21, 2021
When battery in your laptop goes below a threshold, it is hibernated and shutdown. In the process of hibernation, the contents of RAM is dumped into the SWAP partition.
Edit: Post Ubuntu-18.04, Ubuntu automatically creates a swap file in root file system if a separate swap partition is not made.
Answered by turbulence on November 21, 2021
1 Asked on January 26, 2021 by user1725216
0 Asked on January 26, 2021
4 Asked on January 25, 2021 by rahul-raj-rai
2 Asked on January 25, 2021 by jorrit
1 Asked on January 24, 2021 by marievi
0 Asked on January 24, 2021 by arsh
0 Asked on January 24, 2021 by paul-wessex
1 Asked on January 24, 2021 by donttakemeseriously
0 Asked on January 23, 2021 by k-madhura-nadh-12a
4 Asked on January 23, 2021 by akaichi
0 Asked on January 23, 2021 by brad
0 Asked on January 23, 2021
0 Asked on January 23, 2021 by asocia
3 Asked on January 22, 2021 by thomas-ding
0 Asked on January 22, 2021 by salem-f
2 Asked on January 22, 2021 by gevra
0 Asked on January 22, 2021 by richard-boekamp
Get help from others!