mm: Memory offlining + page isolation cleanups
Subsystems (4)
cover mm: Memory offlining + page isolation cleanups
Two cleanups that popped up while working on (and discussing) virtio-mem:
https://lkml.org/lkml/2019/9/19/463
Tested with DIMMs on x86.
David Hildenbrand (2):
mm/page_alloc.c: Don't set pages PageReserved() when offlining mm/page_isolation.c: Convert SKIP_HWPOISON to MEMORY_OFFLINE
include/linux/page-isolation.h | 4 ++-- mm/memory_hotplug.c | 8 +++++--- mm/page_alloc.c | 9 +++------ mm/page_isolation.c | 12 ++++++------ 4 files changed, 16 insertions(+), 17 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/2 mm/page_alloc.c: Don't set pages PageReserved() when offlining
We call __offline_isolated_pages() from __offline_pages() after all pages were isolated and are either free (PageBuddy()) or PageHWPoison. Nothing can stop us from offlining memory at this point.
In __offline_isolated_pages() we first set all affected memory sections offline (offline_mem_sections(pfn, end_pfn)), to mark the memmap as invalid (pfn_to_online_page() will no longer succeed), and then walk over all pages to pull the free pages from the free lists (to the isolated free lists, to be precise).
Note that re-onlining a memory block will result in the whole memmap getting reinitialized, overwriting any old state. We already poision the memmap when offlining is complete to find any access to stale/uninitialized memmaps.
So, setting the pages PageReserved() is not helpful. The memap is marked offline and all pageblocks are isolated. As soon as offline, the memmap is stale either way.
This looks like a leftover from ancient times where we initialized the memmap when adding memory and not when onlining it (the pages were set PageReserved so re-onling would work as expected).
--- mm/page_alloc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
mm/page_alloc.c +1 -4
@@ -8667,7 +8667,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) {struct page *page;struct zone *zone; -unsigned int order, i; +unsigned int order;unsigned long pfn;unsigned long flags;unsigned long offlined_pages =0 ;
@@ -8695,7 +8695,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)*/ if (unlikely (!PageBuddy (page) &&PageHWPoison (page))) { pfn++; -SetPageReserved (page); offlined_pages++;continue ; }
@@ -8709,8 +8708,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) pfn, 1 << order, end_pfn);#endif del_page_from_free_area (page, &zone->free_area[order]); -for (i =0 ; i < (1 << order); i++) -SetPageReserved ((page+i)); pfn += (1 << order); }spin_unlock_irqrestore (&zone->lock, flags);
Signature · 1 line
2.21.0
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 23 lines · David Hildenbrand
We call
__offline_isolated_pages()from__offline_pages()after all pages were isolated and are either free (PageBuddy()) or PageHWPoison. Nothing can stop us from offlining memory at this point.In
__offline_isolated_pages()we first set all affected memory sections offline (offline_mem_sections(pfn, end_pfn)), to mark the memmap as invalid (pfn_to_online_page()will no longer succeed), and then walk over all pages to pull the free pages from the free lists (to the isolated free lists, to be precise).Note that re-onlining a memory block will result in the whole memmap getting reinitialized, overwriting any old state. We already poision the memmap when offlining is complete to find any access to stale/uninitialized memmaps.
So, setting the pages
PageReserved()is not helpful. The memap is marked offline and all pageblocks are isolated. As soon as offline, the memmap is stale either way.This looks like a leftover from ancient times where we initialized the memmap when adding memory and not when onlining it (the pages were set PageReserved so re-onling would work as expected).
Quoted 12 lines
Cc Andrew Morton <[email protected]>Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Oscar Salvador <[email protected]>Cc Mel Gorman <[email protected]>Cc Mike Rapoport <[email protected]>Cc Dan Williams <[email protected]>Cc Wei Yang <[email protected]>Cc Alexander Duyck <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Pavel Tatashin <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
We still set PageReserved before onlining pages and that one should be good to go as well (memmap_init_zone).
Thanks!
There is a comment above offline_isolated_pages_cb that should be removed as well.
Quoted 37 lines
--- mm/page_alloc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)mm/page_alloc.c +1
-4@@ -8667,7 +8667,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) {struct page *page;struct zone *zone; -unsigned int order, i; +unsigned int order;unsigned long pfn;unsigned long flags;unsigned long offlined_pages =0 ;@@ -8695,7 +8695,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)*/ if (unlikely (!PageBuddy (page) &&PageHWPoison (page))) { pfn++; -SetPageReserved (page); offlined_pages++;continue ; }@@ -8709,8 +8708,6 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) pfn, 1 << order, end_pfn);#endif del_page_from_free_area (page, &zone->free_area[order]); -for (i =0 ; i < (1 << order); i++) -SetPageReserved ((page+i)); pfn += (1 << order); }spin_unlock_irqrestore (&zone->lock, flags);Signature · 1 line
2.21.0
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 37 lines · Michal Hocko
Quoted 23 lines · David Hildenbrand
We call
__offline_isolated_pages()from__offline_pages()after all pages were isolated and are either free (PageBuddy()) or PageHWPoison. Nothing can stop us from offlining memory at this point.In
__offline_isolated_pages()we first set all affected memory sections offline (offline_mem_sections(pfn, end_pfn)), to mark the memmap as invalid (pfn_to_online_page()will no longer succeed), and then walk over all pages to pull the free pages from the free lists (to the isolated free lists, to be precise).Note that re-onlining a memory block will result in the whole memmap getting reinitialized, overwriting any old state. We already poision the memmap when offlining is complete to find any access to stale/uninitialized memmaps.
So, setting the pages
PageReserved()is not helpful. The memap is marked offline and all pageblocks are isolated. As soon as offline, the memmap is stale either way.This looks like a leftover from ancient times where we initialized the memmap when adding memory and not when onlining it (the pages were set PageReserved so re-onling would work as expected).
Quoted 12 lines
Cc Andrew Morton <[email protected]>Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Oscar Salvador <[email protected]>Cc Mel Gorman <[email protected]>Cc Mike Rapoport <[email protected]>Cc Dan Williams <[email protected]>Cc Wei Yang <[email protected]>Cc Alexander Duyck <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Pavel Tatashin <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Quoted 5 lines
Acked-by Michal Hocko <[email protected]>We still set PageReserved before onlining pages and that one should be good to go as well (
memmap_init_zone).
Thanks!
memmap_init_zone() is called when onlining memory. There, set all pages to reserved right now (on context == MEMMAP_HOTPLUG). We clear PG_reserved when onlining a page to the buddy (e.g., generic_online_page). If we would online a memory block with holes, we would want to keep all such pages (!pfn_valid()) set to reserved. Also, there might be other side effects.
So it might not be that easy to remove. A cleanup that I have on my list is to disallow offlining memory blocks with holes. This implies that we will never online memory blocks with holes. This allows for some cleanups in the onlining/offlining code. For example, it would allow to get rid of this PG_reserved initialization.
I don't think that we have to support offlining memory blocks with holes. This can only be bootmem (never hotplugged memory), where the chance for this to work is in my opinion already not too good.
What's your opinion on this?
Quoted 3 lines
There is a comment above
offline_isolated_pages_cbthat should be removed as well.
Right, I'll convert that comment
"Mark all sections offline and remove all free pages from the buddy."
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 1 line · David Hildenbrand
On 21.10.19 16:43, Michal Hocko wrote:
[...]
Quoted 9 lines
Quoted 3 lines
We still set PageReserved before onlining pages and that one should be good to go as well (
memmap_init_zone).
Thanks!
memmap_init_zone()is called when onlining memory. There, set all pages to reserved right now (on context ==MEMMAP_HOTPLUG). We clearPG_reservedwhen onlining a page to the buddy (e.g.,generic_online_page). If we would online a memory block with holes, we would want to keep all such pages (!pfn_valid()) set to reserved. Also, there might be other side effects.
Isn't it sufficient to have those pages in a poisoned state? They are not onlined so their state is basically undefined anyway. I do not see how PageReserved makes this any better.
Also is the hole inside a hotplugable memory something we really have to care about. Has anybody actually seen a platform to require that?
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 13 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 21.10.19 16:43, Michal Hocko wrote:
[...]
Quoted 9 lines
Quoted 3 lines
We still set PageReserved before onlining pages and that one should be good to go as well (
memmap_init_zone).
Thanks!
memmap_init_zone()is called when onlining memory. There, set all pages to reserved right now (on context ==MEMMAP_HOTPLUG). We clearPG_reservedwhen onlining a page to the buddy (e.g.,generic_online_page). If we would online a memory block with holes, we would want to keep all such pages (!pfn_valid()) set to reserved. Also, there might be other side effects.
Quoted 3 lines
Isn't it sufficient to have those pages in a poisoned state? They are not onlined so their state is basically undefined anyway. I do not see how PageReserved makes this any better.
It is what people have been using for a long time. Memory hole -> PG_reserved. The memmap is valid, but people want to tell "this here is crap, don't look at it".
Quoted 3 lines
Also is the hole inside a hotplugable memory something we really have to care about. Has anybody actually seen a platform to require that?
That's what I was asking. I can see "support" for this was added basically right from the beginning. I'd say we rip that out and cleanup/simplify. I am not aware of a platform that requires this. Especially, memory holes on DIMMs (detected during boot) seem like an unlikely thing.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 14 lines · David Hildenbrand
Quoted 13 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 21.10.19 16:43, Michal Hocko wrote:
[...]
Quoted 9 lines
Quoted 3 lines
We still set PageReserved before onlining pages and that one should be good to go as well (
memmap_init_zone).
Thanks!
memmap_init_zone()is called when onlining memory. There, set all pages to reserved right now (on context ==MEMMAP_HOTPLUG). We clearPG_reservedwhen onlining a page to the buddy (e.g.,generic_online_page). If we would online a memory block with holes, we would want to keep all such pages (!pfn_valid()) set to reserved. Also, there might be other side effects.
Quoted 7 lines
Quoted 3 lines
Isn't it sufficient to have those pages in a poisoned state? They are not onlined so their state is basically undefined anyway. I do not see how PageReserved makes this any better.
It is what people have been using for a long time. Memory hole ->
PG_reserved. The memmap is valid, but people want to tell "this here is crap, don't look at it".
The page is poisoned, right? If yes then setting the reserved bit doesn't make any sense.
Quoted 7 lines
Quoted 2 lines
Also is the hole inside a hotplugable memory something we really have to care about. Has anybody actually seen a platform to require that?
That's what I was asking. I can see "support" for this was added basically right from the beginning. I'd say we rip that out and cleanup/simplify. I am not aware of a platform that requires this. Especially, memory holes on DIMMs (detected during boot) seem like an unlikely thing.
The thing is that the hotplug development shows ad-hoc decisions throughout the code. It is even worse that it is hard to guess whether some hludges are a result of a careful design or ad-hoc trial and failure approach on setups that never were production. Building on top of that be preserving hacks is not going to improve the situation. So I am perfectly fine to focus on making the most straightforward setups work reliably. Even when there is a risk of breaking some odd setups. We can fix them up later but we would have at least a specific example and document it.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 19 lines · Michal Hocko
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 21.10.19 16:43, Michal Hocko wrote:
[...]
Quoted 9 lines
Quoted 3 lines
We still set PageReserved before onlining pages and that one should be good to go as well (
memmap_init_zone).
Thanks!
memmap_init_zone()is called when onlining memory. There, set all pages to reserved right now (on context ==MEMMAP_HOTPLUG). We clearPG_reservedwhen onlining a page to the buddy (e.g.,generic_online_page). If we would online a memory block with holes, we would want to keep all such pages (!pfn_valid()) set to reserved. Also, there might be other side effects.Isn't it sufficient to have those pages in a poisoned state? They are not onlined so their state is basically undefined anyway. I do not see how PageReserved makes this any better.
Quoted 6 lines
Quoted 3 lines
It is what people have been using for a long time. Memory hole ->
PG_reserved. The memmap is valid, but people want to tell "this here is crap, don't look at it".The page is poisoned, right? If yes then setting the reserved bit doesn't make any sense.
No it's not poisoned AFAIK. It should be initialized - and I remember that PG_reserved on memory holes is relevant to detect MMIO pages. (e.g., looking at KVM code ...)
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Also is the hole inside a hotplugable memory something we really have to care about. Has anybody actually seen a platform to require that?
That's what I was asking. I can see "support" for this was added basically right from the beginning. I'd say we rip that out and cleanup/simplify. I am not aware of a platform that requires this. Especially, memory holes on DIMMs (detected during boot) seem like an unlikely thing.
Quoted 10 lines
The thing is that the hotplug development shows ad-hoc decisions throughout the code. It is even worse that it is hard to guess whether some hludges are a result of a careful design or ad-hoc trial and failure approach on setups that never were production. Building on top of that be preserving hacks is not going to improve the situation. So I am perfectly fine to focus on making the most straightforward setups work reliably. Even when there is a risk of breaking some odd setups. We can fix them up later but we would have at least a specific example and document it.
Alright, I'll prepare a simple patch that rejects offlining memory with memory holes. We can apply that and see if anybody screams out loud. If not, we can clean up that crap.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Michal Hocko
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Michal Hocko
Quoted 1 line · David Hildenbrand
On 21.10.19 16:43, Michal Hocko wrote:
[...]
Quoted 9 lines
Quoted 3 lines
We still set PageReserved before onlining pages and that one should be good to go as well (
memmap_init_zone).
Thanks!
memmap_init_zone()is called when onlining memory. There, set all pages to reserved right now (on context ==MEMMAP_HOTPLUG). We clearPG_reservedwhen onlining a page to the buddy (e.g.,generic_online_page). If we would online a memory block with holes, we would want to keep all such pages (!pfn_valid()) set to reserved. Also, there might be other side effects.Isn't it sufficient to have those pages in a poisoned state? They are not onlined so their state is basically undefined anyway. I do not see how PageReserved makes this any better.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
It is what people have been using for a long time. Memory hole ->
PG_reserved. The memmap is valid, but people want to tell "this here is crap, don't look at it".The page is poisoned, right? If yes then setting the reserved bit doesn't make any sense.
No it's not poisoned AFAIK. It should be initialized
Dohh, it seems I still keep confusing myself. You are right the page is initialized at this stage. A potential hole in RAM or ZONE_DEVICE memory will just not hit the page allocator. Sorry about the noise.
Quoted 2 lines
- and I remember that
PG_reservedon memory holes is relevant to detect MMIO pages. (e.g., looking at KVM code ...)
I can see kvm_is_reserved_pfn() which checks both pfn_valid and PageReserved. How does this help to detect memory holes though? Any driver might be setting the page reserved.
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Also is the hole inside a hotplugable memory something we really have to care about. Has anybody actually seen a platform to require that?
That's what I was asking. I can see "support" for this was added basically right from the beginning. I'd say we rip that out and cleanup/simplify. I am not aware of a platform that requires this. Especially, memory holes on DIMMs (detected during boot) seem like an unlikely thing.
Quoted 10 lines
The thing is that the hotplug development shows ad-hoc decisions throughout the code. It is even worse that it is hard to guess whether some hludges are a result of a careful design or ad-hoc trial and failure approach on setups that never were production. Building on top of that be preserving hacks is not going to improve the situation. So I am perfectly fine to focus on making the most straightforward setups work reliably. Even when there is a risk of breaking some odd setups. We can fix them up later but we would have at least a specific example and document it.
Quoted 1 line
Alright, I'll prepare a simple patch that rejects offlining memory with
Is offlining an interesting path? I would expect onlining to be much more interesting one.
Quoted 2 lines
memory holes. We can apply that and see if anybody screams out loud. If not, we can clean up that crap.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v1 1/2] mm/page_alloc.c: Don't set pages PageReserved() when offlining
Quoted 6 lines
Quoted 2 lines
- and I remember that
PG_reservedon memory holes is relevant to detect MMIO pages. (e.g., looking at KVM code ...)I can see
kvm_is_reserved_pfn()which checks bothpfn_validand PageReserved. How does this help to detect memory holes though? Any driver might be setting the page reserved.
See my other mail. This is mostly to not touch MMIO pages and ZONE_DEVICE pages ... well and /dev/mem mapped pages.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 8 lines
Quoted 3 lines
Also is the hole inside a hotplugable memory something we really have to care about. Has anybody actually seen a platform to require that?
That's what I was asking. I can see "support" for this was added basically right from the beginning. I'd say we rip that out and cleanup/simplify. I am not aware of a platform that requires this. Especially, memory holes on DIMMs (detected during boot) seem like an unlikely thing.
The thing is that the hotplug development shows ad-hoc decisions throughout the code. It is even worse that it is hard to guess whether some hludges are a result of a careful design or ad-hoc trial and failure approach on setups that never were production. Building on top of that be preserving hacks is not going to improve the situation. So I am perfectly fine to focus on making the most straightforward setups work reliably. Even when there is a risk of breaking some odd setups. We can fix them up later but we would have at least a specific example and document it.
Quoted 4 lines
Quoted 1 line
Alright, I'll prepare a simple patch that rejects offlining memory with
Is offlining an interesting path? I would expect onlining to be much more interesting one.
If you can't offline memory with holes, you can also not online memory with holes AFAIKS :)
Bootmem is online, and memory you can hotplug (initially offline) cannot have any holes.
Signature · 3 lines
Thanks, David / dhildenb
PATCH 2/2 mm/page_isolation.c: Convert SKIP_HWPOISON to MEMORY_OFFLINE
In reply to David HildenbrandWe have two types of users of page isolation:
1. Memory offlining: Offline memory so it can be unplugged. Memory won't be touched.
2. Memory allocation: Allocate memory (e.g., alloc_contig_range()) to become the owner of the memory and make use of it.
For example, in case we want to offline memory, we can ignore (skip over) PageHWPoison() pages, as the memory won't get used. We can allow to offline memory. In contrast, we don't want to allow to allocate such memory.
Let's generalize the approach so we can special case other types of pages we want to skip over in case we offline memory. While at it, also pass the same flags to test_pages_isolated().
--- include/linux/page-isolation.h | 4 ++-- mm/memory_hotplug.c | 8 +++++--- mm/page_alloc.c | 4 ++-- mm/page_isolation.c | 12 ++++++------ 4 files changed, 15 insertions(+), 13 deletions(-)
include/linux/page-isolation.h +2 -2
@@ -30,7 +30,7 @@ static inline bool is_migrate_isolate(int migratetype) }#endif -#define SKIP_HWPOISON 0x1 +#define MEMORY_OFFLINE 0x1#define REPORT_FAILURE 0x2 bool has_unmovable_pages(struct zone *zone, struct page *page, int count,
@@ -58,7 +58,7 @@ undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,* Test all pages in [start_pfn, end_pfn) are isolated or not. */ int test_pages_isolated (unsigned long start_pfn,unsigned long end_pfn, -bool skip_hwpoisoned_pages); +int isol_flags);struct page *alloc_migrate_target (struct page *page,unsigned long private);
mm/memory_hotplug.c +5 -3
@@ -1149,7 +1149,8 @@ static bool is_pageblock_removable_nolock(unsigned long pfn)if (!zone_spans_pfn (zone, pfn))return false; -return !has_unmovable_pages (zone, page,0 ,MIGRATE_MOVABLE ,SKIP_HWPOISON ); +return !has_unmovable_pages (zone, page,0 ,MIGRATE_MOVABLE , +MEMORY_OFFLINE ); }/* Checks if this range of memory is likely to be hot-removable. */
@@ -1366,7 +1367,8 @@ static int check_pages_isolated_cb(unsigned long start_pfn, unsigned long nr_pages, void *data) { -return test_pages_isolated (start_pfn, start_pfn + nr_pages, true); +return test_pages_isolated (start_pfn, start_pfn + nr_pages, +MEMORY_OFFLINE ); }static int __init cmdline_parse_movable_node (char *p)
@@ -1477,7 +1479,7 @@ static int __ref __offline_pages(unsigned long start_pfn,/* set above range as isolated */ ret =start_isolate_page_range (start_pfn, end_pfn,MIGRATE_MOVABLE , -SKIP_HWPOISON |REPORT_FAILURE ); +MEMORY_OFFLINE |REPORT_FAILURE );if (ret <0 ) { reason ="failure to isolate range" ; goto failed_removal;
mm/page_alloc.c +2 -2
@@ -8270,7 +8270,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,* The HWPoisoned page may be not in buddy system, and * page_count() is not 0. */ -if ((flags &SKIP_HWPOISON ) &&PageHWPoison (page)) +if (flags &MEMORY_OFFLINE &&PageHWPoison (page))continue ;if (__PageMovable (page))
@@ -8486,7 +8486,7 @@ int alloc_contig_range(unsigned long start, unsigned long end, }/* Make sure the range is really isolated. */ -if (test_pages_isolated (outer_start, end, false)) { +if (test_pages_isolated (outer_start, end,0 )) {pr_info_ratelimited ("%s: [%lx, %lx) PFNs busy\n" , __func__, outer_start, end); ret = -EBUSY ;
mm/page_isolation.c +6 -6
@@ -168,7 +168,8 @@ __first_valid_page(unsigned long pfn, unsigned long nr_pages)* @migratetype: Migrate type to set in error recovery. * @flags: The following flags are allowed (they can be combined in * a bit mask) -* SKIP_HWPOISON - ignore hwpoison pages +* MEMORY_OFFLINE - isolate to offline (!allocate) memory +* e.g., skip over PageHWPoison() pages * REPORT_FAILURE - report details about the failure to * isolate the range *
@@ -257,7 +258,7 @@ void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,*/ static unsigned long __test_page_isolated_in_pageblock (unsigned long pfn,unsigned long end_pfn, -bool skip_hwpoisoned_pages) +int flags) {struct page *page;
@@ -274,7 +275,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,* simple way to verify that as VM_BUG_ON(), though. */ pfn +=1 <<page_order (page); - else if (skip_hwpoisoned_pages && PageHWPoison(page)) + else if (flags & MEMORY_OFFLINE && PageHWPoison(page))/* A HWPoisoned page cannot be also PageBuddy */ pfn++; else
@@ -286,7 +287,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,/* Caller should ensure that requested range is in a single zone */ int test_pages_isolated (unsigned long start_pfn,unsigned long end_pfn, -bool skip_hwpoisoned_pages) +int isol_flags) {unsigned long pfn, flags;struct page *page;
@@ -308,8 +309,7 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,/* Check all pages are free or marked as ISOLATED */ zone =page_zone (page);spin_lock_irqsave (&zone->lock, flags); - pfn =__test_page_isolated_in_pageblock (start_pfn, end_pfn, - skip_hwpoisoned_pages); + pfn =__test_page_isolated_in_pageblock (start_pfn, end_pfn, isol_flags);spin_unlock_irqrestore (&zone->lock, flags);trace_test_pages_isolated (start_pfn, end_pfn, pfn);
Signature · 1 line
2.21.0
Re: [PATCH v1 2/2] mm/page_isolation.c: Convert SKIP_HWPOISON to MEMORY_OFFLINE
Quoted 15 lines · David Hildenbrand
We have two types of users of page isolation:
1. Memory offlining: Offline memory so it can be unplugged. Memory won't be touched.
2. Memory allocation: Allocate memory (e.g.,alloc_contig_range()) to become the owner of the memory and make use of it.For example, in case we want to offline memory, we can ignore (skip over)
PageHWPoison()pages, as the memory won't get used. We can allow to offline memory. In contrast, we don't want to allow to allocate such memory.Let's generalize the approach so we can special case other types of pages we want to skip over in case we offline memory. While at it, also pass the same flags to
test_pages_isolated().
Quoted 15 lines
Cc Michal Hocko <[email protected]>Cc Oscar Salvador <[email protected]>Cc Andrew Morton <[email protected]>Cc Anshuman Khandual <[email protected]>Cc David Hildenbrand <[email protected]>Cc Pingfan Liu <[email protected]>Cc Qian Cai <[email protected]>Cc Pavel Tatashin <[email protected]>Cc Dan Williams <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mel Gorman <[email protected]>Cc Mike Rapoport <[email protected]>Cc Alexander Duyck <[email protected]>Suggested-by Michal Hocko <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Yes, a highlevel flag makes more sense than requesting specific types of pages to skip over.
Please make the code easier to follow ...
Quoted 20 lines
--- include/linux/page-isolation.h | 4 ++-- mm/memory_hotplug.c | 8 +++++--- mm/page_alloc.c | 4 ++-- mm/page_isolation.c | 12 ++++++------ 4 files changed, 15 insertions(+), 13 deletions(-)mm/page_alloc.c +1
-1@@ -8270,7 +8270,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,* The HWPoisoned page may be not in buddy system, and * page_count() is not 0. */ -if ((flags &SKIP_HWPOISON ) &&PageHWPoison (page)) +if (flags &MEMORY_OFFLINE &&PageHWPoison (page))continue ;if (__PageMovable (page))
[...]
Quoted 10 lines
mm/page_alloc.c +1
-1@@ -257,7 +258,7 @@ void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,*/ static unsigned long __test_page_isolated_in_pageblock (unsigned long pfn,unsigned long end_pfn, -bool skip_hwpoisoned_pages) +int flags) {struct page *page;
mm/page_alloc.c __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn, · line 281
Quoted 8 lines
mm/page_alloc.c +1
-1@@ -274,7 +275,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,* simple way to verify that as VM_BUG_ON(), though. */ pfn +=1 <<page_order (page); - else if (skip_hwpoisoned_pages && PageHWPoison(page)) + else if (flags & MEMORY_OFFLINE && PageHWPoison(page))/* A HWPoisoned page cannot be also PageBuddy */ pfn++; else
.. and use parentheses for the flag check.
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v1 2/2] mm/page_isolation.c: Convert SKIP_HWPOISON to MEMORY_OFFLINE
Quoted 68 lines · Michal Hocko
Quoted 15 lines · David Hildenbrand
We have two types of users of page isolation:
1. Memory offlining: Offline memory so it can be unplugged. Memory won't be touched.
2. Memory allocation: Allocate memory (e.g.,alloc_contig_range()) to become the owner of the memory and make use of it.For example, in case we want to offline memory, we can ignore (skip over)
PageHWPoison()pages, as the memory won't get used. We can allow to offline memory. In contrast, we don't want to allow to allocate such memory.Let's generalize the approach so we can special case other types of pages we want to skip over in case we offline memory. While at it, also pass the same flags to
test_pages_isolated().Quoted 15 lines
Cc Michal Hocko <[email protected]>Cc Oscar Salvador <[email protected]>Cc Andrew Morton <[email protected]>Cc Anshuman Khandual <[email protected]>Cc David Hildenbrand <[email protected]>Cc Pingfan Liu <[email protected]>Cc Qian Cai <[email protected]>Cc Pavel Tatashin <[email protected]>Cc Dan Williams <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Mel Gorman <[email protected]>Cc Mike Rapoport <[email protected]>Cc Alexander Duyck <[email protected]>Suggested-by Michal Hocko <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Yes, a highlevel flag makes more sense than requesting specific types of pages to skip over.
Acked-by Michal Hocko <[email protected]>Please make the code easier to follow ...
Quoted 20 lines
--- include/linux/page-isolation.h | 4 ++-- mm/memory_hotplug.c | 8 +++++--- mm/page_alloc.c | 4 ++-- mm/page_isolation.c | 12 ++++++------ 4 files changed, 15 insertions(+), 13 deletions(-)mm/page_alloc.c +1
-1@@ -8270,7 +8270,7 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count,* The HWPoisoned page may be not in buddy system, and * page_count() is not 0. */ -if ((flags &SKIP_HWPOISON ) &&PageHWPoison (page)) +if (flags &MEMORY_OFFLINE &&PageHWPoison (page))continue ;if (__PageMovable (page))[...]
Quoted 9 lines
mm/page_alloc.c +1
-1@@ -257,7 +258,7 @@ void undo_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,*/ static unsigned long __test_page_isolated_in_pageblock (unsigned long pfn,unsigned long end_pfn, -bool skip_hwpoisoned_pages) +int flags) {struct page *page;
Quoted 12 lines
mm/page_alloc.c __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn, · line 281
Quoted 9 lines
mm/page_alloc.c +1
-1@@ -274,7 +275,7 @@ __test_page_isolated_in_pageblock(unsigned long pfn, unsigned long end_pfn,* simple way to verify that as VM_BUG_ON(), though. */ pfn +=1 <<page_order (page); - else if (skip_hwpoisoned_pages && PageHWPoison(page)) + else if (flags & MEMORY_OFFLINE && PageHWPoison(page))/* A HWPoisoned page cannot be also PageBuddy */ pfn++; else.. and use parentheses for the flag check.
Can do if you prefer :)
Thanks!
I'll resend both patches.
Signature · 3 lines
Thanks, David / dhildenb