summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.de.marchi@gmail.com>2012-10-30 03:46:12 -0200
committerLucas De Marchi <lucas.de.marchi@gmail.com>2012-10-30 04:56:59 -0200
commite4a7352ad3c16f0b4b658218d9997e3570a70772 (patch)
tree3995d24cfb777a9f8d1496754c6d39cffef5c5a3
parent447eed8c489258552942afbba8ea042f99c838e6 (diff)
downloadkmod-tip.tar.gz
depmod: unref kmod_module once we don't need it anymoretip
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.
-rw-r--r--tools/depmod.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/depmod.c b/tools/depmod.c
index 154a0b3..670b90a 100644
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -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",