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.

[Edit]: I don't want to know that what swappiness does, instead I want how much I need. According to a suggestion below I am listing some common tasks and apps I use. I am a programmer so apps like: VScode, Pycharm are neccesary for me and also some heavy tasks like virtualization (most of the times of android or windows) are in my usual work. And I also do video editing and graphics design, but, for those I use light programs (I think they are because they feels so fast) like: Shotcut, Inkscape.
So, I think this info would help in answering the question

Will appreciate an answer!:))

  • 3
    This is impossible to answer. Depending on actual application and usage patterns, the best value would be different. Just test a few settings yourself and see which works best. If you don't notice a big difference, it probably just doesn't matter as much. – Sunday Feb 20 at 11:21
  • 1
    Swappiness is there for emergency. Therefore avoid using swap if you can. Swap is 1000x slower than RAM – Bruce Malaudzi Feb 20 at 11:32
  • 1
    @jsbillings Ok let me clear, As I said i am not talking about swap size, but, about the swappiness .... – Unnat Feb 20 at 14:13
  • 1
    Just leave it at the default. I doubt you will notice. – jsbillings Feb 20 at 14:14
  • 3
    "I don't want to know that what swappiness does, instead I want how much I need.". It's a ratio/score not a quantity. If you want to change it the least you could do is know what it does first. – A.B Feb 20 at 16:57

Set it to 10 you probably won't even notice a difference during normal use cases maybe when your compiling but you can always use sysctl vm.swappiness=X and try out a setting for a little bit while your working most people are not going to notice a major difference in performance. If you concerned about SSD life check out one of the many posts and articles about it basically it "may" have been an issue at one point in time but that time has come and gone when your dealing with even a marginally good drive. The predicted life for a 128 GB MLC SSD of medium quality (3000 write cycles before failure) and average of 10GB write per day is around 35000 days so we are dealing with absurd times here. Don't over think the issue.

Jason C.

Just to bring it up in case your interested in this stuff look into trim for SSD's. Can start a whole new interesting discussion.

  • The thing is, that almost no consumer-grade SSDs are MLCs since five years now because they're mostly all 10x nm TLCs with worse lifespan, and now we have QLCs already starting to replace TLCs which are even worse. Theoritical cells lifespan is a thing, but reality is another one since write-based manufacturer warranties is far shorter than the "year-based" ones, some OEM rates them as only worth of 100TB writes. Writing 250GB of data a week is very easy with web browsing nowadays (e.g Youtube and JS infested webpages that are the norm helps a lot), even for a granny. – X.LINK Feb 22 at 2:46
  • Also, most field-tested articles we have are only about "3D" 40nm TLC drives (roughtly 2/3 lifespan of planar MLC 20nm) which also none of them are produced since around four years ago (the lower the nm, the less it will lasts). Those "field-tests" were also done with empty drives, which is far from reality. We have no field-tested data about the lifespan of "3D" 20 nm TLC cells, nor the 1xnm ones or even the QLC ones. That, and no field-tested data retention for any SSD celles type while the theoretical ones are pretty low. Anyway, swapping on SSD is a bad idea. – X.LINK Feb 22 at 2:49

You're starting things with a wrong assumption: Swappiness don't change with how much RAM you have, but with what software you'll use.

If you do virtual machine, you don't want a high swappiness. But if you do graphics design or coding, swappiness may be high.

But as a rule of thumbs: Set your swappiness to 0, so Linux will swap as late as it can. Doing this will keep your system responsive, and prolong your SDD lifespan if you have one (that's why you mostly saw answers to set swappiness to 10 and nothing else).

As others say, swap will only be an emergency "RAM" for most people.

Also, considering that you only have 4 GBs of RAM, you'll pretty quickly reach that limit in no time just with web browsing alone, swap won't even help here. Even 8GBs of RAM won't be enough for what you intend to do.

Then, depending on what your CPU is, you may still have a hard time even with more RAM. To make it short: there is a relation between your CPU and how much RAM you should have, but also what you intend to do (which you told us already).

Some tips about swap:

  • Swap partitions are useless for most people, do use swap files instead.
  • Swap should be at the very least the physical size of your RAM (not how much the OS detects them) PLUS the amount your dedicated GPU(s) physically has, if you have one. That's even truer if you do make use of hibernation.

Also: Just because a program looks "fast", doesn't mean it's lightweight since caching is a thing that is overly used since less than a decade. In short: You'll trade less CPU usage for far more RAM usage.

  • 1
    Swappiness of zero is just a waste of perfectly good RAM. – jsbillings Feb 22 at 1:10
  • There's no reason to swap until it is need, which means when there's not enough RAM. Preemtively swapping means making the system less responsive while nothing else fills the RAM, while sometimes thrashing the I/O and reduced SSD lifespan for nothing. – X.LINK Feb 22 at 1:25
  • Pay closer attention. I asked if they intend to suspend to disk, OP said No. Also, I think you might be confused by what swap is used for. It’s not just “emergency memory”. A normal OS uses swap for memory pages that haven’t been touched in a while, and lets the kernel use unused RAM for buffers and cache. With no swap, or swappiness=0, those pages are essentially wasted on storing objects that no one cares about. – jsbillings Feb 22 at 1:28
  • Also, last I checked, Video RAM wasn’t suspended to disk. Anything important in vram needs to be put into RAM by the driver enforce hibernation or regenerated on restore. – jsbillings Feb 22 at 1:31
  • Also, since you do bring up hibernation, swap files are a major pain to beginner users (adding kernel parameters?), and can break restore completely if you use btrfs. – jsbillings Feb 22 at 1:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.