Re: __read_mostly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 7, 2010 at 11:46 PM, Mulyadi Santosa
<mulyadi.santosa@xxxxxxxxx> wrote:
> Hi Onkar....
>
> On Wed, Apr 7, 2010 at 17:56, Onkar Mahajan <kern.devel@xxxxxxxxx> wrote:
>> static struct hlist_head *inode_hashtable __read_mostly;
>>
>>
>> what is the use of  __read_mostly ?
>>
>> I did not find any detailed documentation for this
>> on GCC  website , Is it GCC optimization feature ?
>
> I failed to search the definition in kernel source or gcc docs.
> However, I am pretty confidence that this is somekind of definition to
> mark the related variable/structure/whatever and put them into the
> same memory segment.
>
> By doing so, the programmers are hoping that these data are grouped
> into the same cache line. And since they are mostly read only, cache
> won't be invalidated too much (maybe zero in some cases) if there is
> update into that cache line.
>

I think u are right too....

>From here is the definition:

arch/x86/include/asm/cache.h:
#define __read_mostly __attribute__((__section__(".data.read_mostly")))

and then the location is defined in the LDS linker script
(arch/x86/kernel/vmlinux.lds):

  CONSTRUCTORS
  /* rarely changed data like cpu maps */
  . = ALIGN((1 << 6)); *(.data.read_mostly)
  /* End of data section */
  _edata = .;
 } :data

which defined how vmlinux is created.

but ultimately it is a special keyword recognized by GCC.

(http://www.jauu.net/data/pdf/effective-c-with-gcc.pdf)
-- 
Regards,
Peter Teoh

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux