Cache and swap space are powerful tools when doing Linux performance tuning. Many think swap space isn’t useful and therefore configure a minimal amount. But if you want optimal performance on your servers, you need a better approach to managing cache and swap space.
On any operating system, swap is used as additional memory. If a system runs out of physical RAM, it can start allocating swap, which is emulated memory on hard disk. This generally is slower, but it’s always good to have some swap. If your server runs out of memory — that is, RAM or swap — it can crash.
There is a close relation between the amount of swap and the amount of cache a server has available. The starting point of an optimization of the amount of swap on your server is that at all times there should be at least 20% of the total RAM as cache; 30% is even better. To accomplish this goal, you need to make sure the ability of the server to move memory pages to swap is big enough. If you are below the minimal amount of cache you want to have, increase the likelihood of your server to swap. To identify the amount of cache currently in use on your server, use the free -m command. Your server must be running for at least a few hours to get a good impression of the amount of RAM that is typically available for caching.
Use: # free -m —-à to determine the amount of cache
| total | used | free | Shared | buffers | cached | |
| Mem: |
993 |
721 |
271 |
0 |
25 |
272 |
| -/+ buffers/cache: |
423 |
569 |
|
|
|
|
| Swap: |
1983 |
0 |
1983 |
|
|
So if the server falls below 25% of cache, you can use the swappiness parameter to increase it.
By default, the Linux kernel swaps quite aggressively, even if it doesn’t really show on most servers due to the amount of RAM, as the amount of swap in use is 0 or close to it. To influence the swap behavior of a server, an administrator can modify the swappiness parameter. This parameter sets the willingness of the kernel to move memory pages to swap.
The swappiness parameter can have a value between 0 and 100, where 0 means “do not swap at all” and 100 means “swap as soon as you can.” By default, the swappiness of the kernel is set to 60. To change this parameter, change the content of the file /proc/sys/vm/swappiness, using the following command:
echo 80 > /proc/sys/vm/swappiness
To make the setting persistent, you should also include the following line in /etc/sysctl.conf:
vm.swappiness = 60
Tuning a Linux server’s swap settings will result in better I/O handling and therefore much better Linux system performance. J !
your post is an excellent example of why i keep coming back to read your excellent quality content that is forever updated. nice post and thanks for sharing. regards. lista de emails lista de emails lista de emails lista de emails lista de emails