Skip to contentSkip to conversation

mm/memory_hotplug: online_pages() cleanups

PATCH Superseded David Hildenbrand 3 participants 16 messages Aug 9, 2019 – Aug 14, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mm/memory_hotplug: online_pages() cleanups

Some cleanups (+ one fix for a special case) in the context of online_pages(). Hope I am not missing something obvious. Did a sanity test with DIMMs only.

David Hildenbrand (4):
resource: Use PFN_UP / PFN_DOWN in walk_system_ram_range() mm/memory_hotplug: Handle unaligned start and nr_pages in
online_pages_blocks()
mm/memory_hotplug: Simplify online_pages_range() mm/memory_hotplug: online_pages cannot be 0 in online_pages()

 kernel/resource.c   |  4 +--
 mm/memory_hotplug.c | 62 ++++++++++++++++++++-------------------------
 2 files changed, 30 insertions(+), 36 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/4 resource: Use PFN_UP / PFN_DOWN in walk_system_ram_range()

This makes it clearer that we will never call func() with duplicate PFNs in case we have multiple sub-page memory resources. All unaligned parts of PFNs are completely discarded.

Cc Dan Williams <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Nadav Amit <[email protected]>
Cc Wei Yang <[email protected]>
Cc Oscar Salvador <[email protected]>
---
 kernel/resource.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/resource.c +2 -2
index 7ea4306503c5..88ee39fa9103 100644
@@ -487,8 +487,8 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
 	while (start < end &&
 	       !find_next_iomem_res(start, end, flags, IORES_DESC_NONE,
 				    false, &res)) {
-		pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
-		end_pfn = (res.end + 1) >> PAGE_SHIFT;
+		pfn = PFN_UP(res.start);
+		end_pfn = PFN_DOWN(res.end + 1);
 		if (end_pfn > pfn)
 			ret = (*func)(pfn, end_pfn - pfn, arg);
 		if (ret)
Signature · 1 line
2.21.0
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH v1 1/4] resource: Use PFN_UP / PFN_DOWN in walk_system_ram_range()

Quoted 4 lines · David Hildenbrand

This makes it clearer that we will never call func() with duplicate PFNs in case we have multiple sub-page memory resources. All unaligned parts of PFNs are completely discarded.

Quoted 10 lines
Cc Dan Williams <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Nadav Amit <[email protected]>
Cc Wei Yang <[email protected]>
Cc Oscar Salvador <[email protected]>
Quoted 21 lines
---
 kernel/resource.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/resource.c +2 -2
