Need for SHIFT and MASK
Hi ,
While browsing through the code i came across macros like SHIFT , MASK , SIZE which are used in conversion from linear address to physical address
but this is the job of the processor (address translation) then why do we have these macros
can anyone please explain.
--
Thanks and Regards
Vivek Kutal
http://vivekkutal.blogspot.com
"Live as if you were to die tomorrow. Learn as if you were to live forever."
Hi Vivek,
Quoted 6 lines · Vivek Kutal
While browsing through the code i came across macros like SHIFT , MASK , SIZE which are used in conversion from linear address to physical address
but this is the job of the processor (address translation) then why do we have these macros
can anyone please explain.
This is usally table driven and someone has to set up this "Page Translation Tables". That's a job of the Linux kernel.
Just use sth. like Google to find out how it works or go to the library and read some books on OS design and virtual memory management.
Happy Studying!
Regards
Ingo Oeser
Hi Ingo,
Quoted 2 lines
This is usally table driven and someone has to set up this "Page Translation Tables". That's a job of the Linux kernel.
Yes setting up the page table entries is the job of the kernel , but for that we need to put the physical add. of the page and some bits (present,access writes etc) in the entry, once it is done the main job of translation which requires the masking and shifting is done by the processor whenever that page is referenced .
so why these macros are present in the kernel?
--
Thanks and Regards
Vivek Kutal
http://vivekkutal.blogspot.com
"Live as if you were to die tomorrow. Learn as if you were to live forever."
Quoted 4 lines · Vivek Kutal
Quoted 3 lines
This is usally table driven and someone has to set up this "Page Translation Tables". That's a job of the Linux kernel.
Quoted 8 lines
Yes setting up the page table entries is the job of the kernel , but for that we need to put the physical add. of the page and some bits (present,access writes etc) in the entry, once it is done the main job of translation which requires the masking and shifting is done by the processor whenever that page is referenced .
so why these macros are present in the kernel?
The setting of the Page Translation Tables are done by the Kernel, and processor actually do the traversing over those page table entries (PGD, PMD, PTE) to get the physical address of the page and then add the last 12-bits of virtual/linear address to get to the physical address .....
And as far as SHIFT, MASK, SIZE macros are concerned they are used in creating Page Translation Tables and also used to get the translation from linear to physical, SIZE macro used to get the current PAGE_SIZE, SHIFT can be used to get PFN etc in Kernel Code ....
(I might not able to explain, just b/c I think your question is not so clear to me !!!). You better study the stuffs and search in the kernel code for those SHIFT, MASK, SIZE macros and you will see where they are needed and used !!!!!
--
Fawad Lateef
Quoted 3 lines
And as far as SHIFT, MASK, SIZE macros are concerned they are used in creating Page Translation Tables and also used to get the translation from linear to physical
how are these macros used to create page translation tables (functions like pgd_alloc(), pmd_alloc() & pte_alloc() are used for this purpose)and the translation (virtual/linear to physical)is done by the processor and not by the OS.
--
Thanks and Regards
Vivek Kutal
http://vivekkutal.blogspot.com
"Live as if you were to die tomorrow. Learn as if you were to
live forever."
Quoted 10 lines · Vivek Kutal
Quoted 3 lines
And as far as SHIFT, MASK, SIZE macros are concerned they are used in creating Page Translation Tables and also used to get the translation from linear to physical
how are these macros used to create page translation tables (functions like
pgd_alloc(),pmd_alloc()&pte_alloc()are used for this purpose)and the translation (virtual/linear to physical)is done by the processor and not by the OS.
Actually I don't mean by mentioning "SHIFT, MASK, SZIE macros are used in creating Page Translation Table" that you will see them in pgd_alloc() etc but they are used in many memory initialization fucntions at the boot time ...... and for example look
http://lxr.linux.no/source/arch/i386/mm/init.c#L207 !!!!!! These Macros are might be there for the compatibility reasons tooo as you can see the PAGE_SIZE can be changed but if you use PAGE_SIZE in every module/place you won't be concerned about the actual size of the page at that moment or in Architecture ...........
--
Fawad Lateef
Quoted 11 lines · Vivek Kutal
Hi Ingo,
Quoted 2 lines
This is usally table driven and someone has to set up this "Page Translation Tables". That's a job of the Linux kernel.
Yes setting up the page table entries is the job of the kernel , but for that we need to put the physical add. of the page and some bits (present,access writes etc) in the entry, once it is done the main job of translation which requires the masking and shifting is done by the processor whenever that page is referenced .
so why these macros are present in the kernel?
They are needed. You can remome them.
NB: joke tags are invisible, but they are there.
--
vda