![为什么有些已加载的模块未被使用?](https://linux22.com/image/1539390/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%9C%89%E4%BA%9B%E5%B7%B2%E5%8A%A0%E8%BD%BD%E7%9A%84%E6%A8%A1%E5%9D%97%E6%9C%AA%E8%A2%AB%E4%BD%BF%E7%94%A8%EF%BC%9F.png)
我正在使用默认 Linux 内核运行 ArchLinux,使用 lsmod 时我注意到大约有 20 个模块用于我没有的硬件,或者它们没有用于任何事情,我检查了 /etc/modules-load.d/ 和 /etc/modprobe.d/ 并且两个目录都是空的,我想看看是什么加载了它们
$ lsmod | awk '{print $1" "$3" "$4}'
Module Used by
fuse 3
rfcomm 2
ipt_MASQUERADE 1
nf_nat_masquerade_ipv4 1 ipt_MASQUERADE
nf_conntrack_netlink 0
nfnetlink 2 nf_conntrack_netlink
xfrm_user 1
xfrm_algo 1 xfrm_user
iptable_nat 1
nf_conntrack_ipv4 3
nf_defrag_ipv4 1 nf_conntrack_ipv4
nf_nat_ipv4 1 iptable_nat
xt_addrtype 2
iptable_filter 1
xt_conntrack 1
nf_nat 2 nf_nat_masquerade_ipv4,nf_nat_ipv4
nf_conntrack 7 nf_conntrack_ipv4,ipt_MASQUERADE,nf_conntrack_netlink,nf_nat_masquerade_ipv4,xt_conntrack,nf_nat_ipv4,nf_nat
br_netfilter 0
bridge 1 br_netfilter
stp 1 bridge
llc 2 bridge,stp
overlay 0
bnep 2
uvcvideo 0
rtsx_usb_sdmmc 0
rtsx_usb_ms 0
videobuf2_vmalloc 1 uvcvideo
mmc_core 1 rtsx_usb_sdmmc
memstick 1 rtsx_usb_ms
videobuf2_memops 1 videobuf2_vmalloc
dm_thin_pool 1
dm_persistent_data 1 dm_thin_pool
dm_bio_prison 1 dm_thin_pool
dm_bufio 1 dm_persistent_data
libcrc32c 3 nf_conntrack,dm_persistent_data,nf_nat
crc32c_generic 0
videobuf2_v4l2 1 uvcvideo
videobuf2_core 2 uvcvideo,videobuf2_v4l2
videodev 3 uvcvideo,videobuf2_core,videobuf2_v4l2
btusb 0
rtsx_usb 2 rtsx_usb_sdmmc,rtsx_usb_ms
btrtl 1 btusb
media 2 uvcvideo,videodev
dm_mod 11 dm_bufio,dm_persistent_data,dm_thin_pool
dax 1 dm_mod
intel_rapl 0
x86_pkg_temp_thermal 0
intel_powerclamp 0
coretemp 0
nls_iso8859_1 1
kvm_intel 0
nls_cp437 1
kvm 1 kvm_intel
vfat 1
fat 1 vfat
snd_soc_skl 0
snd_soc_skl_ipc 1 snd_soc_skl
joydev 0
arc4 2
snd_hda_codec_hdmi 1
mousedev 0
snd_hda_codec_conexant 1
snd_hda_codec_generic 1 snd_hda_codec_conexant
iwlmvm 0
snd_soc_sst_ipc 1 snd_soc_skl_ipc
iTCO_wdt 1
snd_soc_sst_dsp 1 snd_soc_skl_ipc
mac80211 1 iwlmvm
iTCO_vendor_support 1 iTCO_wdt
snd_hda_ext_core 1 snd_soc_skl
snd_soc_sst_match 1 snd_soc_skl
irqbypass 1 kvm
iwlwifi 1 iwlmvm
evdev 23
snd_soc_core 1 snd_soc_skl
crct10dif_pclmul 0
crc32_pclmul 0
crc32c_intel 1
ghash_clmulni_intel 0
snd_compress 1 snd_soc_core
snd_pcm_dmaengine 1 snd_soc_core
pcbc 0
ac97_bus 1 snd_soc_core
aesni_intel 0
aes_x86_64 1 aesni_intel
ideapad_laptop 0
crypto_simd 1 aesni_intel
glue_helper 1 aesni_intel
hci_uart 0
btbcm 2 hci_uart,btusb
btqca 1 hci_uart
btintel 2 hci_uart,btusb
bluetooth 33 btrtl,hci_uart,btintel,btqca,bnep,btbcm,rfcomm,btusb
input_leds 0
cfg80211 3 iwlmvm,iwlwifi,mac80211
cryptd 3 crypto_simd,ghash_clmulni_intel,aesni_intel
led_class 3 iwlmvm,rtsx_usb_sdmmc,input_leds
ecdh_generic 1 bluetooth
sparse_keymap 1 ideapad_laptop
mac_hid 0
snd_hda_intel 6
rfkill 6 bluetooth,ideapad_laptop,cfg80211
r8169 0
mii 1 r8169
snd_hda_codec 4 snd_hda_intel,snd_hda_codec_conexant,snd_hda_codec_hdmi,snd_hda_codec_generic
intel_cstate 0
intel_rapl_perf 0
snd_hda_core 7 snd_hda_intel,snd_hda_codec_conexant,snd_hda_codec,snd_hda_ext_core,snd_soc_skl,snd_hda_codec_hdmi,snd_hda_codec_generic
snd_hwdep 1 snd_hda_codec
i915 33
ucsi 0
psmouse 0
pcspkr 0
snd_pcm 8 snd_hda_intel,snd_hda_codec,snd_pcm_dmaengine,snd_hda_ext_core,snd_hda_core,snd_soc_skl,snd_hda_codec_hdmi,snd_soc_core
wmi 1 ideapad_laptop
snd_timer 1 snd_pcm
snd 22 snd_compress,snd_hda_intel,snd_hwdep,snd_hda_codec_conexant,snd_hda_codec,snd_timer,snd_hda_codec_hdmi,snd_hda_codec_generic,snd_soc_core,snd_pcm
video 2 i915,ideapad_laptop
battery 0
soundcore 1 snd
drm_kms_helper 1 i915
intel_lpss_acpi 0
intel_lpss 1 intel_lpss_acpi
i2c_hid 0
drm 30 i915,drm_kms_helper
shpchp 0
tpm_tis 0
button 1 i915
mei_me 0
mei 1 mei_me
intel_gtt 1 i915
syscopyarea 1 drm_kms_helper
sysfillrect 1 drm_kms_helper
sysimgblt 1 drm_kms_helper
fb_sys_fops 1 drm_kms_helper
tpm_tis_core 1 tpm_tis
i2c_algo_bit 1 i915
tpm 2 tpm_tis,tpm_tis_core
intel_pch_thermal 0
i2c_i801 0
acpi_pad 0
sch_fq_codel 2
ac 0
vboxnetflt 0
vboxnetadp 0
pci_stub 1
vboxpci 0
vboxdrv 3 vboxnetadp,vboxnetflt,vboxpci
ip_tables 2 iptable_filter,iptable_nat
x_tables 5 ip_tables,iptable_filter,ipt_MASQUERADE,xt_addrtype,xt_conntrack
ext4 2
crc16 2 bluetooth,ext4
jbd2 1 ext4
fscrypto 1 ext4
mbcache 1 ext4
hid_logitech_hidpp 0
hid_logitech_dj 0
usbhid 0
hid 6 i2c_hid,usbhid,hid_logitech_dj,hid_logitech_hidpp
sr_mod 0
cdrom 1 sr_mod
sd_mod 6
serio_raw 0
atkbd 0
libps2 2 atkbd,psmouse
ahci 5
libahci 1 ahci
xhci_pci 0
xhci_hcd 1 xhci_pci
libata 2 ahci,libahci
usbcore 7 uvcvideo,usbhid,xhci_pci,rtsx_usb,btusb,xhci_hcd
scsi_mod 3 sd_mod,libata,sr_mod
usb_common 1 usbcore
i8042 1 ideapad_laptop
serio 6 serio_raw,atkbd,psmouse,i8042
请注意,我只打印 3 列:模块、使用和由。
然后我继续 grep 那些 Used == 0 和 by == "" 的模块,我得到了这些
$ lsmod | awk '{print $1" "$3" "$4}' | grep acpi_pad
acpi_pad 0
$ lsmod | awk '{print $1" "$3" "$4}' | grep battery
battery 0
$ lsmod | awk '{print $1" "$3" "$4}' | grep joydev
joydev 0
所以我的问题是,为什么要加载这些模块?出于什么目的,将它们列入黑名单是否安全?
提前致谢!
:-)
答案1
它们被加载是因为某些东西在某个时间使用了它们,可能是间接的,例如在启动期间,但当前没有应用程序使用它们。
对它们来说这是安全的rmmod
(当需要它们时它们只会被重新加载),但将它们列入黑名单并不安全(因为无论需要它们什么都不会起作用,而且如果你决定需要使用硬件的这一部分,它们将来也不会起作用)。
它们占用的内存非常少,所以无需担心。只需保持原样即可。