Kernel Newbies archive on lore.kernel.org
 help / Atom feed
* When kernel deletes unused kernel module from RAM?
@ 2018-11-30 17:35 Lev Olshvang
  2018-11-30 19:12 ` valdis.kletnieks
  0 siblings, 1 reply; 2+ messages in thread
From: Lev Olshvang @ 2018-11-30 17:35 UTC (permalink / raw)
  To: kernelnewbies

[-- Attachment #1: Type: text/html, Size: 975 bytes --]

<div xmlns="http://www.w3.org/1999/xhtml">Hi list,</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">I saw many times that kernel keeps kernel module with reference count of 0 in a running system until explicit rmmod command is entered/</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Is there any way to require that unused module will be removed from kernel by the kernel itself ?</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">I mean may be there are  might exist some sysctl parameter  or configuration option or OOM policy to configure such behavior?</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Please advice.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div><div xmlns="http://www.w3.org/1999/xhtml">Lev.</div><div xmlns="http://www.w3.org/1999/xhtml"> </div>


[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: When kernel deletes unused kernel module from RAM?
  2018-11-30 17:35 When kernel deletes unused kernel module from RAM? Lev Olshvang
@ 2018-11-30 19:12 ` valdis.kletnieks
  0 siblings, 0 replies; 2+ messages in thread
From: valdis.kletnieks @ 2018-11-30 19:12 UTC (permalink / raw)
  To: Lev Olshvang; +Cc: kernelnewbies

[-- Attachment #1.1: Type: text/plain, Size: 1850 bytes --]

On Fri, 30 Nov 2018 20:35:54 +0300, Lev Olshvang said:

> I saw many times that kernel keeps kernel module with reference count of 0 in a
> running system until explicit rmmod command is entered/

> Is there any way to require that unused module will be removed from kernel by
> the kernel itself ?

No, because that's a really good way to shoot yourself in the foot.

Hint 1:  What's the refcount the instant after modprobe finishes?  Even if it's being
auto-probed by modprobe because it's a pre-req module for the one that modprobe
has been asked to load, there's a race condition.

lsmod | grep dell
dell_laptop            32768  0
dell_smbios            20480  1 dell_laptop

So if smbios got loaded due to a 'modprobe dell_laptop', the refcount will
still be 0 for an instant, and it gets auto-rmmod'ed before dell_laptop can try
(and then fail) to load)

Hint 2:

What will break if that dell_laptop module gets auto-rmmod'ed?

The *correct* solution here is to have a userspace daemon that cleans up if you *really*
care about a module being unloaded.  Except for the beached-whale module from NVidia
that's 14M in size, most modules are only 8K to 200K or so in size - if you're really that
stressed for RAM, you're probably an embedded system and have *bigger* things to worry
about.

Now, there's *other* good reasons to want to remove a module - for instance,  only have
certain security-related modules loaded when a security USB widget is plugged in, for
example, or time-of-day restrictions on when the feature(s) provided by a module are
available.  But that sort of thing is best done from userspace, not "when the refcount
reaches zero".

So the question becomes:  What actual problem are you trying to solve by doing an
auto-rmmod of a module? There's almost certainly a better solution....

[-- Attachment #1.2: Type: application/pgp-signature, Size: 486 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30 17:35 When kernel deletes unused kernel module from RAM? Lev Olshvang
2018-11-30 19:12 ` valdis.kletnieks

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox