What is swap?
The term “Swap System” refers to the space that is reserved on the hard drive by the operating system in the event that there is not enough RAM available. The swap system in Linux may either be a partitioned region on the hard drive that is dedicated to operating as a swap or a swap file. It is also possible for the swap system to consist of a mix of swap files and swap partitions.
When a computer’s main memory runs out of space, the kernel moves idle data pages from the main memory to a separate memory location known as the swap system. That makes some room available in the main RAM for use by other processes, which is always a good thing.
What is swappiness?
The pace at which the kernel of a Linux platform swaps pages into and out of active memory is referred to as the “swappiness” of the platform. Before writing pages to disk, the Linux platform does not wait for all of the available RAM to be used before beginning the process. Instead, it switches pages according on how long each of them has gone without being used. When the swappiness value is increased, the Linux kernel begins moving inactive memory pages to swap earlier than it does when the swappiness parameter is set to a lower value.
The swappiness parameter is a configurable value that may be adjusted anywhere on a scale from 0 to 100 and is what defines the swappiness property. The swappiness number on Linux servers is commonly set to 60 as the default. When there are heavy memory loads on a server or other variables linked to workloads and available resources, administrators will modify the “swappiness” of Linux. The “swappiness” value controls how often pages that are not being used are moved from main memory to swap space. If the value is set too low, pages that are now being used will stay in main memory even if the value is increased.
How to check swappiness value?
There are a couple of ways to check the swappiness value. You can use any one of them.
cat /proc/sys/vm/swappiness
or,
sysctl vm.swappiness
How to change swappiness value?
There are a couple of ways to change the swappiness value. We will show you one here.
sudo sysctl vm.swappiness=10