]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: unref kmod_module once we don't need it anymore
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 30 Oct 2012 05:46:12 +0000 (03:46 -0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 30 Oct 2012 06:56:59 +0000 (04:56 -0200)
Once we read all we need from a module, unref it so any resource taken
by it (including the mmap to access the file in libkmod) will be
dropped. This drastically reduces the number of open file descriptors
and also the memory needed, with no performance penalties. Rather,
there's a small speedup of ~2.6%.

Running depmod in a laptop with 2973 modules and comparing the number of
open file descriptors for kmod-10, before and after the last patches to
depmod (caaf438cb681c5b5b5b3c32e5b6bd12e96993dd7 and HEAD) we have:

Before: 2980 simultaneously open fds
After: 7    simultaneously open fds
kmod-10: 7    simultaneously open fds

So now we have the speedup of caching the file in kmod_module without
the drawback of increasing the number of open file descriptors.

tools/depmod.c

index 154a0b3dc020005be123811864152729e1d538ee..670b90a86eed262fc928250fabd6b48cee419292 100644 (file)
@@ -993,7 +993,7 @@ static void cfg_free(struct cfg *cfg)
 /* depmod calculations ***********************************************/
 struct mod {
        struct kmod_module *kmod;
-       const char *path;
+       char *path;
        const char *relpath; /* path relative to '$ROOT/lib/modules/$VER/' */
        char *uncrelpath; /* same as relpath but ending in .ko */
        struct kmod_list *info_list;
@@ -1029,10 +1029,11 @@ static void mod_free(struct mod *mod)
 {
        DBG("free %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path);
        array_free_array(&mod->deps);
-       kmod_module_unref(mod->kmod);
+       assert(mod->kmod == NULL);
        kmod_module_info_free_list(mod->info_list);
        kmod_module_dependency_symbols_free_list(mod->dep_sym_list);
        free(mod->uncrelpath);
+       free(mod->path);
        free(mod);
 }
 
@@ -1141,7 +1142,7 @@ static int depmod_module_add(struct depmod *depmod, struct kmod_module *kmod)
 
        array_init(&mod->deps, 4);
 
-       mod->path = kmod_module_get_path(kmod);
+       mod->path = strdup(kmod_module_get_path(kmod));
        lastslash = strrchr(mod->path, '/');
        mod->baselen = lastslash - mod->path;
        if (strncmp(mod->path, cfg->dirname, cfg->dirnamelen) == 0 &&
@@ -1576,6 +1577,8 @@ load_info:
                kmod_module_get_info(mod->kmod, &mod->info_list);
                kmod_module_get_dependency_symbols(mod->kmod,
                                                   &mod->dep_sym_list);
+               kmod_module_unref(mod->kmod);
+               mod->kmod = NULL;
        }
 
        DBG("loaded symbols (%zd modules, %zd symbols)\n",