How do I configure swappiness?

Discussions related with hosting control panels used, which include cPanel, Plesk, Directadmin etc..

Moderator: Staff

Post Reply
Ashlin
Posts: 0
Joined: Fri Sep 16, 2016 10:10 am

How do I configure swappiness?

Post by Ashlin »

I need a easy way to configure swappiness.Please help


Aaron
Posts: 17
Joined: Mon Apr 11, 2016 8:59 am

Re: How do I configure swappiness?

Post by Aaron »

Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. The default value is 60. You can simply set the swappiness value running as root user.

To find the current swappiness settings:

Code: Select all

cat /proc/sys/vm/swappiness
  • Result: 60
To temporarily set the swappiness in Linux, write the desired value
(e.g. 30) to /proc/sys/vm/swappiness using the following command.



# Set the swappiness value as root

Code: Select all

echo 30 > /proc/sys/vm/swappiness
# Alternatively, run this

Code: Select all

sysctl -w vm.swappiness=30
# Verify the change

Code: Select all

cat /proc/sys/vm/swappiness
  • Result: 30
# Alternatively, verify the change

Code: Select all

sysctl vm.swappiness
  • Result: vm.swappiness = 30

To make changes permanent, you can add the setting to the /etc/sysctl.conf file:

Code: Select all

sudo nano /etc/sysctl.conf
Add the below line.
# Search for the vm.swappiness setting. Uncomment and change it as necessary.

Code: Select all

vm.swappiness=10

You can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect.


Aaron N
Linux Support Engineer.
Nixtree Solutions LLP
Managed Full Server Backups
https://www.nixtree.com/managed-backups.php

Follow us on : https://twitter.com/nixtree
If you are looking for assistance in server management, please get in touch with our support.
Post Reply