This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: System Administration

Kernel tuning with sysctl

By Federico Kereki on September 09, 2008 (4:00:00 PM)

Share    Print    Comments   

The Linux kernel is flexible, and you can even modify the way it works on the fly by dynamically changing some of its parameters, thanks to the sysctl command. Sysctl provides an interface that allows you to examine and change several hundred kernel parameters in Linux or BSD. Changes take effect immediately, and there's even a way to make them persist after a reboot. By using sysctl judiciously, you can optimize your box without having to recompile your kernel, and get the results immediately.

To start getting a taste of what sysctl can modify, run sysctl -a and you will see all the possible parameters. The list can be quite long: in my current box there are 712 possible settings.

$ sysctl -a kernel.panic = 0 kernel.core_uses_pid = 0 kernel.core_pattern = core kernel.tainted = 129 ...many lines snipped...

If you want to get the value of just a single variable, use something like sysctl vm.swappiness, or just sysctl vm to list all variables that start with "vm." Add the -n option to output just the variable values, without the names; -N has the opposite effect, and produces the names but not the values.

You can change any variable by using the -w option with the syntax sysctl -w variable=value. For example, sysctl -w net.ipv6.conf.all.forwarding=1 sets the corresponding variable to true (0 equals "no" or "false"; 1 means "yes" or "true") thus allowing IP6 forwarding. You may not even need the -w option -- it seems to be deprecated. Do some experimenting on your own to confirm that.

For more information, run man sysctl to display the standard documentation.

sysctl values are loaded at boot time from the /etc/sysctl.conf file. This file can have blank lines, comments (lines starting either with a "#" character or a semicolon), and lines in the "variable=value" format. For example, my own sysctl.conf file is listed below. If you want to apply it at any time, you can do so with the command sysctl -p.

# Disable response to broadcasts. net.ipv4.icmp_echo_ignore_broadcasts = 1 # enable route verification on all interfaces net.ipv4.conf.all.rp_filter = 1 # enable ipV6 forwarding net.ipv6.conf.all.forwarding = 1 # increase the number of possible inotify(7) watches fs.inotify.max_user_watches = 65536

Getting somewhere?

With so many tunable parameters, how do you decide what to do? Alas, this is a sore point with sysctl: most of the relevant documentation is hidden in the many source files of the Linux kernel, and isn't easily available, and it doesn't help that the explanations given are sometime arcane and difficult to understand. You may find something in the /usr/src/linux/Documentation/sysctl directory, but most (if not all) files there refer to kernel 2.2, and seemingly haven't been updated in the last several years.

Looking around for books on the subject probably won't help much. I found hack #71 in O'Reilly's Linux Server Hacks, Volume 2, from 2005, but that was about it. Several other books include references to sysctl, but as to specific parameters or hints, you are on your own.

As an experiment, I tried looking for information on the swappiness parameter, which can optimize virtual memory management. The /usr/src/Linux/Documentation/sysctl/vm.txt file didn't even refer to it, probably because this parameter appeared around version 2.6 of the kernel. Doing a general search in the complete /usr/src/linux directory turned up five files that mention "swappiness": three "include" (.h) files in include/linux, plus kernel/sysctl.c and mm/vmscan.c. The latter file included the information:

/* * From 0 .. 100. Higher means more swappy. */ int vm_swappiness = 60;

That was it! You can see the default value (60) and a minimal reference to the field meaning. How helpful is that?

My suggestion would be to use sysctl -a to learn the available parameters, then Google around for extra help. You may find, say, an example of changing the shared memory allocation to solve a video program problem, or an explanation on vm.swappiness, or even more suggestions for optimizing IP4 network traffic.

sysctl shows yet another aspect of the great flexibility of Linux systems. While documentation for it is not widely available, learning its features and capabilities on your own can help you get even more performance out of your box. That's system administration at its highest (or lowest?) level.

Federico Kereki is an Uruguayan systems engineer with more than 20 years' experience developing systems, doing consulting work, and teaching at universities.

Share    Print    Comments   

