Re: [patch] Re: rmmod -a does not unload unused modules in 2.2.x

Keith Owens (kaos@ocs.com.au)
Thu, 25 Nov 1999 10:37:26 +1100


On Thu, 25 Nov 1999 01:09:35 +0200 (EET),
Tuukka Toivonen <tuukkat@ees2.oulu.fi> wrote:
>For first, rmmod -a has to be run 2 times before anything happens. But this
>still doesn't clean up "(unused)" modules. Why? Maybe there is a reason,
>but my system works fine with the test removed. Patch attached.
>
>Could this be included in the kernel, and if not, why not?
>
>--- linux-2.2.13/kernel/module.c.old Sun Dec 27 20:41:41 1998
>+++ linux-2.2.13/kernel/module.c Mon Nov 22 00:39:42 1999
>@@ -397,7 +397,6 @@
> && (mod->flags & MOD_AUTOCLEAN)
> && (mod->flags & MOD_RUNNING)
> && !(mod->flags & MOD_DELETED)
>- && (mod->flags & MOD_USED_ONCE)
> && !__MOD_IN_USE(mod)) {
> if ((mod->flags & MOD_VISITED)
> && !(mod->flags & MOD_JUST_FREED)) {

DON'T DO THAT! Removing the test for MOD_USED_ONCE opens you up to
horrendous race conditions. You end up with this :-

kernel needs a module, calls kmod
kmod does modprobe -k module_name
crond kicks in with rmmod -a (see Documentation/kmod.txt)
*** With your patch, unused modules are removed ***
kernel uses module that it thought was loaded but has been removed, splat!

The test for used_once is to prevent modules being unloaded before the
kernel gets a chance to use them. Do not change that test, instead
find out why you are loading modules marked as autoclean but not using
them.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/