Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Mapping Addresses to a struct page</strong></p> <p>There is a requirement for Linux to have a fast method of mapping virtual addresses to physical addresses and for mapping struct pages to their physical address. Linux achieves this by knowing where, in both virtual and physical memory, the global mem_map array is because the global array has pointers to all struct pages representing physical memory in the system. All architectures achieve this with very similar mechanisms, but, for illustration purposes, we will only examine the x86 carefully. </p> <p>Mapping Physical to Virtual Kernel Addresses</p> <p>any virtual address can be translated to the physical address by simply subtracting PAGE_OFFSET, which is essentially what the function virt_to_phys() with the macro __pa() does:</p> <pre><code>/* from &lt;asm-i386/page.h&gt; */ 132 #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) /* from &lt;asm-i386/io.h&gt; */ 76 static inline unsigned long virt_to_phys(volatile void * address) 77 { 78 return __pa(address); 79 } </code></pre> <p>Obviously, the reverse operation involves simply adding PAGE_OFFSET, which is carried out by the function phys_to_virt() with the macro __va(). Next we see how this helps the mapping of struct pages to physical addresses.</p> <p><strong>There is one exception where virt_to_phys() cannot be used to convert virtual addresses to physical ones.</strong> Specifically, on the PPC and <strong>ARM architectures</strong>, virt_to_phys() cannot be used to convert addresses that have been returned by the function consistent_alloc(). consistent_alloc() is used on PPC and ARM architectures to return memory from non-cached for use with DMA.</p> <p><a href="http://www.makelinux.net/ldd3/chp-15-sect-1"><strong>What are all the kinds of memory zones in the kernel?</strong></a> &lt;---see here</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload