good explanation of __read_mostly, __init, __exit macros,

Arif Hossain aftnix at gmail.com
Tue Jul 17 07:07:33 EDT 2012


On Tue, 2012-07-17 at 02:03 +0700, Mulyadi Santosa wrote:
> Hi :)
> 
> On Tue, Jul 17, 2012 at 1:49 AM, Aft nix <aftnix at gmail.com> wrote:
> > This special section, "data..read_mostly" , is it maintained by
> > kernel?
> 
> by maintained, you mean allocated? then yes....
> 
> > then Linker has to know this information. How that is done?
> 
> it is provided by the linker script.... the fastest I can find is in
> directory include/asm-generic/vmlinux.lds.h. This file is not final
> linker script, it's kinda a "template" that will be further modified
> by Kbuild (I guess)
> 
> > I mean lets say a.c is compiled into a.o. a.o already has the offsets
> > for its data. Linker resolves the final address. So how the linker is
> > invoked
> > in a way so that this data flagged with __read__mostly will end up in
> > the special section?
> 
> it's actually the same like putting your initialized variable in .data
> section, your code in .text and so on. I just get the big picture that
> it is done by creating section in the object file. By section, I think
> it's simply done by creating a mark to denote the section.
> 
> please kindly study  ELF documentation for further info
> 
> > Thing is, i'm getting the idea what these macros mean, but not
> > understanding the mechanisms behind them.
> 
> the whole chain is complex actually, but try to get the simple view
> first. it's a grouping, read mostly data into a section/group in a
> file (in this case, kernel image), kernel loaded.....kernel arrange
> itself..put appropriate section into related addresses....done
> 

Thanks for the detailed explanation. I've got the idea behind
__read_mostly. I've found a interesting document "Dead code elimination
" which i guess relates to "__init" and "__exit". 

Here is the link :
elinux.org/images/2/2d/ELC2010-gc-sections_Denys_Vlasenko.pdf

I'm going to study this post if any question arises.

cheers.






More information about the Kernelnewbies mailing list