1

I am a bit confused because everyone says to reduce the swappiness to about 10; but if I have only 4GB RAM than how much swappiness would be the best? and also If I had 8 and 16GB ram?

and also I am not talking about swap partition/file size I am talking about swappiness

Will appreciate an answer!:))

muru
  • 197,895
  • 55
  • 485
  • 740
Unnat
  • 165
  • What's wrong with the default setting? What's the issue you are encountering, and what leads you to believe that tinkering with swappiness is the answer to that issue? – user535733 Feb 20 '21 at 13:59
  • Nothing is wrong I just want to know that how much swappiness I need with 4GB of ram – Unnat Feb 20 '21 at 14:02
  • 2
    Just leave at default (60). Only in very special situations you will have to change it. – Soren A Feb 20 '21 at 14:05
  • @SorenA Does the amount of ram matter in amount of swappiness? please explain your answer – Unnat Feb 20 '21 at 14:12
  • Why not use the default value and if it doesn't work out for you, then change it? I wouldn't worry about what "everyone" is saying. – Ray Feb 20 '21 at 14:16
  • The original advice about reducing swappiness from the default 60 to 10 was in the context of drives that used to wear out quickly, such as flash drives, or early SSDs. It had nothing to do with RAM. Modern day SSDs can withstand more write cycles than those early (and expensive) versions. So, there is no need to change the default. – user68186 Feb 20 '21 at 14:16
  • but I use an HDD (I know I am too outdated:) ) – Unnat Feb 20 '21 at 14:22
  • You can read a little bit about swappiness here. TL;DR: swappiness isn't just about swap, and it isn't a percentage. If you're using a desktop system with less than 16GB RAM, leave it be –  Feb 20 '21 at 14:23
  • In case you feel that swap usage is too much and your computer is frequently slowing down, you can try reducing swappiness, and use the value which works best for you (there is no "best", it is an opinion based question). I myself completely disabled swap on a computer with an old hard disk and am quite satisfied because now it does not freeze anymore. The kernel intelligently kills any process that takes too much memory. The system never becomes completely frozen, unlike when swap is there. – Archisman Panigrahi Feb 20 '21 at 15:03
  • @Unnat The amount of RAM it self doesn't by it self impact the value swappiness. Enough RAM for your workload is always the best solution, with SWAP as a "spillover" area to park seldom used memory pages (data or program-code). Swappiness basically tells when to start paging out pages not used recently. Normally default is fine, but in a few cases you will see excessive paging out and in that impact the systems performance, even though you seems to have enough RAM. In such cases performance might benefit by changing Swappiness or disabling SWAP totally ... or buy more RAM. – Soren A Feb 20 '21 at 17:17
  • @ArchismanPanigrahi All systems need swap. You may have had too small a swap, or a defective "old hard disk", or a corrupt swap partition. – heynnema Feb 21 '21 at 15:49
  • @SorenA All systems need swap. In cases of "excessive paging" you do the wrong thing to "disabling SWAP totally". – heynnema Feb 21 '21 at 15:51
  • @heynnema I have been regularly using this computer since October 2020. I disabled swap and removed the swap partition, and never faced any issue. The computer never freezes even when the it uses 2.8 gb out of 3 gb of the memory. Yes, the hard disk is quite old, which may have caused the freezing when swap was being used. (I don't want to argue about whether it is a good or bad idea to disable swap, or how much swap one needs. I just wanted to share my personal experience that the computer works very well even without swap, and now it does not freeze anymore when memory usage becomes high). – Archisman Panigrahi Feb 21 '21 at 16:27
  • @ArchismanPanigrahi No argument here. If you only have 3G RAM, you need swap. Try and load up an additional application or two, and watch what happens to your system :-) – heynnema Feb 21 '21 at 16:31
  • @heynnema I simply don't open too many memory consuming applications (e.g. Chromium and V.S. code) simultaneously, and I can tell that now the system is snappier without swap :-) – Archisman Panigrahi Feb 21 '21 at 16:34

1 Answers1

2

I wish that I could find the article(s) that blindly recommended setting vm.swappiness=10 to improve performance. Too many users blindly change this value without really understanding what they're doing, and system performance usually suffers.

In short, vm.swappiness values approaching zero favor RAM usage, and values approaching one hundred favor swapping.

With 4G or 8G RAM, you should leave vm.swappiness=60 (the default) alone, or maybe change vm.swappiness to around 80 to encourage more swapping.

With 16G or more RAM, or in a server environment, you could set vm.swappiness=10 to favor RAM, reduce system latency, and discourage swapping.

heynnema
  • 70,711