/proc/sys vs /sys/modules/mod/parameter

6,687

Solution 1

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).

Solution 2

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 filesystem. The organization of the filesystem directory hierarchy is strict, and based the internal organization of kernel data structures. The files that are created in the filesystem are (mostly) ASCII files with (usually) one value per file. 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
ahci
arc4
ath
ath9k
ath9k_common
ath9k_hw
bluetooth
bnep
cfg80211
…

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

Share:
6,687

Related videos on Youtube

ast
Author by

ast

Updated on September 18, 2022

Comments

  • ast
    ast almost 2 years

    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.

    Are parameters for modules in /proc/sys/ related only to hard complied into kernel? or there could be parameters for Loadable Kernel Modules also?

    LKM after being loaded into running Kernel reveal their parameters in /sys/modules/module/paraeter/params. Does it mean, that there aren't parameters for modules compiled into Kernel?

    What is difference between both directories.

  • ast
    ast almost 11 years
    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
    ast almost 11 years
    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
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 11 years
    @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.
  • ast
    ast almost 11 years
    thanks a lot, I was trying to fully understand this relationship and spent 3 days on reading a lot of stuff to find answer.