Re: How to convert virtual address to physical address and revers e?

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

On Wed, 30 Mar 2005 22:20:02 +0530, Gaurav Dhiman <gaurav4lkg@xxxxxxxxx> wrote:
> On Wed, 30 Mar 2005 08:09:25 +0530, Raj <rajagopalan.duraisamy@xxxxxxxxx> wrote:
> > The Kernel maps the physical address starting from PAGE_OFFSET in
> > Virtual Address Space that is why we subtract PAGE_OFFSET to get the
> > physical address from VA. According to my understanding this will be
> > valid only in Kernel address space and not in user address space.
> >
> > Again as far as I know, to access the virtual address for a given
> > physical address, you need to access the rmap structure in the struct
> > page. This how you can do it,
> >
> > physical address >> PAGE_SHIFT , this gives you the pfn
> >
> > node_mem_map + pfn gives the struct page pointer value.
> can you explain  bit more about node_mem_map and mem_map ? What does
> these two represent ?

The memory architecture in LINUX mm follows the NUMA architecture and
hence is organized into nodes. Each node is represented by a pg_data_t
structure. For a NUMA architecture there is a list of pg_data_t called
For UMA there is only one pg_data_t structure maintained in a variable
called contig_page_data.

Each node contains a number of blocks of memory called Zones. Each
node also contains an array of struct page called node_mem_map.

typedef struct pglist_data {
         struct zone node_zones[MAX_NR_ZONES];
         struct zonelist node_zonelists[GFP_ZONETYPES];
         int nr_zones;
         struct page *node_mem_map;
         struct bootmem_data *bdata;
         unsigned long node_start_pfn;
         unsigned long node_present_pages; /* total number of physical pages */
         unsigned long node_spanned_pages; /* total size of physical page
                                              range, including holes */
         int node_id;
         struct pglist_data *pgdat_next;
         wait_queue_head_t       kswapd_wait;
         struct task_struct *kswapd;
} pg_data_t;

The node_mem_map contains the first page address that the node starts
from. For UMA I think it is the first page after 8MB ( I am not sure
of this though) .

Thus node_mem_map is just an array of struct page of the nodes pages.
The mem_map is the global memory map array of struct page. The mem_map
is used to convert from pfn to struct page* .
For UMA architecture,
mem_map + (physical address >> PAGE_SHIFT) gives the struct page*
which is the physical memory's representation in the Kernel.

> > Acess the rmap structure in the page structure. This is a list of all
> > the virtual addresses where this page is mapped.
> what does rmap represents ?

The Page tables represent the mapping from the virtual address to the
phsical address. The rmap is a reverse mapping from physical address
to virtual address.

> Please explain bit more, how can we convert the physical address to
> the user virtual address ? For converting from virtual to physical, we
> need to use process page tables.
> I know that page tables are specific to processes, wanted to know is
> there any data structure either specific to process ot global, which
> can convert the physical address to virtual address of any process ?

I am sorry. Even I am reading through the code so that is all the
information I have for now. I think the Mel Gorman's Understanding the
LINUX VM Manager might be of more help to you.

> Gaurav

Kernelnewbies: Help each other learn about the Linux kernel.

[Newbies FAQ]     [Kernel Development Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Networking]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]

Add to Google Powered by Linux