GOAL
- Why Swap is being Consumed when Physical Memory is Available in DBaaS System or in any Linux System.
free -m
total used free shared buffers cached
Mem: 120616 115746 4869 167 390 44187
-/+ buffers/cache: 71169 49447
Swap: 2047 1614 433
SOLUTION
- It's normal for Linux systems to start swapping before the RAM is filled up. This is done to improve performance and responsiveness:
Performance is increased because sometimes RAM is better used for disk cache than to store program memory. So it's better to swap out a program that's been inactive for a while, and instead keep often-used files in cache.
Responsiveness is improved by swapping pages out when the system is idle, rather than when the memory is full and some program is running and requesting more RAM to complete a task.
- In Linux, Swappiness is the rate at which kernel moves pages into and out of active memory. Swappiness can have a value of between 0 and 100
swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible. For Kernel version 3.5 and newer it disables swapiness.
swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache
- You may check the the swappiness value using below (ideally on latest Linux system it's set to 60)
[opc@rrr ~]$ cat /proc/sys/vm/swappiness
60
[opc@rrr ~]$