Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: module auto-unload



On Sun, 15 Dec 2013, Paul Goyette wrote:

On Sun, 15 Dec 2013, Paul Goyette wrote:

Given the recent discussion on the usefulness of auto-unload, would it possibly make sense to enable/disable this via a new sysctl variable?

We could make kern.module.unload_delay default to 10 seconds (the current default); if the delay is ever set to a non-positive value, it would disable the auto-unload feature completely.

Comments?

The attached patch has been compile-tested, but not actually booted. If anyone wants to give it a try, please let me know if it works.

Attached an updated patch that fixes a cut-&-paste error and also updates the sysctl(7) man page.


-------------------------------------------------------------------------
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:       |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com    |
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |                          | pgoyette at netbsd.org  |
-------------------------------------------------------------------------
Index: share/man/man7/sysctl.7
===================================================================
RCS file: /cvsroot/src/share/man/man7/sysctl.7,v
retrieving revision 1.77
diff -u -p -r1.77 sysctl.7
--- share/man/man7/sysctl.7     27 Oct 2013 10:09:28 -0000      1.77
+++ share/man/man7/sysctl.7     15 Dec 2013 18:46:43 -0000
@@ -739,6 +739,7 @@ The third level names for the settings a
 .Bl -column "kern.module.autoload" "integer" "Changeable" -offset indent
 .It Sy Third level name        Type    Changeable
 .It kern.module.autoload       integer yes
+.It kern.module.autotime       integer yes
 .It kern.module.verbose        integer yes
 .El
 .Pp
@@ -749,6 +750,10 @@ A boolean that controls whether kernel m
 See
 .Xr module 7
 for additional details.
+.It Li kern.module.autotime
+An integer that controls the delay before an attempt is made to
+automatically unload a module that was auto-loaded.  Setting this value
+to zero disables the auto-unload function.
 .It Li kern.module.verbose
 A boolean that enables or disables verbose
 debug messages related to kernel modules.
Index: sys/kern/kern_module.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_module.c,v
retrieving revision 1.93
diff -u -p -r1.93 kern_module.c
--- sys/kern/kern_module.c      13 Sep 2013 07:18:34 -0000      1.93
+++ sys/kern/kern_module.c      15 Dec 2013 18:46:58 -0000
@@ -99,6 +99,8 @@ static void   module_enqueue(module_t *);
 static bool    module_merge_dicts(prop_dictionary_t, const prop_dictionary_t);
 
 static void    sysctl_module_setup(void);
+static int     sysctl_module_autotime(SYSCTLFN_PROTO);
+
 #define MODULE_CLASS_MATCH(mi, class) \
        ((class) == MODULE_CLASS_ANY || (class) == (mi)->mi_class)
 
@@ -405,6 +407,27 @@ module_builtin_require_force(void)
 
 static struct sysctllog *module_sysctllog;
 
+static int
+sysctl_module_autotime(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node;
+       int t, error;
+
+       t = *(int *)rnode->sysctl_data;
+
+       node = *rnode;
+       node.sysctl_data = &t;
+       error = sysctl_lookup(SYSCTLFN_CALL(&node));
+       if (error || newp == NULL)
+               return (error);
+
+       if (t < 0)
+               return (EINVAL);
+
+       *(int *)rnode->sysctl_data = t;
+       return (0);
+}
+
 static void
 sysctl_module_setup(void)
 {
@@ -433,10 +456,16 @@ sysctl_module_setup(void)
                CTL_CREATE, CTL_EOL);
        sysctl_createv(&module_sysctllog, 0, &node, NULL,
                CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
-               CTLTYPE_BOOL, "verbose",
+               CTLTYPE_BOOL, "autotime",
                SYSCTL_DESCR("Enable verbose output"),
                NULL, 0, &module_verbose_on, 0,
                CTL_CREATE, CTL_EOL);
+       sysctl_createv(&module_sysctllog, 0, &node, NULL,
+               CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+               CTLTYPE_INT, "verbose",
+               SYSCTL_DESCR("Auto-unload delay"),
+               sysctl_module_autotime, 0, &module_autotime, 0,
+               CTL_CREATE, CTL_EOL);
 }
 
 /*
@@ -1107,10 +1136,10 @@ module_do_load(const char *name, bool is
        if (modp != NULL) {
                *modp = mod;
        }
-       if (autoload) {
+       if (autoload && module_autotime > 0) {
                /*
                 * Arrange to try unloading the module after
-                * a short delay.
+                * a short delay unless auto-unload is disabled.
                 */
                mod->mod_autotime = time_second + module_autotime;
                mod->mod_flags |= MODFLG_AUTO_LOADED;
@@ -1288,7 +1317,8 @@ module_find_section(const char *name, vo
  *
  *     Automatically unload modules.  We try once to unload autoloaded
  *     modules after module_autotime seconds.  If the system is under
- *     severe memory pressure, we'll try unloading all modules.
+ *     severe memory pressure, we'll try unloading all modules, else if
+ *     module_autotime is non-positive, we don't try to unload.
  */
 static void
 module_thread(void *cookie)
@@ -1311,6 +1341,8 @@ module_thread(void *cookie)
 
                        if (uvmexp.free < uvmexp.freemin) {
                                module_thread_ticks = hz;
+                       } else if (module_autotime <= 0) {
+                               continue;
                        } else if (mod->mod_autotime == 0) {
                                continue;
                        } else if (time_second < mod->mod_autotime) {


Home | Main Index | Thread Index | Old Index