Comments

on Kernel tuning with sysctl

Note: Comments are owned by the poster. We are not responsible for their content.

Kernel tuning with sysctl

Posted by: Anonymous [ip: 96.14.205.198] on September 09, 2008 05:26 PM
There won't be a whole book on sysctl anytime soon--it would be about 14 pages, including title, copyright, TOC, and index. The actual parameters have changed dramatically over time, not only in availability, but also in interpretation. A setting that's valid in a 2.4 kernel might be gone in 2.6, or might have a different set of valid values.

#

Re: Kernel tuning with sysctl

Posted by: Anonymous [ip: 63.160.65.14] on September 11, 2008 11:39 PM
Understanding the internal functions of the kernel is essential before tuning it.

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 88.115.31.30] on September 09, 2008 06:25 PM
"Federico Kereki is an Uruguayan systems engineer with more than 20 years' experience developing systems, doing consulting work, and teaching at universities."

And your best recommendation is for everyone to privately figure it out, 20 years down the drain.
How about a wiki with real-world information and experience of the inner workings of sysctl?
Another just as needed wiki would be one regarding kernel-settings. "If you dont know what this does then..." anyone?

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 69.202.144.113] on September 10, 2008 04:10 AM
This is a very common problem with open source projects -- lack of documentation. I believe that it's one of the problems that most hold back open source from wider adoption. Either no one (except the guy who coded it) knows how to use the software, or people don't even know what the software does at all.

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 195.113.70.110] on September 10, 2008 12:03 PM
o hovne

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 59.41.252.228] on September 10, 2008 02:39 PM
So where's the documentation on how to tweak the Windows kernel? Of course it doesn't exist. Not enough documentation. So Windows has no great future running the internet. Open Source has plenty of documentation there are thousands of books on every subject someone can learn. Such as how to build a kernel from scratch.

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 72.51.48.231] on September 10, 2008 04:18 PM
"While documentation for it is not widely available"

Linux documentation may not exist, but sysctl() is supposedly a standard interface - I suggest reading the BSD docs for it, they're quite comprehensive.

This is not to say, of course, that code written for BSD sysctl() will work on Linux - I highly doubt it - but I'm pretty sure the interface is exactly the same (the system call, not the sysctl program)

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 134.59.22.73] on September 11, 2008 01:06 PM
"/proc et /sys" from Olivier Daudel is the only book dedicated to proc and sys documentation: http://www.amazon.fr/Proc-sys-Olivier-Daudel/dp/2841773868/ref=sr_1_2?ie=UTF8&s=books&qid=1221134588&sr=1-2.
It's a very good reference...but in french, what maybe harder than reading the kernel source.

#

Kernel tuning with sysctl

Posted by: Anonymous [ip: 76.183.9.4] on September 11, 2008 01:33 PM
"Federico Kereki is an Uruguayan systems engineer with more than 20 years' experience developing systems, doing consulting work, and teaching at universities."

For anyone complaining about the disconnect between Federico's abundant experience and "where to go from here", ponder this:

a) He has posted more than just this article. He is most definitely giving back to the open source community, even though it might not be in a shrink-wrapped, wikified format you desire.

b) Is the suggestion of a wiki a bad one? Not at all; feel free to get cracking on that. :-) I've been a computer professional for 20+ years myself, and going from memory, I've added one whole page to the Ubuntu site, and some years back was trying to help package up NIS+ for RHEL (despite lack of experience in packaging at the time).

c) It's easy to complain. It's a bit more of a challenge to step up and write something for others to consume. It's even more challenging to do so in a way which not only keeps the reader's interest, but is concise, well-written (not full of typos and grammatical atrocities), ... you get my point.

d) He's from Uruguay. How cool is that? :-)

#

Re: Kernel tuning with sysctl

Posted by: Anonymous [ip: 76.114.35.96] on September 18, 2008 06:12 AM
Elitist often miss the point as their ego gets in the way of their myopic perspective. The point is that one needs to research sysctl() to discover its functionality. This can be applied to anything *nix.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya