Performance Tuning of Linux servers via Kernel tunable parameters

We can tune Linux servers performance by updating Kernel Parameters, This can be achieved via

1) At runtime updating “/proc/sys” – it is not persistent across server reboot
2) via sysctl by command line – it is not persistent across server reboot
3) via sysctl by configuration file “/etc/sysctl.d” – It is persistent across server reboot

“/proc/sys” directory contains data which directly refers that how the Kernel handles Operating system activities
it is owned by ‘root’ user. By changing these values, server’s performance reflected in either constructive(Positive performance) or destructive (Negative performance).

For example, by tuning TCP socket buffer size:
if it is high, we will get high throughput(more packets will be processed) and High latency(more time consuming)

To list out available tunable, please execute the below command,

# sysctl -a

Now we will apply the tuning parameter “vm.swappiness” by using above three methods,

Swappiness can be set to values between 0 and 100. This value is directly proportionate to usage of swap memory.
Low value means the kernel will try to avoid swapping as much as possible.
High value means kernel will aggressively try to use swap space.

To know the current value of ‘swappiness’

[root@centos7 ~]# cat /proc/sys/vm/swappiness
[root@centos7 ~]#

[root@centos7 ~]# sysctl -a | grep -i swappiness
vm.swappiness = 30
[root@centos7 ~]#

Updating ‘swappiness’ value to 20 from 30 as below,

1) Updating via “/proc/sys”. echo 20 > /proc/sys/vm/swappiness

[root@centos7 ~]# echo 20 > /proc/sys/vm/swappiness
[root@centos7 ~]#

[root@centos7 ~]# sysctl -a | grep -i swappiness
vm.swappiness = 20
[root@centos7 ~]#

2) sysctl -w vm.swappiness=20

[root@centos7 ~]# sysctl -w vm.swappiness=20
vm.swappiness = 20
[root@centos7 ~]#

3) echo “vm.swappiness=20” >> /etc/sysctl.d/swap.conf

Under “/etc/sysctl.d/” directory, we are creating a ‘swap.conf’ file to hold the swappiness value.

[root@centos7 ~]# echo "vm.swappiness=20" >> /etc/sysctl.d/swap.conf
[root@centos7 ~]# sysctl -a | grep -i swappiness
vm.swappiness = 20
[root@centos7 ~]#

To apply the above changes without server reboot, please execute below command.

[root@centos7 ~]# sysctl -p /etc/sysctl.d/swap.conf
vm.swappiness = 20
[root@centos7 ~]#


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: