TransWikia.com

Downsides to disabling/removing swap?

Ask Ubuntu Asked by GChuf on November 21, 2021

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 vm.swappiness in /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?

3 Answers

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.

References:

https://superuser.com/a/1203014

https://help.ubuntu.com/community/SwapFaq#Why_do_I_need_swap.3F

Edit: Post Ubuntu-18.04, Ubuntu automatically creates a swap file in root file system if a separate swap partition is not made.

Ref: https://askubuntu.com/a/1234843/1107236

Answered by turbulence on November 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP