Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


This section not only examines theprocinterface of the sysctl mechanism, but also discusses how sysctls
are registered and managed in the kernel, particularly as these two aspects are closely related.

Using Sysctls


To paint a general picture of system control options and usage, I have chosen a short example to illustrate
how userspace programs call on sysctl resources with the help of thesysctlsystem call. The example
also shows how difficult things would be without theprocfilesystem.

The many sysctls in everyUnixlook-alike are organized into a clear hierarchical structure that mirrors
the familiar tree structure used in filesystems: and it’s thanks to this feature that sysctls can be exported
with such ease by a virtual filesystem.

However, in contrast to filesystems, sysctls do not use strings to represent path components. Instead,
they use integer numbers packed in symbolic constants. These are easier for the kernel to parse than
pathnames in strings.

The kernel provides several ‘‘base categories‘‘ includingCTL_DEV(information on peripherals),CTL_KERN
(information on the kernel itself), andCTL_VM(memory management information and parameters).

CTL_DEVincludes a subcategory namedDEV_CDROMthat supplies information on the CD-ROM drive(s) of
the system (CD-ROM drives are obviously peripherals).

InCTL_DEV/DEV_CDROMthere are several ‘‘end points‘‘ representing the actual sysctls. For
example, there is a sysctl calledDEV_CDROM_INFOwhich supplies general information on the
capabilities of the drive. Applications wishing to access this sysctl must specify the path-
nameCTL_DEV/DEV_CDROM/DEV_CDROM_INFOto identify it uniquely. The numeric values of
the required constants are defined in<sysctl.h>, which the standard library also used (via
/usr/include/sys/sysctl.h).

Figure 10-6 shows a graphic excerpt from the sysctl hierarchy that also includes the path described above.

CTL_KERN

KERN_OSTYPE
KERN_OSRELEASE
KERN_SYSRQ

DEV_CDROM_CHECK_MEDIA

CTL_VM VM_PAGEBUF
VM_SWAPPINESS

CTL_NET

NET_CORE

NET_IPV4

NET_CORE_FASTROUTE
NET_CORE_DEVWEIGHT

NET_IPV4_TVP_FIN_TIMEOUT
NET_IPV4_AUTOCONFIG

CTL_DEV
DEV_CDROM

DEV_PARPORT DEV_CDROM_INFO
DEV_CDROM_AUTOCLOSE

Figure 10-6: Hierarchy of sysctl entries.
Free download pdf