Sysctl

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Sysctl is an interface for examining and dynamically changing parameters in the BSD and Linux operating systems. The implementation mechanism in these two systems is very different.

In BSD these parameters are generally objects in a Management Information Base that describe tunable limits such as the size of a shared memory segment, the number of threads the operating system will use as an NFS client, or the maximum number of processes on the system; or describe, enable or disable behaviors such as IP forwarding, security restrictions on the superuser (the "securelevel"), or debugging output.

In BSD a system call or system call wrapper is usually provided for use by programs, as well as an administrative program and a configuration file (for setting the tunable parameters when the system boots).

This feature appeared in the "4.4BSD" version of Unix. It has the advantage over hardcoded constants that changes to the parameters can be made dynamically without recompiling the kernel.

In Linux the sysctl interface mechanism is implemented on top of procfs or sysfs. This difference means checking the value of some parameter requires opening a file in a virtual filesystem, reading its contents, parsing them and closing the file.

Contents

[edit] Performance considerations

In BSD the system call is implemented directly in the kernel, as described in the sysctl(3) manual page[1]. In Linux, the sysctl is implemented as a wrapper around file system routines that access contents of files in the /proc directory. The result is that it is much more expensive to use the sysctl interface in Linux. The effect of this can be easily seen with system monitoring tools. On Linux, running top and holding the spacebar to force it to refresh quickly uses large amounts of CPU time, which is not the case on BSD systems. On Linux sysctl interfaces are typically not called repeatedly or frequently in this fashion so this impact is rarely an important consideration. But the difference is worth noting. A programmer who is not aware of the cost or who is used to the lower cost on BSD systems might assume that it is not significant to call the interface repeatedly on Linux and could create Linux software that significantly slows down the system by calling sysctl too frequently.

However the Linux approach provides its own advantages, allowing the direct manipulation of parameters hidden by sysctl through scripts in user space. This is arguably closer to the original unix philosophy of "everything is a file" and provides better integration to distributing the facilities over a network using a file system interface.

[edit] Examples

When IP forwarding is enabled, the operating system kernel will act as a router. In FreeBSD, NetBSD, OpenBSD, DragonFly BSD, and Darwin/Mac OS X the parameter net.inet.ip.forwarding can be set to 1 to enable this behavior. In Linux's emulation of sysctl, the parameter is called net.ipv4.ip_forward.

In most systems, the command sysctl -w parameter=1 will enable the desired behavior. This will persist until the next reboot. If the behavior should be enabled whenever the system boots, the line parameter=1 can be added to the file /etc/sysctl.conf. Additionally, some sysctl variables cannot be modified after the system is booted, these variables (depending on the variable and the version and flavor of BSD) need to either be set statically in the kernel at compile time or set in /boot/loader.conf.

[edit] References

[edit] External links

Personal tools
Languages