An article explaining how to tune kernel parameters in the Linux system using command or using a configuration file.
In this article we will be discussing how to set or tune the kernel parameter in any Linux system. There are many ways you can do it like setting them in their configuration files or using a system control command
sysctl command is used to configure kernel parameters at runtime. Your current kernel parameters values can be viewed with
# sysctl -a abi.vsyscall32 = 1 crypto.fips_enabled = 0 debug.exception-trace = 1 debug.kprobes-optimization = 1 dev.hpet.max-user-freq = 64 dev.mac_hid.mouse_button2_keycode = 97 dev.mac_hid.mouse_button3_keycode = 100 dev.mac_hid.mouse_button_emulation = 0 dev.parport.default.spintime = 500 ----- output clipped -----
In the above output you can see parameters on left and their current value on the right. Parameters are sorted with alphabetical order and both columns in output are delimited with
= sign so that you can sort this output easily using this delimiter.
There are a few parameters you can even view using the proc file system. You can cat their respective files and view values.
# cat /proc/sys/kernel/shmmni 2048
In above example we can see
shmmni value is set to 2048.
How to tune kernel parameter
To change the kernel parameter you can define it under configuration file
/etc/sysctl.conf and it will be applied at the next reboot. You need to define parameter=value format in this file (ex. kernel.shmmni=4096).
Each new line represents a new parameter and value pair. Values in this file will be loaded at the next reboot. If you want to load this file immediately then you can can do it by using
sysctl -p command. It will load
/etc/sysctl.conf file in kernel. You can even define values with
-w switch explained below.
To change the kernel parameter using
sysctl, you should use a write switch
-w along with parameter and value. In the below example we are changing
kernel.shmmni value to 2048.
# sysctl kernel.shmmni kernel.shmmni = 4096 # sysctl -w kernel.shmmni=2048 kernel.shmmni = 2048
You can observe previously
kernel.shmmni value was 4096, using
-w we changed it to 2048. This change is immediate and does not need a reboot to comes in effect.