Skip to contentSkip to conversation

free_memmap() and sparsemem

PATCH Catalin Marinas 2 participants 3 messages Sep 9, 2009 – Sep 19, 2009 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

Hi Russell,

I haven't followed the full thread on omap and memory holes but I got an issue on RealView PBX with sparsemem enabled (patches not pushed yet for mainline). Basically I'm using this configuration:

256MB @ 0x00000000 -> PAGE_OFFSET
512MB @ 0x20000000 -> PAGE_OFFSET + 0x10000000
256MB @ 0x80000000 -> PAGE_OFFSET + 0x20000000

I could only use two banks (the second at 0x70000000) but I need the first 256MB for DMA (since Linux only accepts DMA zone to be at the bottom). The phys_to_virt/virt_to_phys macros were modified to provide a contiguous translation to virtual addresses.

Anyway, the free_memmap() called from free_unused_memmap_node() shouldn't actually do much with sparsemem because the way the page arrays are structured. In theory, start_pg and end_pg should be the same but because the start_pfn passed to this function doesn't belong to any node, it gets some random values for start_pg. The patch below solved the problem for me:

Fix the start_pg value in free_memmap()

From: Catalin Marinas <[email protected]>

If sparsemem is enabled, the start_pfn passed to the free_memmap() function corresponds to an area of memory not known to the kernel and pfn_to_page returns a wrong value. The (start_pfn - 1), however, is known to the kernel.

---
 arch/arm/mm/init.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mm/init.c +1 -1
index 82c4b42..b0423b7 100644
@@ -419,7 +419,7 @@ free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
 	/*
 	 * Convert start_pfn/end_pfn to a struct page pointer.
 	 */
-	start_pg = pfn_to_page(start_pfn);
+	start_pg = pfn_to_page(start_pfn - 1) + 1;
 	end_pg = pfn_to_page(end_pfn);
 
 	/*
Signature · 1 line
Catalin
#1 lore raw
Quoted 4 lines · Catalin Marinas

I haven't followed the full thread on omap and memory holes but I got an issue on RealView PBX with sparsemem enabled (patches not pushed yet for mainline). Basically I'm using this configuration:

Quoted 8 lines

256MB @ 0x00000000 -> PAGE_OFFSET
512MB @ 0x20000000 -> PAGE_OFFSET + 0x10000000
256MB @ 0x80000000 -> PAGE_OFFSET + 0x20000000

I could only use two banks (the second at 0x70000000) but I need the first 256MB for DMA (since Linux only accepts DMA zone to be at the bottom). The phys_to_virt/virt_to_phys macros were modified to provide a contiguous translation to virtual addresses.

I normally say to keep these translation macros simple, so that conversions are as fast as possible.

There's also no point using sparsemem if you're going to make the virtual memory space contiguous - it just buys you complexity with no advantage. Sparsemem is about a sparse virtual space, not a sparse physical space.

So at the end of it, your patch has nothing to do with sparsemem, but is a problem with non-linear v:p translations.

New patch description to reflect those comments please.

#2 lore raw
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Catalin Marinas

I haven't followed the full thread on omap and memory holes but I got an issue on RealView PBX with sparsemem enabled (patches not pushed yet for mainline). Basically I'm using this configuration:

256MB @ 0x00000000 -> PAGE_OFFSET
512MB @ 0x20000000 -> PAGE_OFFSET + 0x10000000
256MB @ 0x80000000 -> PAGE_OFFSET + 0x20000000

Quoted 7 lines
Quoted 4 lines

I could only use two banks (the second at 0x70000000) but I need the first 256MB for DMA (since Linux only accepts DMA zone to be at the bottom). The phys_to_virt/virt_to_phys macros were modified to provide a contiguous translation to virtual addresses.

I normally say to keep these translation macros simple, so that conversions are as fast as possible.

I'd like to keep them simple as well but the physical blocks are too far apart.

Quoted 3 lines

There's also no point using sparsemem if you're going to make the virtual memory space contiguous - it just buys you complexity with no advantage. Sparsemem is about a sparse virtual space, not a sparse physical space.

My reason for sparsemem is a smaller mem_map table (I don't want to keep page structures for 1GB between 0x40000000 and 0x80000000). Do you have a better suggestion here?

Quoted 2 lines

So at the end of it, your patch has nothing to do with sparsemem, but is a problem with non-linear v:p translations.

I would say it has to do with non-contiguous physical map, nothing related to the virtual translation here as the code in question only deals with pfn. The problem appears when sparesemem is enabled because the mem_map is no longer a contiguous array (could be for both sparsemem and discontigmem but I only tried the former).

Signature · 1 line
Catalin