Thread (17 messages) flat view 17 messages, 7 authors, 2012-09-03

How to understand the macro __init?

From: Amarnath Revanna <hidden>
Date: 2012-08-16 16:08:38

Hi Wanny,

On Thu, Aug 16, 2012 at 8:43 PM, ?? [off-list ref] wrote:

2012/8/16 Amarnath Revanna [off-list ref]
quoted
Hi Vijay,

Is this a loadable kernel module or a built-in module?
If it is a loadable module, everything still remains in the memory
without being freed.

Functions and data defined with __init gets freed after their execution
only if these are part of built-in kernel modules.

In your case, if the module is a loadable one, you can still access the
print_k() from hello_exit() as its still residing in memory.

Regards,
-Amar
   Hi Amar

       Thank you  very much  for reply. I often write loadable modules,but
know little about
built-in modules,can you tell something about built-in modules? or,how i
can take a built-in
module into the kernel?

When I say built-in module, I meant to say the driver module is going to be
part of kernel itself, i.e. the module is compiled as part of kernel and
not explicitly loaded later.
The __init macros are applicable only for these modules that are
initialized as part of the kernel boot process.

At the end of the boot process, the kernel identifies all these memory
areas that are part of the init section that were required only during
initialization phase, and will continue to free these memory region to
re-use.

If you have a linux machine, you can do a dmesg to see this memory freeing
message that looks something something like:
" [1.011596] Freeing unused kernel memory: 664k freed "

This is exactly the freeing of all __init data sections from different
drivers/modules that were part of the kernel image. The freeing was done at
the end of the boot process, after they had  been used.

On the other hand, any other kernel module that you load using insmod or
modprobe comes after this stage, wherein the kernel was already booted, and
hence, no memory area of __init will ever be freed.

Regards,
-Amar




quoted
On Thu, Aug 16, 2012 at 5:23 PM, Vijay Chauhan [off-list ref]wrote:
quoted
Hi,

On Tue, Aug 14, 2012 at 9:34 AM, Mulyadi Santosa
[off-list ref] wrote:
quoted
Hi.. :)

On Tue, Aug 14, 2012 at 9:14 AM, ?? [off-list ref] wrote:
quoted
i use the __init for function print_k.
in my opinion  after the fisrt invoking the print_k in the hello_init.
the memory of print_k will be freed,and the second invoking will
not be executed.but the result of second invoking is executing .

why?
because you're still in module_init.... :)

right after modul init stage is done, _init marked function is thrown
away...


Even if we call  print_k() function inside hello_exit, it still works.
At that point __init hello_init execution is over. How its still
working?


Regards,
Vijay
quoted
--
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120816/4f7fa34c/attachment.html 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help