powerpc/powernv: Increase memory block size to 1GB on radix
PATCH 1/1 powerpc/powernv: Increase memory block size to 1GB on radix
From: Anton Blanchard <[email protected]>
Memory hot unplug on PowerNV radix hosts is broken. Our memory block size is 256MB but since we map the linear region with very large pages, each pte we tear down maps 1GB.
A hot unplug of one 256MB memory block results in 768MB of memory getting unintentionally unmapped. At this point we are likely to oops.
Fix this by increasing our memory block size to 1GB on PowerNV radix hosts.
--- arch/powerpc/platforms/powernv/setup.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/setup.c +9 -1
@@ -272,7 +272,15 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE static unsigned long pnv_memory_block_size (void ) { -return 256UL *1024 *1024 ; +/* +* We map the kernel linear region with 1GB large pages on radix. For +* memory hot unplug to work our memory block size must be at least +* this size. +*/ +if (radix_enabled ()) +return 1UL *1024 *1024 *1024 ; +else +return 256UL *1024 *1024 ; }#endif
Signature · 1 line
2.11.0
Quoted 28 lines · Anton Blanchard
From: Anton Blanchard <[email protected]>
Memory hot unplug on PowerNV radix hosts is broken. Our memory block size is 256MB but since we map the linear region with very large pages, each pte we tear down maps 1GB.
A hot unplug of one 256MB memory block results in 768MB of memory getting unintentionally unmapped. At this point we are likely to oops.
Fix this by increasing our memory block size to 1GB on PowerNV radix hosts.
Signed-off-by Anton Blanchard <[email protected]>--- arch/powerpc/platforms/powernv/setup.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)arch/powerpc/platforms/powernv/setup.c +2
-1@@ -272,7 +272,15 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE static unsigned long pnv_memory_block_size (void ) { -return 256UL *1024 *1024 ; +/* +* We map the kernel linear region with 1GB large pages on radix. For
arch/powerpc/platforms/powernv/setup.c static void pnv_kexec_cpu_down(int crash_shutdown, int secondary) · line 286
Quoted 10 lines
arch/powerpc/platforms/powernv/setup.c +7
-0+* memory hot unplug to work our memory block size must be at least +* this size. +*/ +if (radix_enabled ()) +return 1UL *1024 *1024 *1024 ; +else + return 256UL * 1024 * 1024; }#endif
There is a similar issue being worked on w.r.t pseries.
https://lkml.kernel.org/r/[email protected]
The question is should we map these regions ? ie, we need to tell the kernel memory region that we would like to hot unplug later so that we avoid doing kernel allocations from that. If we do that, then we can possibly map them via 2M size ?
-aneesh
Hi,
Quoted 8 lines
There is a similar issue being worked on w.r.t pseries.
https://lkml.kernel.org/r/[email protected]
The question is should we map these regions ? ie, we need to tell the kernel memory region that we would like to hot unplug later so that we avoid doing kernel allocations from that. If we do that, then we can possibly map them via 2M size ?
But all of memory on PowerNV should be able to be hot unplugged, so there are two options as I see it - either increase the memory block size, or map everything with 2MB pages.
Anton
Quoted 6 lines · Anton Blanchard
Hi,
Quoted 4 lines
There is a similar issue being worked on w.r.t pseries.
Quoted 8 lines
Quoted 4 lines
The question is should we map these regions ? ie, we need to tell the kernel memory region that we would like to hot unplug later so that we avoid doing kernel allocations from that. If we do that, then we can possibly map them via 2M size ?
But all of memory on PowerNV should be able to be hot unplugged, so there are two options as I see it - either increase the memory block size, or map everything with 2MB pages.
Or be smarter and map with 1G when blocks of 1G are available and break down to 2M where necessary, it shouldn't be too hard.
Cheers,
Ben.
Quoted 3 lines · Anton Blanchard
But all of memory on PowerNV should be able to be hot unplugged, so there are two options as I see it - either increase the memory block size, or map everything with 2MB pages.
I may be misunderstanding this, but what if we did something like x86 does? When trying to unplug a region smaller than the mapping, they fill that part of the pagetable with 0xFD instead of freeing the whole thing. Once the whole thing is 0xFD, free it.
See arch/x86/mm/init_64.c:remove_{pte,pmd,pud}_table()
---%<---
memset((void *)addr, PAGE_INUSE, next - addr);
page_addr = page_address(pte_page(*pte));
if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) {
...
pte_clear(&init_mm, addr, pte);
...
}---%<---
Signature · 1 line
Reza Arbab
Hi Reza,
Quoted 16 lines
I may be misunderstanding this, but what if we did something like x86 does? When trying to unplug a region smaller than the mapping, they fill that part of the pagetable with
0xFDinstead of freeing the whole thing. Once the whole thing is0xFD, free it.See arch/x86/mm/init_64.c:remove_{pte,pmd,pud}_table()
---%<---
memset((void *)addr, PAGE_INUSE, next - addr); page_addr = page_address(pte_page(*pte)); if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) { ... pte_clear(&init_mm, addr, pte); ... }
Quoted 1 line
---%<---
But you only have 1GB ptes at this point, you'd need to start instantiating a new level in the tree, and populate 2MB ptes.
That is what Ben is suggesting. I'm happy to go any way (fix hotplug to handle this, or increase the memblock size on PowerNV to 1GB), I just need a solution.
Anton
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 4 lines · Anton Blanchard
Hi,
Quoted 2 lines
There is a similar issue being worked on w.r.t pseries.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
https://lkml.kernel.org/r/[email protected]
The question is should we map these regions ? ie, we need to tell the kernel memory region that we would like to hot unplug later so that we avoid doing kernel allocations from that. If we do that, then we can possibly map them via 2M size ?
But all of memory on PowerNV should be able to be hot unplugged, so
For this ideally we need movable mappings for the regions we intend to hot-unplug - no? Otherwise, there is no guarantee that hot-unplug will work
Quoted 6 lines
Quoted 2 lines
there are two options as I see it - either increase the memory block size, or map everything with 2MB pages.
Or be smarter and map with 1G when blocks of 1G are available and break down to 2M where necessary, it shouldn't be too hard.
strict_rwx patches added helpers to do this
Balbir Singh.
We should do the 1G block size as a fix, and backport it, and then make the hot unplug code smarter.
cheers
Quoted 30 lines · Anton Blanchard
Hi Reza,
Quoted 17 lines
I may be misunderstanding this, but what if we did something like x86
does? When trying to unplug a region smaller than the mapping, they fill that part of the pagetable with
0xFDinstead of freeing the whole thing. Once the whole thing is0xFD, free it.See arch/x86/mm/init_64.c:remove_{pte,pmd,pud}_table()
---%<---
memset((void *)addr, PAGE_INUSE, next - addr); page_addr = page_address(pte_page(*pte)); if (!memchr_inv(page_addr, PAGE_INUSE, PAGE_SIZE)) { ... pte_clear(&init_mm, addr, pte); ... }Quoted 1 line
---%<---
But you only have 1GB ptes at this point, you'd need to start instantiating a new level in the tree, and populate 2MB ptes.
That is what Ben is suggesting. I'm happy to go any way (fix hotplug to handle this, or increase the memblock size on PowerNV to 1GB), I just
need a solution.Anton
Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Michael Ellerman
AppliedQuoted 6 lines · Anton Blanchard
From: Anton Blanchard <[email protected]>
Memory hot unplug on PowerNV radix hosts is broken. Our memory block size is 256MB but since we map the linear region with very large pages, each pte we tear down maps 1GB.
Quoted 7 lines
A hot unplug of one 256MB memory block results in 768MB of memory getting unintentionally unmapped. At this point we are likely to oops.
Fix this by increasing our memory block size to 1GB on PowerNV radix hosts.
Signed-off-by Anton Blanchard <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/53ecde0b9126ff140abe3aefd7f0ec
cheers