How to perform temporary and permanent kernel parameter tuning in linux ?

In this post, we will look how to tune/change Linux kernel parameters temporarily or permanent.

To change/verify the parameters we will use sysctl command.

From its man page, we can have its details as follows.

sysctl – command to configure kernel parameters at runtime
-a, -A Display all values currently available.

For Temporary Change

-w Use this option when you want to change a sysctl setting.

For permanent Change

1. Change/Define parameter value /etc/sysctl.conf.
2. Run sysctl -p to update the file changes.

-p Load in sysctl settings from the file(s) specified or /etc/sysctl.conf
if none given. Specifying – as filename means reading data from stan-
dard input.

1. Display all kernel parameters current value.

[root@nglinux ~]#sysctl -a
kernel.sched_child_runs_first = 0
kernel.sched_min_granularity_ns = 1000000
kernel.sched_latency_ns = 5000000
kernel.sched_wakeup_granularity_ns = 1000000
kernel.sched_tunable_scaling = 1
kernel.sched_features = 7279
kernel.sched_migration_cost = 500000
kernel.sched_nr_migrate = 32
kernel.sched_time_avg = 1000
kernel.sched_shares_window = 10000000
kernel.timer_migration = 1
kernel.sched_rt_period_us = 1000000
kernel.sched_rt_runtime_us = 950000
kernel.sched_compat_yield = 0
kernel.sched_rr_timeslice_ms = 100
kernel.sched_autogroup_enabled = 0

2. Tempoarary change of a parameter value.

### Change the value using -w parameter
[root@nglinux ~]#sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

### Verify if the value is changed.
[root@nglinux ~]#sysctl -a | grep -i net.ipv4.ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
[root@nglinux ~]#

3. Permanent change of a parameter value

### check current value of the parameter
[root@nglinux ~]# sysctl -a | grep -i net.ipv4.ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_use_pmtu = 0

### Change the value to 1 and check again
[root@nglinux ~]# tail -2 /etc/sysctl.conf 
net.ipv4.ip_forward = 1 

### Now re-read the sysctl.conf file using -p option.
[root@nglinux ~]#sysctl -p | grep -i net.ipv4.ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward = 1

### verify using sysctl -a command if the value is changed.
[root@nglinux ~]#sysctl -a | grep -i net.ipv4.ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
[root@nglinux ~]#

4. Viewing all variables defined in /etc/sysctl.conf.
To view only those parameters defined in /etc/sysctl.conf and read this file, we can use -p option which we have used above to read and load the file after changes.

[root@nglinux ~]#sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
[root@nglinux ~]#

After reading above article, you should now able to change the kernel parameters temporarily and permanent as per the requirement.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments