linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mm/memory_hotplug: Fix updating the node span
@ 2019-10-27 22:27 David Hildenbrand
  2019-10-30  8:14 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: David Hildenbrand @ 2019-10-27 22:27 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Andrew Morton, Michal Hocko,
	Oscar Salvador, Stephen Rothwell, Dan Williams, Pavel Tatashin,
	Greg Kroah-Hartman

We recently started updating the node span based on the zone span to
avoid touching uninitialized memmaps.

Currently, we will always detect the node span to start at 0, meaning a
node can easily span too many pages. pgdat_is_empty() will still work
correctly if all zones span no pages. We should skip over all zones without
spanned pages and properly handle the first detected zone that spans pages.

Unfortunately, in contrast to the zone span (/proc/zoneinfo), the node span
cannot easily be inspected and tested. The node span gives no real
guarantees when an architecture supports memory hotplug, meaning it can
easily contain holes or span pages of different nodes.

The node span is not really used after init on architectures that support
memory hotplug. E.g., we use it in mm/memory_hotplug.c:try_offline_node()
and in mm/kmemleak.c:kmemleak_scan(). These users seem to be fine.

Fixes: 00d6c019b5bc ("mm/memory_hotplug: don't access uninitialized memmaps in shrink_pgdat_span()")
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---

Luckily, this patch made me realize that try_offline_node() is completely
broken:
- We easily touch the (garbage) memmap of offline sections
- We will not properly handle the case where we have different NIDs within
  a single section
This needs proper fixing. We will have to look at the memory block nid
of offline memory blocks and scan all pages (or rather pageblocks) of
online memory blocks.

---
 mm/memory_hotplug.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 561371ead39a..0140c20837b6 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -442,6 +442,14 @@ static void update_pgdat_span(struct pglist_data *pgdat)
 					     zone->spanned_pages;
 
 		/* No need to lock the zones, they can't change. */
+		if (!zone->spanned_pages)
+			continue;
+		if (!node_end_pfn) {
+			node_start_pfn = zone->zone_start_pfn;
+			node_end_pfn = zone_end_pfn;
+			continue;
+		}
+
 		if (zone_end_pfn > node_end_pfn)
 			node_end_pfn = zone_end_pfn;
 		if (zone->zone_start_pfn < node_start_pfn)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] mm/memory_hotplug: Fix updating the node span
  2019-10-27 22:27 [PATCH v1] mm/memory_hotplug: Fix updating the node span David Hildenbrand
@ 2019-10-30  8:14 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2019-10-30  8:14 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton
  Cc: linux-mm, Michal Hocko, Oscar Salvador, Stephen Rothwell,
	Dan Williams, Pavel Tatashin, Greg Kroah-Hartman

On 27.10.19 23:27, David Hildenbrand wrote:
> We recently started updating the node span based on the zone span to
> avoid touching uninitialized memmaps.
> 
> Currently, we will always detect the node span to start at 0, meaning a
> node can easily span too many pages. pgdat_is_empty() will still work
> correctly if all zones span no pages. We should skip over all zones without
> spanned pages and properly handle the first detected zone that spans pages.
> 
> Unfortunately, in contrast to the zone span (/proc/zoneinfo), the node span
> cannot easily be inspected and tested. The node span gives no real
> guarantees when an architecture supports memory hotplug, meaning it can
> easily contain holes or span pages of different nodes.
> 
> The node span is not really used after init on architectures that support
> memory hotplug. E.g., we use it in mm/memory_hotplug.c:try_offline_node()
> and in mm/kmemleak.c:kmemleak_scan(). These users seem to be fine.
> 
> Fixes: 00d6c019b5bc ("mm/memory_hotplug: don't access uninitialized memmaps in shrink_pgdat_span()")


@Andrew, can we also give this a churn, we should try to get this into 
5.4 due to

$ git tag --contains 00d6c019b5bc
[...]
v5.4-rc5

Thanks!

-- 

Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-30  8:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-27 22:27 [PATCH v1] mm/memory_hotplug: Fix updating the node span David Hildenbrand
2019-10-30  8:14 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).