Tuesday, August 8, 2023

Tuning kernel parameters in linux

For most people, the kernel provided with our favorite linux distro is good enough for daily use. But for some other people, they need more performance out of their linux machine, so they need to tune some kernel parameters, to suit whatever need they have in their hands.


We can add the parameter to the kernel runtime (would not survive reboot) by using sysctl command
$ sudo sysctl <tunable class>.<tunable>
To make the change permanent, we can add the kernel parameter to /etc/sysctl.conf or /etc/sysctl.d/filename.conf (best practice) by using any text editor

We can also add the parameter by using 
$ sudo sysctl -w <tunable class>.<tunable> >> /etc/sysctl.conf
$ sudo sysctl -w <tunable class>.<tunable> >> /etc/sysctl.d/filename.conf
Load kernel parameters from /etc/sysctl.conf or /etc/sysctl.d/filename.conf 
$ sudo sysctl -p 
$ sudo sysctl -p /etc/sysctl.d/filename.conf
We can also load from all system configuration files. System configuration files are /etc/sysctl.d/*.conf, /run/sysctl.d/*.conf, /usr/local/lib/sysctl.d/*.conf, /usr/lib/sysctl.d/*.conf, /lib/sysctl.d/*.conf and /etc/sysctl.conf
$ sudo sysctl --system
View all the kernel parameters currently available by using
$ sudo sysctl -a
We can also set pattern for the displayed results. For example, 
$ sudo sysctl -a --pattern 'kernel'


What are the available tunable classes? According to Red Hat, these are the ones available in RHEL.

- abi: execution domain and personalities 

- crypto: cryptographic interfaces

- debug: kernel debugging interfaces

- dev: device specific information

- fs: global and specific filesystem tunables

- kernel: global kernel tunables

- net: network tunables

- sunrpc: sun remote procedure calls (NFS)

- user: user namespace limits

- vm: tuning and management of memory, buffer and cache


How to get information about the tunables and its usage? Refer to https://www.kernel.org/doc/Documentation/

No comments: