1

We want to disable swap on all our RHEL servers (Hadoop servers). We have 2 options:

  1. Set swappiness to 0, and swapoff -a & swapon -a
  2. swapoff -a , and disable swap from fstab

From my understanding, both options disable swap completely

Option 2 for sure, since we swapoff -a and disable the swap from fstab.

But does option 1 give the same results as option 2?

2 Answers 2

7
  1. What happened when you tested it?

  2. Did you read the documentation?

    A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.

    i.e., a value of zero does not disable swap, it just defers it.

2
  • so in spite we set swappiness to 0 , in some cases swap used on linux can consume 1-(max swap) GIGA memory ? Commented Feb 22, 2022 at 23:04
  • Yes, if you enable swap with swapon, the kernel is allowed to use it; the various sysctl settings available only affect how it uses it, not whether it can. Commented Feb 23, 2022 at 9:11
6

from my understanding both options are disable swap completely

Incorrect. Setting swappiness to 0 does not disable swap.

"Swap" is basically just virtual RAM on your hard disk. It is used when your RAM is out of memory. Turning swap off means if a program needs more RAM, it crashes. Don't do that. Have a swap file. Since modern default Ubuntu installations (ex: Ubuntu 22.04) do not provide a swap file by default, however, you have to manually create one after installing Ubuntu. Here is my answer on how to quickly and easily make one.

Setting swappiness to 0 is fine. It does not disable swap space. I know this. I've tested it extensively and still see my swap grow. I've also read the description for swappiness in the Linux source code. Rather, it defers using swap to as late as possible until it can't fine a way to free RAM and decides to move some memory in RAM to swap space anyway.

See also my answer about swappiness and how to configure it. I've included the Linux kernel source code quotes here describing it too: Ask Ubuntu: How do I configure swappiness?


End of answer and beginning of anecdote and personal experience with swappiness.

I have found that setting swappiness to 0 significantly improves the performance of my system which has 32 GB RAM, a 64 GB swap file on a high-speed m.2 SSD, and which is continually running out of RAM.

With swappiness set to the default of 60, I'd regularly get 1 to 2 minute lockup periods while kswapd0 is running (as shown by top) to try to swap memory for some memory hog application like Chrome, Slack, Eclipse, or Google Meet (within Chrome). I'd start to get these lockups at 80% full RAM. The computer would be completely unusable during this time--unable even for me to type into a terminal or click on a menu.

Setting swappiness to 0 significantly helped!. I started not getting really high CPU usage until 90% RAM full, swap space would still get used plenty--but more efficiently, and when my RAM did get almost full my computer would become very sluggish, but still barely usable rather than completely unusable!

See some of my symptoms here, which I originally thought were due to a bug in Google Meet, but now think were due to memory swap making my computer slow: https://github.com/ElectricRCAircraftGuy/bug_reports/issues/3#issue-1177137900

6
  • This answer is unnecessarily chatty, talking about issues that the user in the question does not have. The Github issue thread that you link to does not mention anything to do with this question. Commented Dec 13, 2022 at 7:15
  • @Kusalananda, I put a bar to delineate the end of my answer and the start of my anecdote. Commented Dec 13, 2022 at 7:21
  • 1
    "Don't do that. Have a swap file." This used to be standard practice, and should still be a tool in any good sysadmin's bag of tricks, but in most cases, when a server host goes into swap performance will take a nose-dive (leading to a backup of demand, and greater load.....death spiral). Its not really an effective way to manage workload in the long term. Nowadays I still usually configure swap on workstations, but rarely on server hosts. Commented Dec 26, 2023 at 15:39
  • @symcbean, that's interesting that the decreased speed due to a swap file could crash a server. I just bought a Samsung 990 PRO M.2 SSD with 7450 MB/s read and 6900 MB/s write speeds. With such a fast SSD, I would think swap would be very effective, even on a server, no? I've used up to 32 GB of swap (I made the swap file 64 GB) on an SSD half that fast for compiling huge C++ projects, and it was fast enough to work well, for instance. My RAM was only 32 GB on that machine, but the required RAM to compile was ~65 GB, so the swap was heavily used. Commented Dec 26, 2023 at 16:17
  • 1
    1) server is using more memory than you planned for because you are not controlling the amount of traffic hitting it. i.e. there is more work than it can handle. 2) As load increases beyond #cpus kernel will start pre-empting tasks which decreases throughput, 3) Your SSD is still slower than (main) RAM and RAM is slower than CPU cache. 4) Compiling code is not something usually run on a server Commented Dec 26, 2023 at 17:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.