index 7ea4306503c5..88ee39fa9103 100644
@@ -487,8 +487,8 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
 	while (start < end &&
 	       !find_next_iomem_res(start, end, flags, IORES_DESC_NONE,
 				    false, &res)) {
-		pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
-		end_pfn = (res.end + 1) >> PAGE_SHIFT;
+		pfn = PFN_UP(res.start);
+		end_pfn = PFN_DOWN(res.end + 1);
 		if (end_pfn > pfn)
 			ret = (*func)(pfn, end_pfn - pfn, arg);
 		if (ret)
Signature · 1 line
2.21.0
Signature · 2 lines
Michal Hocko
SUSE Labs
#3 lore raw

PATCH 2/4 mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

In reply to David Hildenbrand

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

Fixes a9cd410a3d29 ("mm/page_alloc.c: memory hotplug: free pages as higher order")
Cc Arun KS <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
---
 mm/memory_hotplug.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/memory_hotplug.c +4 -0
index 3706a137d880..2abd938c8c45 100644
@@ -640,6 +640,10 @@ static int online_pages_blocks(unsigned long start, unsigned long nr_pages)
 	while (start < end) {
 		order = min(MAX_ORDER - 1,
 			get_order(PFN_PHYS(end) - PFN_PHYS(start)));
+		/* make sure the PFN is aligned and we don't exceed the range */
+		while (!IS_ALIGNED(start, 1ul << order) ||
+		       (1ul << order) > end - start)
+			order--;
 		(*online_page_callback)(pfn_to_page(start), order);
 
 		onlined_pages += (1UL << order);
Signature · 1 line
2.21.0
maintainer
#4 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

Quoted 6 lines · On Fri, 9 Aug 2019 14:56:59 +0200 David Hildenbrand <[email protected]> wrote:

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

I'm assuming this doesn't fix any known runtime problem and that a -stable backport isn't needed.

Quoted 1 line
Fixes a9cd410a3d29 ("mm/page_alloc.c: memory hotplug: free pages as higher order")

To that end, I replaced this with my new "Fixes-no-stable" in order to discourage -stable maintainers from overriding our decision.

Quoted 7 lines
Cc Arun KS <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
#5 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Fri, 9 Aug 2019 14:56:59 +0200 David Hildenbrand <[email protected]> wrote:

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

I'm assuming this doesn't fix any known runtime problem and that a -stable backport isn't needed.

Yeah, my understanding is that this would only apply when offlining and re-onlining boot memory that contains such weird memory holes. I don't think this is stable material.

Thanks!

Quoted 13 lines
Quoted 2 lines
Fixes a9cd410a3d29 ("mm/page_alloc.c: memory hotplug: free pages as higher order")

To that end, I replaced this with my new "Fixes-no-stable" in order to discourage -stable maintainers from overriding our decision.

Quoted 7 lines
Cc Arun KS <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
Signature · 3 lines
Thanks,

David / dhildenb
#6 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

In reply to David Hildenbrand
Quoted 6 lines · David Hildenbrand

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

I would really like to see an example of such setup before making the code hard to read. Because I am not really sure something like that exists at all.

Quoted 29 lines
Fixes a9cd410a3d29 ("mm/page_alloc.c: memory hotplug: free pages as higher order")
Cc Arun KS <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
---
 mm/memory_hotplug.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/memory_hotplug.c +4 -0
index 3706a137d880..2abd938c8c45 100644
@@ -640,6 +640,10 @@ static int online_pages_blocks(unsigned long start, unsigned long nr_pages)
 	while (start < end) {
 		order = min(MAX_ORDER - 1,
 			get_order(PFN_PHYS(end) - PFN_PHYS(start)));
+		/* make sure the PFN is aligned and we don't exceed the range */
+		while (!IS_ALIGNED(start, 1ul << order) ||
+		       (1ul << order) > end - start)
+			order--;
 		(*online_page_callback)(pfn_to_page(start), order);
 
 		onlined_pages += (1UL << order);
Signature · 1 line
2.21.0
Signature · 2 lines
Michal Hocko
SUSE Labs
#7 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

Quoted 11 lines · Michal Hocko
Quoted 6 lines · David Hildenbrand

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

I would really like to see an example of such setup before making the code hard to read. Because I am not really sure something like that exists at all.

I don't have a real-live example at hand (founds this while exploring the code), however, the linked commit changed it without stating why it would be safe to do so.

In case you have an idea on how to make this code easier to read, please let me know.

Quoted 31 lines
Quoted 30 lines
Fixes a9cd410a3d29 ("mm/page_alloc.c: memory hotplug: free pages as higher order")
Cc Arun KS <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
---
 mm/memory_hotplug.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/memory_hotplug.c +4 -0
index 3706a137d880..2abd938c8c45 100644
@@ -640,6 +640,10 @@ static int online_pages_blocks(unsigned long start, unsigned long nr_pages)
 	while (start < end) {
 		order = min(MAX_ORDER - 1,
 			get_order(PFN_PHYS(end) - PFN_PHYS(start)));
+		/* make sure the PFN is aligned and we don't exceed the range */
+		while (!IS_ALIGNED(start, 1ul << order) ||
+		       (1ul << order) > end - start)
+			order--;
 		(*online_page_callback)(pfn_to_page(start), order);
 
 		onlined_pages += (1UL << order);
Signature · 1 line
2.21.0
Signature · 3 lines
Thanks,

David / dhildenb
#8 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

Quoted 9 lines · David Hildenbrand
Quoted 8 lines · Michal Hocko
Quoted 6 lines · David Hildenbrand

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

Quoted 7 lines
Quoted 3 lines

I would really like to see an example of such setup before making the code hard to read. Because I am not really sure something like that exists at all.

I don't have a real-live example at hand (founds this while exploring the code), however, the linked commit changed it without stating why it would be safe to do so.

So, while I agree that "not a power of two" is rare, are you sure we will only have holes that are aligned to 4MB (especially on x86)?

Signature · 3 lines
Thanks,

David / dhildenb
#9 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

Quoted 14 lines · David Hildenbrand
Quoted 13 lines · David Hildenbrand
Quoted 11 lines · Michal Hocko
Quoted 6 lines · David Hildenbrand

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

I would really like to see an example of such setup before making the code hard to read. Because I am not really sure something like that exists at all.

Quoted 6 lines
Quoted 3 lines

I don't have a real-live example at hand (founds this while exploring the code), however, the linked commit changed it without stating why it would be safe to do so.

So, while I agree that "not a power of two" is rare, are you sure we will only have holes that are aligned to 4MB (especially on x86)?

No I am not saying that because I do not know. I am not aware of any such HW but that doesn't really mean anything. But I would like to see an example and have it archived in the changelog before we make the code more complicated.

Signature · 2 lines
Michal Hocko
SUSE Labs
#10 lore raw

Re: [PATCH v1 2/4] mm/memory_hotplug: Handle unaligned start and nr_pages in online_pages_blocks()

In reply to David Hildenbrand
Quoted 9 lines · David Hildenbrand
Quoted 8 lines · Michal Hocko
Quoted 6 lines · David Hildenbrand

Take care of nr_pages not being a power of two and start not being properly aligned. Essentially, what walk_system_ram_range() could provide to us. get_order() will round-up in case it's not a power of two.

This should only apply to memory blocks that contain strange memory resources (especially with holes), not to ordinary DIMMs.

Quoted 7 lines
Quoted 3 lines

I would really like to see an example of such setup before making the code hard to read. Because I am not really sure something like that exists at all.

I don't have a real-live example at hand (founds this while exploring the code), however, the linked commit changed it without stating why it would be safe to do so.

Then just drop the change. It is making the code a real head scratcher, and more so after the next patch. I am pretty sure that things would easily and quickly blow up if we had ranges like that.

Signature · 2 lines
Michal Hocko
SUSE Labs
#11 lore raw

PATCH 3/4 mm/memory_hotplug: Simplify online_pages_range()

In reply to David Hildenbrand

move_pfn_range_to_zone() will set all pages to PG_reserved via memmap_init_zone(). The only way a page could no longer be reserved would be if a MEM_GOING_ONLINE notifier would clear PG_reserved - which is not done (the online_page callback is used for that purpose by e.g., Hyper-V instead). walk_system_ram_range() will never call online_pages_range() with duplicate PFNs, so drop the PageReserved() check.

Simplify the handling, as online_pages always corresponds to nr_pages. There is no need for online_pages_blocks() anymore.

Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
---
 mm/memory_hotplug.c | 42 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 24 deletions(-)
mm/memory_hotplug.c +18 -24
index 2abd938c8c45..87f85597a19e 100644
@@ -632,37 +632,31 @@ static void generic_online_page(struct page *page, unsigned int order)
 #endif
 }
 
-static int online_pages_blocks(unsigned long start, unsigned long nr_pages)
+static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
+			void *arg)
 {
-	unsigned long end = start + nr_pages;
-	int order, onlined_pages = 0;
+	const unsigned long end_pfn = start_pfn + nr_pages;
+	unsigned long pfn;
+	int order;
 
-	while (start < end) {
-		order = min(MAX_ORDER - 1,
-			get_order(PFN_PHYS(end) - PFN_PHYS(start)));
+	/*
+	 * Online the pages. The callback might decide to keep some pages
+	 * PG_reserved (to add them to the buddy later), but we still account
+	 * them as being online/belonging to this zone ("present").
+	 */
+	for (pfn = start_pfn; pfn < end_pfn; pfn += 1ul << order) {
+		order = min(MAX_ORDER - 1, get_order(PFN_PHYS(end_pfn - pfn)));
 		/* make sure the PFN is aligned and we don't exceed the range */
-		while (!IS_ALIGNED(start, 1ul << order) ||
-		       (1ul << order) > end - start)
+		while (!IS_ALIGNED(start_pfn, 1ul << order) ||
+		       (1ul << order) > end_pfn - pfn)
 			order--;
-		(*online_page_callback)(pfn_to_page(start), order);
-
-		onlined_pages += (1UL << order);
-		start += (1UL << order);
+		(*online_page_callback)(pfn_to_page(pfn), order);
 	}
-	return onlined_pages;
-}
-
-static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
-			void *arg)
-{
-	unsigned long onlined_pages = *(unsigned long *)arg;
-
-	if (PageReserved(pfn_to_page(start_pfn)))
-		onlined_pages += online_pages_blocks(start_pfn, nr_pages);
 
-	online_mem_sections(start_pfn, start_pfn + nr_pages);
+	/* mark all involved sections as online */
+	online_mem_sections(start_pfn, end_pfn);
 
-	*(unsigned long *)arg = onlined_pages;
+	*(unsigned long *)arg += nr_pages;
 	return 0;
 }
 
Signature · 1 line
2.21.0
#12 lore raw

Re: [PATCH v1 3/4] mm/memory_hotplug: Simplify online_pages_range()

Quoted 9 lines · David Hildenbrand

move_pfn_range_to_zone() will set all pages to PG_reserved via memmap_init_zone(). The only way a page could no longer be reserved would be if a MEM_GOING_ONLINE notifier would clear PG_reserved - which is not done (the online_page callback is used for that purpose by e.g., Hyper-V instead). walk_system_ram_range() will never call online_pages_range() with duplicate PFNs, so drop the PageReserved() check.

Simplify the handling, as online_pages always corresponds to nr_pages. There is no need for online_pages_blocks() anymore.

This would be easier to review if split up into two patches. One that only performs cleanup without any other changes and the PageReserved check. I like the check going away and we should get rid of the dependency on the Reserved bit completely.

Other than that I find the start_pfn and pfn being used both for iteration each a different way really confusing and I cannot convince myself it is even correct because I didn't bother to look deeper as I simply think that the order manipulation from the previous is just making things worse at this moment. If the problem is even real then it can be done on top instead with some real example of the memory layout that breaks.

Quoted 72 lines
Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
---
 mm/memory_hotplug.c | 42 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 24 deletions(-)
mm/memory_hotplug.c +18 -24
index 2abd938c8c45..87f85597a19e 100644
@@ -632,37 +632,31 @@ static void generic_online_page(struct page *page, unsigned int order)
 #endif
 }
 
-static int online_pages_blocks(unsigned long start, unsigned long nr_pages)
+static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
+			void *arg)
 {
-	unsigned long end = start + nr_pages;
-	int order, onlined_pages = 0;
+	const unsigned long end_pfn = start_pfn + nr_pages;
+	unsigned long pfn;
+	int order;
 
-	while (start < end) {
-		order = min(MAX_ORDER - 1,
-			get_order(PFN_PHYS(end) - PFN_PHYS(start)));
+	/*
+	 * Online the pages. The callback might decide to keep some pages
+	 * PG_reserved (to add them to the buddy later), but we still account
+	 * them as being online/belonging to this zone ("present").
+	 */
+	for (pfn = start_pfn; pfn < end_pfn; pfn += 1ul << order) {
+		order = min(MAX_ORDER - 1, get_order(PFN_PHYS(end_pfn - pfn)));
 		/* make sure the PFN is aligned and we don't exceed the range */
-		while (!IS_ALIGNED(start, 1ul << order) ||
-		       (1ul << order) > end - start)
+		while (!IS_ALIGNED(start_pfn, 1ul << order) ||
+		       (1ul << order) > end_pfn - pfn)
 			order--;
-		(*online_page_callback)(pfn_to_page(start), order);
-
-		onlined_pages += (1UL << order);
-		start += (1UL << order);
+		(*online_page_callback)(pfn_to_page(pfn), order);
 	}
-	return onlined_pages;
-}
-
-static int online_pages_range(unsigned long start_pfn, unsigned long nr_pages,
-			void *arg)
-{
-	unsigned long onlined_pages = *(unsigned long *)arg;
-
-	if (PageReserved(pfn_to_page(start_pfn)))
-		onlined_pages += online_pages_blocks(start_pfn, nr_pages);
 
-	online_mem_sections(start_pfn, start_pfn + nr_pages);
+	/* mark all involved sections as online */
+	online_mem_sections(start_pfn, end_pfn);
 
-	*(unsigned long *)arg = onlined_pages;
+	*(unsigned long *)arg += nr_pages;
 	return 0;
 }
 
Signature · 1 line
2.21.0
Signature · 2 lines
Michal Hocko
SUSE Labs
#13 lore raw

Re: [PATCH v1 3/4] mm/memory_hotplug: Simplify online_pages_range()

Quoted 8 lines · Michal Hocko
Quoted 7 lines · David Hildenbrand

move_pfn_range_to_zone() will set all pages to PG_reserved via memmap_init_zone(). The only way a page could no longer be reserved would be if a MEM_GOING_ONLINE notifier would clear PG_reserved - which is not done (the online_page callback is used for that purpose by e.g., Hyper-V instead). walk_system_ram_range() will never call online_pages_range() with duplicate PFNs, so drop the PageReserved() check.

Quoted 7 lines
Quoted 2 lines

Simplify the handling, as online_pages always corresponds to nr_pages. There is no need for online_pages_blocks() anymore.

This would be easier to review if split up into two patches. One that only performs cleanup without any other changes and the PageReserved check. I like the check going away and we should get rid of the dependency on the Reserved bit completely.

Yes, makes sense.

Quoted 8 lines

Other than that I find the start_pfn and pfn being used both for iteration each a different way really confusing and I cannot convince myself it is even correct because I didn't bother to look deeper as I simply think that the order manipulation from the previous is just making things worse at this moment. If the problem is even real then it can be done on top instead with some real example of the memory layout that breaks.

Yes, I'll rework this. Only "pfn" should be used in the loop (it seems to be correct but confusing I agree).

Signature · 3 lines
Thanks,

David / dhildenb
#14 lore raw

PATCH 4/4 mm/memory_hotplug: online_pages cannot be 0 in online_pages()

In reply to David Hildenbrand

walk_system_ram_range() will fail with -EINVAL in case online_pages_range() was never called (== no resource applicable in the range). Otherwise, we will always call online_pages_range() with nr_pages > 0 and, therefore, have online_pages > 0.

Remove that special handling.

Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
---
 mm/memory_hotplug.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
mm/memory_hotplug.c +9 -13
index 87f85597a19e..07e72fe17495 100644
@@ -854,6 +854,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
 	ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages,
 		online_pages_range);
 	if (ret) {
+		/* not a single memory resource was applicable */
 		if (need_zonelists_rebuild)
 			zone_pcp_reset(zone);
 		goto failed_addition;
@@ -867,27 +868,22 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
 
 	shuffle_zone(zone);
 
-	if (onlined_pages) {
-		node_states_set_node(nid, &arg);
-		if (need_zonelists_rebuild)
-			build_all_zonelists(NULL);
-		else
-			zone_pcp_update(zone);
-	}
+	node_states_set_node(nid, &arg);
+	if (need_zonelists_rebuild)
+		build_all_zonelists(NULL);
+	else
+		zone_pcp_update(zone);
 
 	init_per_zone_wmark_min();
 
-	if (onlined_pages) {
-		kswapd_run(nid);
-		kcompactd_run(nid);
-	}
+	kswapd_run(nid);
+	kcompactd_run(nid);
 
 	vm_total_pages = nr_free_pagecache_pages();
 
 	writeback_set_ratelimit();
 
-	if (onlined_pages)
-		memory_notify(MEM_ONLINE, &arg);
+	memory_notify(MEM_ONLINE, &arg);
 	mem_hotplug_done();
 	return 0;
 
Signature · 1 line
2.21.0
Acked-by on v1 4/4
#15 lore raw

Re: [PATCH v1 4/4] mm/memory_hotplug: online_pages cannot be 0 in online_pages()

Quoted 4 lines · David Hildenbrand

walk_system_ram_range() will fail with -EINVAL in case online_pages_range() was never called (== no resource applicable in the range). Otherwise, we will always call online_pages_range() with nr_pages > 0 and, therefore, have online_pages > 0.

I have no idea why those checks where there TBH. Tried to dig out commits which added them but didn't help.

Quoted 8 lines

Remove that special handling.

Cc Andrew Morton <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Dan Williams <[email protected]>
Quoted 54 lines
---
 mm/memory_hotplug.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
mm/memory_hotplug.c +9 -13
index 87f85597a19e..07e72fe17495 100644
@@ -854,6 +854,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
 	ret = walk_system_ram_range(pfn, nr_pages, &onlined_pages,
 		online_pages_range);
 	if (ret) {
+		/* not a single memory resource was applicable */
 		if (need_zonelists_rebuild)
 			zone_pcp_reset(zone);
 		goto failed_addition;
@@ -867,27 +868,22 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ
 
 	shuffle_zone(zone);
 
-	if (onlined_pages) {
-		node_states_set_node(nid, &arg);
-		if (need_zonelists_rebuild)
-			build_all_zonelists(NULL);
-		else
-			zone_pcp_update(zone);
-	}
+	node_states_set_node(nid, &arg);
+	if (need_zonelists_rebuild)
+		build_all_zonelists(NULL);
+	else
+		zone_pcp_update(zone);
 
 	init_per_zone_wmark_min();
 
-	if (onlined_pages) {
-		kswapd_run(nid);
-		kcompactd_run(nid);
-	}
+	kswapd_run(nid);
+	kcompactd_run(nid);
 
 	vm_total_pages = nr_free_pagecache_pages();
 
 	writeback_set_ratelimit();
 
-	if (onlined_pages)
-		memory_notify(MEM_ONLINE, &arg);
+	memory_notify(MEM_ONLINE, &arg);
 	mem_hotplug_done();
 	return 0;
 
Signature · 1 line
2.21.0
Signature · 2 lines
Michal Hocko
SUSE Labs