Swappiness - Improve your system's performance.

Post your How to's here


Swappiness - Improve your system's performance.

Postby tanmay.01 » Mon Aug 05, 2013 12:51 pm

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:

Code: Select all
nano /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 : http://askubuntu.com/questions/103915/h ... swappiness
HP ENVY 15
•3rd generation Intel(R) Core(TheeMahn) i5-3210M Processor (2.5 GHz with Turbo Boost up to 3.1 GHz)
• 1GB Radeon(TheeMahn) HD 7750M GDDR5 Graphics [HDMI]
• 6GB 1600DDR3 System Memory (2 Dimm)
• 750GB 7200 rpm Hard Drive
• Intel 2x2 802.11a/b/g/n WLAN + Bluetooth(R)
• Full-size Radiance backlit keyboard.

Image
User avatar
tanmay.01
Moderator
 
Posts: 253
Joined: Wed Dec 07, 2011 1:03 pm
Location: India
Age: 27
Operating System: Other Linux



Re: Swappiness - Improve your system's performance.

Postby ryanvade » Mon Aug 05, 2013 4:21 pm

Very nice tutorial.

Also, if anyone finds they need some swap space but do not want to mess with their partitions they can make a swap file:
http://www.cyberciti.biz/faq/linux-add- ... ile-howto/
Image

Laptop: HP dv6t-7000 CTO Desktop: Compaq Presario SR21632wm
i5 2450m Pentium D 960 @ 4 GHz
6 GB ram 2 GB ram
Intel HD 3000 Graphics / Nvidia GT 630M Nvidia GT 520 @ 820 MHz
Diamond II-B 3.10-rc4/Windows 7 Home Premium KDE | Windows 7 Starter/Arch Linux

Paid supporter of the Linux Foundation
User avatar
ryanvade
Moderator
 
Posts: 499
Joined: Sat Apr 28, 2012 10:54 am
Operating System: Other Linux


Return to How To's (Do not post questions please)

Who is online

Users browsing this forum: No registered users and 0 guests

cron