I've been wondering for last few days how exactly does it work. We can set kernel runtimes parameters using sysctl or echo boolen 1> /proc/sys/module/exactParameter but in /sys/modules/module/parameters/parameter we can also set values.



What is difference between both directories.

migrated from serverfault.com Aug 31 '13 at 20:52

This question came from our site for system and network administrators.


There is little relation between /proc/sys and /sys other than the fact that both are kernel interfaces and a coincidence of names.

/proc/sys is an interface to sysctl, which are kernel configuration parameters. Reading or modifying /proc/sys/foo/bar is equivalent to getting or setting the foo.bar sysctl. Sysctl values are organized by semantic categories, they are not intrinsically related to the structure of the kernel. Many sysctl values are settings that are present on every Linux system regardless of what drivers or features are compiled in; some are related to optional features (e.g. certain network protocols) but never to specific hardware devices.

/sys/module is, as the name indicates, an interface to kernel modules. Each directory corresponds to one kernel module. You can read, and sometimes modify, the parameters of the module foo by writing to /sys/module/foo/parameters/*.

Components that are loaded in the kernel read their parameters from the kernel command line. These parameters cannot be set at runtime (at least not through an automatically-generated interface like /sys/module: the component can expose a custom interface for this).

  • So for modules compiled into Kernel, I can only add parameters through kernel command line (like: /proc/cmdline). There is no other way to change them at runtime? Do I understood right? So what exactly are these kernel (configuration) parameters? I thought that they are changable parameters of some modules compiled into Kernel – ast Sep 1 '13 at 20:37
  • @ast The sysctl parameters are documented in Documentation/sysctl/*.txt in the Linux kernel documentation. It's a set of parameters that mostly apply regardless of which features and drivers are compiled into a particular kernel. – Gilles Sep 1 '13 at 20:42
  • thanks a lot, I was trying to fully understand this relationship and spent 3 days on reading a lot of stuff to find answer. – ast Sep 1 '13 at 20:57

The paper "The sysfs Filesystem" by Patrick Mochel will give you a far better overview of the purpose and history of /sys than will fit in this box. Quoting the abstract:

sysfs is a feature of the Linux 2.6 kernel that allows kernel code to export information to user processes via an in-memory ﬁlesystem. The organization of the ﬁlesystem directory hierarchy is strict, and based the internal organization of kernel data structures. The ﬁles that are created in the ﬁlesystem are (mostly) ASCII ﬁles with (usually) one value per ﬁle. These features ensure that the information exported is accurate and easily accessible, making sysfs one of the most intuitive and useful features of the 2.6 kernel.

In answer to your specific question "Do loadable kernel module get a representation in /sys?" the answer is "yes, if the module's author provides an interface". This can be easily demonstrated by showing how many loaded modules have corresponding entries in /sys/module

$ lsmod | awk '{print $1}' | sort > /tmp/lsmod
$ cd /sys/module ; ls > /tmp/sysmodule
$ comm -12 /tmp/lsmod /tmp/sysmodule

which on my system shows that 73 out of 73 loadable modules have a corresponding entry in /sys/module.

  • I found information especially about /sys/modules/, that there are always each LKM and module_param(name, type, perm) impacts appearance of directory parameters. But I have still questions about sysctl and /proc/sys, where we can set Kernel Runtime Parameters. Why is not possible to employ /sys/modules? And where we set parameters for Kernel compiled modules ( /sys/modules/ or in /proc/sys/ too)? Maybe I mix kernel options with module parameters (I thought that they are the same) so using sysctl I should set module parameter or some kernel functionality – ast Aug 31 '13 at 23:16

Your Answer

