good explanation of __read_mostly, __init, __exit macros,
From: Aft nix <hidden>
Date: 2012-07-16 18:49:15
On Tue, Jul 17, 2012 at 12:39 AM, Mulyadi Santosa [off-list ref] wrote:
Hi.. On Mon, Jul 16, 2012 at 6:22 PM, Aft nix [off-list ref] wrote:quoted
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.
Hi Santosa, This special section, "data..read_mostly" , is it maintained by kernel? then Linker has to know this information. How that is done? 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? Thing is, i'm getting the idea what these macros mean, but not understanding the mechanisms behind them. cheers.
-- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
-- -aft