Optimize the Usage of Swap to Speed up Response
As we know, swap is the area on a hard disk as part of the Virtual Memory. Swap temporarily holds memory pages that are inactive. Swap space is used when your system decides that it needs physical memory(RAM) for active processes and there is insufficient unused physical memory available. If the system happens to need more memory resources or space, inactive pages in physical memory are then moved to the swap space therefore freeing up that physical memory for other uses.
Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory. So we can control the usage of swap area to speed up if there’s a large enough RAM.
There’s a swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. It ranges from 0 to 100, and when swappiness=0 it tells the kernel to avoid swapping processes out of physical memory for as long as possible, when swappiness=100 it tells the kernel to aggressively swap processes out of physical memory and move them to swap cache.
The default value of swappiness in Ubuntu is 60, and it recommends swappiness=10 for Ubuntu Desktop to improve overall performance.
First, check the value of swappiness. Open terminal and type this command:
Temporarily change swappiness’ value to 10 using following command, and it will be reverted in next restart.
sudo sysctl vm.swappiness=10
To permanently change this value, using:
gksudo gedit /etc/sysctl.conf
Search for vm.swappiness and change its value as desired. If vm.swappiness does not exist, add it to the end of the file like so:
Finally, save the file and reboot.
Tags: Optimizing, swap
Created: 4 years ago.
Last edited: 3 years ago.
Reviewed: 3 years ago.
Read 1842 times.
|2 years ago||
|I set vm.swappiness = 0 and have no regrets (with 4gb of RAM).|
|2 years ago||
|I don't think my swap file is working and am having a hard time figuring it out .... I recall at time of maya install the prompt said the swap file could be installed afterwards... Install should setup swap file automatically and the option should be to increase/decrease size|