0

One of my machine had around 120GB of 250GB of RAM consumed. Our swappiness level was 60 which means at around 100GB swapping would take place. I updated the swappiness setting by echo 1 > /proc/sys/vm/swappiness/. But I still see swap space being used.

Do I need to restart my machine/processes to take the effect?

4
  • Huh? How do you figure there should be 100 GB in swap? If you have only used 120/250 gb of ram you shouldn't have anything in swap.
    – psusi
    Commented Feb 12, 2018 at 20:49
  • that' what swappiness is for. it starts using swap if x% of RAM has been used @psusi
    – ffff
    Commented Feb 12, 2018 at 21:23
  • @user135284 where did you get that from? No, that's not how swappiness works. It's a very vague parameter that does not have a definite threshold of what gets swapped when. It's a very complex algorithm.
    – phemmer
    Commented Feb 12, 2018 at 21:53
  • Swappiness basically more or less determines the ratio of what gets swapped out, choosing between files and program data. It has absolutely nothing at all to do with how much memory is in use before swapping occurs
    – Fox
    Commented Feb 13, 2018 at 9:43

1 Answer 1

2

The value is dynamically applied, but there are a couple things you have to consider beyond just that value, namely:

  1. While Linux will swap data out opportunistically (that is, it will start pushing data out to swap before RAM is full), it only swaps data in on-demand (so it only pulls stuff in that's actually needed).

  2. Even after data gets swapped back in, a copy is still kept around in swap until the program terminates. This theoretically improves system performance when the virtual memory subsystem is thrashing (that is, constantly shuffling data in and out of swap because everything that's running won't fit entirely in memory) because it avoids the need to write the data out to swap again if it would get swapped out.

  3. Even if both 1 and 2 weren't the case, the system wouldn't visibly react to the change immediately, simply because it takes time to move data back in from swap.

Now, all that aside, there's something else to consider, namely that your machine was swapping well before memory exhaustion was a reasonable concern. That means one of three things in most cases:

  • You're using memory control groups to limit certain programs' memory usage, and some of them are hitting the limits in the control groups.
  • You have an insane amount of files cached that the system is for some reason not willing to evict from the cache to free up memory.
  • Something that's very active has a huge amount of memory allocated (possibly using huge pages) that it's not actually using.

In the first case, tweaking /proc/sys/vm/swappiness won't help, you need to look at the memory limits set up in the control groups and adjust those instead (or look at the applications you're running and figure out which one is using more RAM than you thought it needed).

In the second case, you will likely have better results increasing /proc/sys/vm/vfs_cache_pressure than you will lowering /proc/sys/vm/swappiness The vfs_cache_pressure sysctl controls how aggressively the system reclaims space from the page cache. It's expressed as a percentage, with the default being 100. I find that bumping it to 200 will usually convince the kernel that you really care more about other memory usage. Setting this too high though will negatively impact overalll performance (because it will waste time trying to shrink the cache when it can't be shrunk).

The third case is an issue with the program in question, and you can't really do much in most cases other than complain to the developers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .