Thank you everyone for the time spent in the analysis. I understand better now. I was confused, as I thought the module_free() below actually free up the entire module. But as you and Johannes and etc have highlighted, module_free() only free up the INIT section: mutex_lock(&module_mutex); /* Drop initial reference. */ module_put(mod); unwind_remove_table(mod->unwind_info, 1); module_free(mod, mod->module_init); mod->module_init = NULL; mod->init_size = 0; mod->init_text_size = 0; mutex_unlock(&module_mutex); Apologized for the confusion!!!! Thanks :-). On Sun, Mar 16, 2008 at 1:22 AM, Thomas Petazzoni <thomas.petazzoni@xxxxxxxxxxxxxxxxxx> wrote: > Hi, > > Le Sun, 16 Mar 2008 00:57:00 +0800, > "Peter Teoh" <htmldeveloper@xxxxxxxxx> a écrit : > > > > may be....where is it?? i will continue the search....thank you for > > the feedback. > > Everything starts in sys_init_module() > http://lxr.free-electrons.com/source/kernel/module.c#2090 > > It starts by loading the module using load_module() > http://lxr.free-electrons.com/source/kernel/module.c#1650 > > Which at some points, calls layout_sections(), which computes > mod->init_size: > > 1487 for (m = 0; m < ARRAY_SIZE(masks); ++m) { > 1488 for (i = 0; i < hdr->e_shnum; ++i) { > 1489 Elf_Shdr *s = &sechdrs[i]; > 1490 > 1491 if ((s->sh_flags & masks[m][0]) != masks[m][0] > 1492 || (s->sh_flags & masks[m][1]) > 1493 || s->sh_entsize != ~0UL > 1494 || strncmp(secstrings + s->sh_name, > 1495 ".init", 5) != 0) > 1496 continue; > 1497 s->sh_entsize = (get_offset(&mod->init_size, s) > 1498 | INIT_OFFSET_MASK); > 1499 DEBUGP("\t%s\n", secstrings + s->sh_name); > 1500 } > 1501 if (m == 0) > 1502 mod->init_text_size = mod->init_size; > 1503 } > > This loop has the effect of adding in mod->init_size the size of all > ELF sections whose name starts with .init. So in load_module(), after > the call to layout_sections(), mod->init_size is the size of .init.text > + init.data + others .init sections. > > Back in load_module(), it does: > > 1852 ptr = module_alloc(mod->init_size); > 1853 if (!ptr && mod->init_size) { > 1854 err = -ENOMEM; > 1855 goto free_core; > 1856 } > 1857 memset(ptr, 0, mod->init_size); > 1858 mod->module_init = ptr; > > So it allocates a specific memory area for init code and data, which is > pointed by mod->module_init. > > Then, if you look back in sys_init_module(), you see that the init > function of the module is called: > > 2125 if (mod->init != NULL) > 2126 ret = mod->init(); > > And if everything went right during the initialization, the following > line is executed: > > 2145 module_free(mod, mod->module_init); > > Which frees the init code and data. > > > > Sincerly, > > Thomas > -- > Thomas Petazzoni, Free Electrons > Free Embedded Linux Training Materials > on http://free-electrons.com/training > (More than 1500 pages!) > -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