Re: Merging Nonlinear and Numa style memory hotplug

Dave Hansen
2004-06-24T22:40:29Z

On Thu, 2004-06-24 at 15:19, Yasunori Goto wrote:
> BTW, I have a question about nonlinear patch.
> It is about difference between phys_section[] and mem_section[]
> I suppose that phys_section[] looks like no-meaning now.
> If it isn't necessary, __va() and __pa() translation can be more simple.
> What is the purpose of phys_section[]. Is it for ppc64?

This is the fun (read: confusing) part of nonlinear.

The mem_section[] array is where the pointer to the mem_map for the
section is stored, obviously. It's indexed virtually, so that something
at a virtual address is in section number (address >> SECTION_SHIFT).
So, that makes it easy to go from a virtual address to a 'struct page'
inside of the mem_map[].

But, given a physical address (or a pfn for that matter), you sometimes
also need to get to a 'struct page'. It is for that reason that we have
the phys_section[] array. Each entry in the phys_section[] points back
to a mem_section[], which then contains the mem_map[].

pfn_to_page(unsigned long pfn)
{
return
&mem_section[phys_section[pfn_to_section(pfn)]].mem_map[section_offset_pfn(pfn)];
}

pfn_to_section(pfn) does a (pfn >> (SECTION_SHIFT - PAGE_SHIFT)), then
uses that section number to index into the phys_section[] array, which
gives an index into the mem_section[] array, from which you can get the
'struct page'.

-- Dave