LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to change the Swappiness of your Linux system (https://www.linuxquestions.org/questions/linux-general-1/how-to-change-the-swappiness-of-your-linux-system-4175546212/)

onebuck 06-23-2015 11:25 AM

How to change the Swappiness of your Linux system
 
Hi,

How to change the Swappiness of your Linux system
Quote:

Most of Linux users that have installed a distribution before, must have noticed the existence of the “swap space” during the partitioning phase (it is usually found as /sda5). This is a dedicated space in your hard drive that is usually set to at least twice the capacity of your RAM, and along with it constitutes the total virtual memory of your system. From time to time, the Linux kernel utilizes this swap space by copying chunks from your RAM to the swap, allowing active processes that require more memory than it is physically available to run.

Swappiness is the kernel parameter that defines how much (and how often) your Linux kernel will copy RAM contents to swap. This parameter's default value is “60” and it can take anything from “0” to “100”. The higher the value of the swappiness parameter, the more aggressively your kernel will swap.

johnsfine 06-23-2015 12:00 PM

The article you linked promotes terrible misinformation on the meaning and effect of swappiness.

Don't tweak what you don't understand.

Quote:

The parameter value set to 60 means that your kernel will swap when RAM reaches 40 capacity.
That part of the article is total garbage. The rest of the article is based on that fundamental misunderstanding, so the whole article will just misinform.

A much more insightful simplification of the meaning of swappiness, would be to say that it represents the relative cost of spilling and reloading anonymous memory vs. non anonymous memory, where a swappiness of 100 implies equal cost and a swappiness of 0 implies non anonymous memory spills and reloads at zero cost.

Using a single traditional hard drive, anonymous memory spills and reloads (through swap space) for on average twice the cost of non anonymous memory reloading from its file backing. A non symmetric performance media (flash) would tend to increase that two to one difference (so optimum swappiness would be lower than the default, but not as low as zero). Multiple and/or mixed media may have a complex impact, generally not worth micro managing. If most rereads are from flash (rather than traditional hard drive) lower swappiness for better performance.

onebuck 06-23-2015 05:10 PM

Member response
 
Hi,

As with most things there are always others who sense of how things should be setup;
http://unix.stackexchange.com/questi...-60-by-default
Quote:

The default value has most likely been chosen as an approximate middleground between these two extremes. As with any performance parameter, adjusting vm.swappiness should be based on benchmark data comparable to real workloads, not just a gut feeling.
In the original post I found that argument interesting. I setup my Laptop SSD install
Code:

~# cat /proc/sys/vm/swappiness
1

I have found better performance utilizing that setting for my system. Each too their own. I feel that since pages that are anonymous have no filesystem backing then the lose may cause issue with these pages which should remain in memory as long as needed unless swap space is available.

Just my thoughts.

syg00 06-24-2015 07:54 AM

swappiness is up there with loadavg - might have seemed like a good idea at the time. Pity no-one understands them.
I wonder if Linus regrets ever allowing either to be included.

johnsfine 06-24-2015 08:37 AM

Quote:

Originally Posted by syg00 (Post 5382246)
swappiness is up there with loadavg - might have seemed like a good idea at the time. Pity no-one understands them.
I wonder if Linus regrets ever allowing either to be included.

Swappiness can be an important and useful feature if you understand it. I would hope some distribution install programs understand it, detect flash devices and reduce swappiness (but I don't know whether any do).

I think the name of the parameter greatly increases the misunderstanding by those who think they know what it means. I don't know a good name. But if someone in control had regrets about the feature, it shouldn't be about having the feature. It should be about giving the feature a name that people think they understand. With an obscure name that no one understands, the feature would be just as useful and much less harmful.

Long ago, very expensive servers might have expensive high-speed, low-capacity hard drives combined with other lower-speed higher-capacity drives, all with inadequate ram. Then placing swap on the faster drive and tuning swappiness above default would be a key performance tweak. With current hardware, I can't think of any reason for above default swappiness. But most systems that do their program loading from flash should have below default swappiness, and those which also have data files and/or swap in flash, even more so.


All times are GMT -5. The time now is 04:45 PM.