How to understand the macro __init?

Jim Cromie jim.cromie at gmail.com
Mon Sep 3 02:27:09 EDT 2012


On Thu, Aug 16, 2012 at 12:39 PM, Amarnath Revanna
<amarnath.revanna at gmail.com> wrote:
> Just want to add a little more for better understanding:
>
> When I spoke about .init section of the final kernel image, please note that
> this section is going to
> contain all the __init data (and functions) coming from _All_ the drivers
> and modules that were included
> as part of the kernel image. Hence, after initialization when we look at the
> print:
>
> " [1.011596] Freeing unused kernel memory: 664k freed "
>
> we see 664k bytes being freed.
>
> This is a significant amount of contiguous physical memory that we can see
> being released by the kernel.
>
> The same cannot be held true for a single loadable module which may be
> releasing just a few, virtually
> contiguous memory.

FWIW, theres no reason that the loadable module's __init section must
be in the same allocation as the module code itself.

The lifetime is certainly different, so "pre-fragmenting" it could
leave fewer holes overall.
I dont know if this is actually done (this way), but it seems
reasonably likely, given that the per-module sections exist.

$ readelf -a /lib/modules/3.6.0-rc3-cha-dyndbg-00008-g6e433ac/kernel/drivers/usb/serial/pl2303.ko
| grep init
  [ 4] .init.text        PROGBITS        00000000 00197c 000019 00  AX  0   0  1
  [ 5] .rel.init.text    REL             00000000 02a58c 000020 08     44   4  4
00001754  0000b702 R_386_PC32        00000000   __init_waitqueue_head
Relocation section '.rel.init.text' at offset 0x2a58c contains 4 entries:
...


>
> Regards,
> -Amar
>
>



More information about the Kernelnewbies mailing list