How to Change Kernel Runtime Parameters in a Persistent and Non-Persistent Way?


Introduction

Kernel runtime parameters are settings that control the behavior of the Linux kernel on your system. These parameters can affect a wide range of system functions, such as memory allocation, network performance, and CPU scheduling.

Understanding how to change these parameters is crucial for optimizing system performance and troubleshooting issues that may arise. There are two main ways to change kernel runtime parameters: non-persistent changes and persistent changes.

Non-persistent changes modify the kernel's behavior temporarily, lasting only until you reboot your system. Persistent changes, on the other hand, modify the kernel's behavior permanently and persist across reboots.

Changing Kernel Runtime Parameters in a Non-Persistent Way

Definition of Non-Persistent Changes and How They Work

Non-persistent changes to kernel runtime parameters are changes that are temporary, meaning they do not survive a system reboot. These changes can be made using command-line tools such as sysctl or echo. Once the system is rebooted, the changes made to the kernel runtime parameters will be lost, and the system will revert to its default settings.

One major advantage of non-persistent changes is that they allow for quick testing of different configurations without making any permanent changes to the system. This flexibility comes with a downside, as it requires constant attention from the administrator to ensure that any desired non-persistent changes have been re-applied after each reboot or service restart.

Step-by-Step Guide on How to Make Non-Persistent Changes Using Command-Line Tools

The following steps detail how to change kernel runtime parameters in a non-persistent way using command-line tools −

  • Identify which kernel parameter(s) you want to modify.

  • Open a terminal and type "sysctl -a" or "cat /proc/sys/[parameter_name]" (without quotes) to view all current values for all sysctl variables or for an individual parameter respectively.

sysctl –a

or

cat /proc/sys/[parameter_name]
  • Determine which value(s) you want to change, and use either "echo [value] > /proc/sys/[parameter_name]" (without quotes) or "sysctl -w [parameter_name]=[value]" (without quotes) followed by "sysctl -p" (to apply all pending settings).

echo [value] > /proc/sys/[parameter_name]

or

sysctl -w [parameter_name]=[value]

sysctl -p
  • Verify that your new value(s) took effect: either use "cat /proc/sys/[parameter_name]" again or try running your application with the new settings.

Examples of Common Kernel Runtime Parameters That Can Be Changed in a Non-Persistent Way

Below are some examples of kernel runtime parameters that can be changed in a non-persistent way using the above process −

  • net.ipv4.tcp_syncookies − set to 0 to disable SYN cookies, which are used to protect against certain types of denial-of-service attacks.

  • vm.swappiness − controls the degree to which the kernel prefers to swap out inactive processes over reclaiming file-backed pages in memory.

  • net.ipv4.ip_forward − set to 1 to enable IP forwarding on a node acting as a router.

  • kernel.sem − adjusts the maximum values for System V IPC semaphores, message queues, and shared memory segments.

  • fs.file-max − sets the maximum number of file handles available system-wide.

By changing these parameters in a non-persistent way, administrators can experiment with different configurations and determine what works best for their systems before committing any changes permanently.

Changing Kernel Runtime Parameters in a Persistent Way

Definition of Persistent Changes and How They Differ from Non-Persistent Changes

Making persistent changes to kernel runtime parameters means that the changes will remain even after the system reboots. These changes are saved in configuration files so they can be loaded automatically when the system initializes. This is different from non-persistent changes which only temporarily modify kernel settings and revert back to their original values upon system restart.

Persistent changes are helpful for making long-term modifications to kernel settings that need to remain consistent across multiple reboots. Additionally, persistent changes can be made through configuration files, which can be useful for automating configurations on multiple systems.

Step-by-Step Guide on How to Make Persistent Changes Using Configuration Files

To make persistent changes using configuration files, you will need to modify the appropriate configuration file for the parameter you want to change. Typically, these configuration files are located in the /etc/sysctl.d/ directory. Here's a step-by-step guide on how to do this −

  • Open a terminal window and switch to root user by typing "sudo su".

  • Navigate to the /etc/sysctl.d/ directory by typing "cd /etc/sysctl.d/".

  • Create a new file with ".conf" extension in this directory using your preferred text editor (e.g. nano) by typing "nano filename.conf".

  • Add your desired kernel runtime parameters with their corresponding values into this file (one parameter-value pair per line).

For example −

net.ipv4.tcp_fin_timeout=30 
vm.swappiness=10  
  • Save and close the file by pressing CTRL+X followed by Y and then ENTER.

  • Refresh sysctl settings using command: "sysctl --system" After performing these steps, your persistent kernel runtime parameter changes will be saved to the configuration file and will persist across reboots.

Examples of Common Kernel Runtime Parameters that Can Be Changed in a Persistent Way

Many kernel runtime parameters can be changed in a persistent way through configuration files. Here are some common examples −

  • net.ipv4.tcp_fin_timeout − This parameter controls the time that a connection stays in the TIME_WAIT state after it's closed. The default value is usually 60 seconds, but this can be reduced for faster connection closing.

  • vm.swappiness − This parameter controls how aggressively the kernel swaps memory pages between RAM and swap space. Lower values (like 10) result in less swapping and more use of physical memory, while higher values (like 60) result in more swapping and less use of physical memory.

  • fs.file-max − This parameter sets the maximum number of open files that can exist on the system at any given time. Increasing this value can be helpful for systems with high file I/O demands.

Overall, changing kernel runtime parameters in a persistent way using configuration files is an important skill for system administrators who want to make long-term modifications to their system's behavior. By following these steps, you can ensure your configurations are automatically loaded each time your system starts up, reducing manual intervention and saving time.

Best Practices for Changing Kernel Runtime Parameters

Changing kernel runtime parameters can have a significant impact on system performance and stability. In order to avoid issues and ensure changes are effective, it is important to follow best practices when making changes. This section will cover some of the key best practices.

Importance of Testing Changes Before Implementing Them

Prior to implementing any changes, it is important to test those changes in a non-production environment. This allows for any issues or conflicts to be identified prior to rolling out the changes on production systems. Testing should include verification that the system functions as expected after the change has been made.

Discussion on When to use Non-persistent vs Persistent Changes

Choosing whether to make non-persistent or persistent kernel runtime parameter changes depends largely on the intended scope of the change and its potential impact. Non-persistent changes are ideal for temporary modifications that do not need to be maintained between system reboots, while persistent changes are better suited for long-term modifications that should persist across reboots.

Conclusion

Changing kernel runtime parameters can be a powerful tool for optimizing system performance and functionality. By understanding the differences between non-persistent and persistent changes, users can make informed decisions about which method to use for their specific needs. It is important to keep in mind that any changes made to these parameters should be thoroughly tested before implementing them on a production system.

Throughout this article, we have covered the step-by-step process of making both non-persistent and persistent changes using command line tools and configuration files. We have also discussed best practices for changing kernel runtime parameters and offered tips on troubleshooting potential issues that may arise.

Updated on: 24-Aug-2023

212 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements