Re: good explanation of __read_mostly, __init, __exit macros,

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

 



One instance where this 'linker magic' is employed is in the treatment of the variable jiffies. jiffies has been traditionally an 'unsigned long'. Therefore, it occupies 32 bits on 32 bit arch. and 64 bits on 64-bit arch. However, having jiffies just 32-bit long can result in overflows pretty quickly (few days) if the HZ value is large. So, nowadays (2.6 kernel), we have one more variable - jiffies_64, which is 64 bit long. To maintain code compatibility, this 'jiffies_64' is overlayed on the original 'jiffies' variable, so that both variables begin at the same address. Older code can continue to operate as is, while new code can make use of the 'jiffies_64' variable, as and when required.

Please refer Chapter:11 (Timers and Time Management), Topic: Internal Representation of Jiffies
Linux Kernel Development, 3rd Edition - Robert Love to read about this.

Best Regards
Gaurav

On Mon, Jul 16, 2012 at 6:10 PM, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
On Mon, 16 Jul 2012, Filipe Rinaldi wrote:

> On 16 July 2012 12:22, Aft nix <aftnix@xxxxxxxxx> 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.
> >
> > Additonal question : I have heard about various "linker magic"
> > employed in kernel development. Any information
> > regarding this will be wonderful.
> >
> > cheers
> >
> > --
> > -aft
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies@xxxxxxxxxxxxxxxxx
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
> Hi Aft,
>
> These macros are used to assign a function or initialised variable
> content to a specific section in memory. If you search for the linker
> script of any architecture (*.lds.S files), you will see that these
> variables and functions are placed in specific sections with names
> like "__init_begin" and "__init_end". After the initialisation, Linux
> can re-use for example the "init" memory.

  that's what's happening when you see that boot-time message:

"Freeing unused memory ..."

or whatever it is, something to that effect.

rday

--

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



--
Gaurav Jain
Associate Software Engineer
VxVM Escalations Team, SAMG
Symantec Software India Pvt. Ltd.



_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[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