8

This is what happens when i run lsmod on an arm board (banana pi) running on kernel 4.3.0

# lsmod
Module                  Size  Used by
async_raid6_recov       1434  -2
async_pq                5548  -2
async_xor               3771  -2
async_memcpy            1665  -2
sha512_generic          8213  -2
rsa_generic             3235  -2
asn1_decoder            2667  -2
mpi                    13730  -2
poly1305_generic        3386  -2
pcbc                    2396  -2
michael_mic             2051  -2
md4                     3536  -2
ghash_generic           1908  -2
gcm                    10511  -2
fcrypt                  8128  -2
echainiv                2110  -2
crypto_user             4316  -2
crc32                   1581  -2
cmac                    2657  -2
chacha20poly1305        6641  -2
chacha20_generic        2902  -2
ccm                     7537  -2
async_tx                1958  -2
asymmetric_keys         3866  -2
arc4                    1882  -2
algif_aead              5293  -2
ablk_helper             1775  -2
cryptd                  7982  -2
dm_crypt               17382  -2
dm_mod                 84208  -2
algif_skcipher          7502  -2
evdev                  10705  -2
nvmem_sunxi_sid         2444  -2
nvmem_core              7792  -2
sg                     23835  -2
sun4i_ts                3948  -2
cpufreq_dt              4349  -2
ohci_platform           4551  -2
ohci_hcd               28715  -2
sun4i_ss               15192  -2
thermal_sys            30747  -2
hwmon                   2571  -2
uio_pdrv_genirq         2949  -2
uio                     7074  -2
#

This is /proc/modules just in case it can provide any hint

# cat /proc/modules
async_raid6_recov 1434 - - Live 0xbf140000
async_pq 5548 - - Live 0xbf13b000
async_xor 3771 - - Live 0xbf137000
async_memcpy 1665 - - Live 0xbf133000
sha512_generic 8213 - - Live 0xbf12d000
rsa_generic 3235 - - Live 0xbf129000
asn1_decoder 2667 - - Live 0xbf125000 (P)
mpi 13730 - - Live 0xbf11d000
poly1305_generic 3386 - - Live 0xbf119000
pcbc 2396 - - Live 0xbf115000
michael_mic 2051 - - Live 0xbf111000
md4 3536 - - Live 0xbf10d000
ghash_generic 1908 - - Live 0xbf109000
gcm 10511 - - Live 0xbf102000
fcrypt 8128 - - Live 0xbf0fd000
echainiv 2110 - - Live 0xbf0f9000
crypto_user 4316 - - Live 0xbf0f4000
crc32 1581 - - Live 0xbf0f0000
cmac 2657 - - Live 0xbf0ec000
chacha20poly1305 6641 - - Live 0xbf0e7000
chacha20_generic 2902 - - Live 0xbf0e3000
ccm 7537 - - Live 0xbf0de000
async_tx 1958 - - Live 0xbf0da000
asymmetric_keys 3866 - - Live 0xbf0d6000
arc4 1882 - - Live 0xbf0d2000
algif_aead 5293 - - Live 0xbf0cd000
ablk_helper 1775 - - Live 0xbf0c9000
cryptd 7982 - - Live 0xbf0c3000
dm_crypt 17382 - - Live 0xbf0b9000
dm_mod 84208 - - Live 0xbf099000
algif_skcipher 7502 - - Live 0xbf094000
evdev 10705 - - Live 0xbf08d000
nvmem_sunxi_sid 2444 - - Live 0xbf089000
nvmem_core 7792 - - Live 0xbf083000
sg 23835 - - Live 0xbf078000
sun4i_ts 3948 - - Live 0xbf074000
cpufreq_dt 4349 - - Live 0xbf069000
ohci_platform 4551 - - Live 0xbf064000
ohci_hcd 28715 - - Live 0xbf057000
sun4i_ss 15192 - - Live 0xbf04f000
thermal_sys 30747 - - Live 0xbf040000
hwmon 2571 - - Live 0xbf026000
uio_pdrv_genirq 2949 - - Live 0xbf024000
uio 7074 - - Live 0xbf000000
# 

The thing is I need the 'Used by' field showing the modules, otherwise I wouldn't care, I guess.

7

In your kernel configuration (make config, make menuconfig etc.) you need to enable CONFIG_MODULE_UNLOAD:

  • When CONFIG_MODULE_UNLOAD is set, the kernel counts references, as you may only unload a module if there are no references to it.

  • When CONFIG_MODULE_UNLOAD is not set, then the kernel has no need to count how many references there are to a module, and it always returns -2 as a marker value.

This answer originally came from Gentoo Forums.

1

The module reference count is made available in /sys/module/<module>/refcnt, for modules which can be unloaded. Modules which are built-in, or on kernels with CONFIG_MODULE_UNLOAD, don’t have a corresponding refcnt file.

To determine a module’s reference count, lsmod nowadays calls the kmod_module_get_refcnt function in the libkmod library; the latter tries to open the refcnt file to read the reference count. For modules which aren’t unloaded, the corresponding file operation fails and sets errno to ENOENT (no such file or directory), which is 2 on Linux — and the kmod_module_get_refcnt negates that and returns it as the reference count. lsmod takes that value and outputs it as the reference count.

This is why lsmod shows -2 for modules when CONFIG_MODULE_UNLOAD is not set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.