good explanation of __read_mostly, __init, __exit macros,

Mulyadi Santosa mulyadi.santosa at gmail.com
Mon Jul 16 14:39:12 EDT 2012


Hi..

On Mon, Jul 16, 2012 at 6:22 PM, Aft nix <aftnix at gmail.com> wrote:
> Hi,
>
> The macro expansion of __read_mostly :
>
> #define __read_mostly __attribute__((__section__(".data..read_mostly"))
>
> This one is from cache.h
>
> __init:
> #define __init          __section(.init.text) __cold notrace
>
> from init.h
>
> __exit:
>
> #define __exit          __section(.exit.text) __exitused __cold notrace
>
> After searching through net i have not found any good explanation of
> what is happening there.

like others had said, it means, the variables marked as read mostly
are grouped into special section in kernel memory layout, named
read_mostly. It's a subsection inside "data", which is I believe
belong to initialized variable.

By grouping this into single special region, it is hoped that you
reduce (if possible none happen) cache invalidation. Such thing happen
when bits in a cache line are updated. In such occasion, the whole
cache line must be updated by re-fetching the related memory address.

Thus, if all these bits are read only, once fetched, it will stays in
cache line as long as possible.

PS: there is no guarantee that this grouping will effectively
works...that's why you need to align it to the size of cache line.

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

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



More information about the Kernelnewbies mailing list