Advertising

Welcome to SparkyLinux forums
Zapraszamy również na polsko-języczne Forum https://forum.linuxiarze.pl

[ Solved ] Swappiness - Improve your system's performance.

Started by way12go, November 30, 2014, 03:01:07 PM

Previous topic - Next topic

way12go


Source : http://askubuntu.com/questions/103915/how-do-i-configure-swappiness

Swappiness - Improve your system's performance.

Question : I have heard that changing the swappiness of my system will improve performance. How does this work and what is a good setting for swappiness?

Answer : Let us imagine for a moment that on our Linux system we have one large pool of memory and this pool is divided into two parts. One part of the memory pool is our machine's RAM. RAM is very fast and in high demand, but there usually isn't a lot of it. The other part of the memory pool is called swap space. Swap space resides on the hard disk which is slow and typically in low demand.

In an ideal situation we would have lots of RAM and everything we need, applications and files, would stay in RAM where it would be accessed amazingly quickly. However, since RAM is relatively small and the hard disk relatively large, not everything we need will fit into RAM. This means the Linux kernel needs to make some tough choices. When the operating system starts to run out of room in RAM should the Linux kernel keep copies of files in memory and send the applications we are using into the slower swap space? Or should the kernel keep our programs in memory and drop files that it has copied into memory for quick access? It's a puzzle. Some applications will benefit from having files stored in RAM, but all processes (especially desktop programs we want to have respond quickly) will benefit from being kept in RAM too. Really, we want to rely on accessing the disk (and swap space) as little as possible.

What the swappiness parameter does is let us tell the Linux kernel our preference. Swappiness is expressed as a number from 0 to 100, inclusive. A high swappiness value (near 100) means that unused process memory should get removed from RAM and sent to swap space as much as possible. A low swappiness value (near 0) means the kernel will attempt to keep programs in memory and, if it needs RAM, cached files will be dropped from memory to free up space. Typically, on a desktop machine, we want a relatively low swappiness value. This means applications such as Firefox and our music player stay in memory and should remain responsive. To see what swappiness value our kernel is currently using we can run

cat /proc/sys/vm/swappiness

Most modern distributions set the default swappiness value to the mid-range, typically 60. Often people running Linux on desktop/laptop machines like to set swappiness to a lower value. So how do we adjust the swappiness of the Linux kernel? First let's look at changing the level of swappiness on a running machine. To set our machine's swappiness level to 10, where applications are less likely to get transferred out of RAM, we can run the following at a command prompt as the root user:

leafpad /etc/sysctl.conf

vm.swappiness=10

To return the swappiness value to 60 we can run

vm.swappiness=60

Should we wish to make our new swappiness level permanent we can add a line to the text file /etc/sysctl.conf. This line will indicate the new swappiness value for the next time the system is booted. In this example I set swappiness to 10:

vm.swappiness=10

Most people will probably get along fine with the defaults, especially on a modern computer with lots of RAM. Swappiness is less of an issue if RAM isn't getting filled up, so if you have 8GB of RAM and only need 2GB for applications, swap space may not be used at all. On the other hand, if you have 1GB of RAM and you find your system is using swap space, then lowering the swappiness value is probably a good idea. If you are not sure if your operating system is making use of swap space, run the free command

free

The free command will show you, on the bottom line, the amount of total swap space available, how much is being used and how much is currently free (unused). If the value in the "used" column is zero then swap space isn't being used and swappiness won't matter much. A value above zero means swap space is used and your system may benefit from being tuned.

Source:

https://lists.debian.org/debian-user/2012/07/msg02001.html


On 7/27/2012 1:23 AM, John Magolske wrote:
> Thanks you everyone for the helpful replies!
>
> * John Magolske <listmail@b79.net> [120723 23:22]:
>> This command will set swappiness (to 0 in this case):
>>
>>   # sysctl vm.swappiness=0
>>
>> To have that setting persist across reboots, it is suggested to add
>> a line like so to /etc/sysfs.conf :
>>
>>   vm.swappiness=0
>>
>> Which I did...but that value is not set after reboot:
>
> Per your suggestions, I set vm.swappiness=0 in /etc/sysctl.conf and
> that value is indeed reflected after reboot (just now got around to
> re-booting this machine).
>
> John


I gave you the answer 3 days ago, only 49 minutes after your post...

On 7/24/2012 2:04 AM, Stan Hoeppner wrote:> On 7/24/2012 1:15 AM, John
Magolske wrote:
>> Hello,
>>
>> This command will set swappiness (to 0 in this case):
>>
>>   # sysctl vm.swappiness=0
>>
>> To have that setting persist across reboots, it is suggested to add
>> a line like so to /etc/sysfs.conf :
>
> Close, it's:
>
>  /etc/sysctl.conf

--
Stan


---- Copied from internet sources by Sagar Gorijala.
Success gives birth to success? Failure gives birth to failure? - Sagar Gorijala.

View the most recent posts on the forum