LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/2] Fixes for sub-section hotplug
@ 2019-07-17  9:07 Oscar Salvador
  2019-07-17  9:07 ` [PATCH v2 1/2] mm,sparse: Fix deactivate_section for early sections Oscar Salvador
  2019-07-17  9:07 ` [PATCH v2 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span Oscar Salvador
  0 siblings, 2 replies; 4+ messages in thread
From: Oscar Salvador @ 2019-07-17  9:07 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, david, pasha.tatashin, mhocko, aneesh.kumar,
	linux-mm, linux-kernel, Oscar Salvador

v2 -> v1: Go the easy way and just adapt the check (Dan/Aneesh)

Hi all,

these two patches address a couple of issues I found while working on my
vmemmap-patchset.
The issues are:

        1) section_deactivate mistakenly zeroes ms->section_mem_map and then
           tries to check whether the section is an early section, but since
           section_mem_map might have been zeroed, we will return false
           when it is really an early section.
           In order to fix this, let us check whether the section is early
           at function entry, so we do not neet check it again later.

        2) shrink_{node,zone}_span work on sub-section granularity now.
           The problem is that since deactivation of the section occurs later
           on in sparse_remove_section, so the pfn_valid()->pfn_section_valid()
           check will always return true for every sub-section chunk.
           In order to avoid that, let us adapt the check and skip the whole
           range to be removed.
           The user visible effect of this is that we are always left with,
           at least, PAGES_PER_SECTION spanned, even if we got to remove all
           memory linked to a zone/node

Oscar Salvador (2):
  mm,sparse: Fix deactivate_section for early sections
  mm,memory_hotplug: Fix shrink_{zone,node}_span

 mm/memory_hotplug.c | 8 ++++----
 mm/sparse.c         | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)

-- 
2.12.3


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

* [PATCH v2 1/2] mm,sparse: Fix deactivate_section for early sections
  2019-07-17  9:07 [PATCH v2 0/2] Fixes for sub-section hotplug Oscar Salvador
@ 2019-07-17  9:07 ` Oscar Salvador
  2019-07-17  9:07 ` [PATCH v2 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span Oscar Salvador
  1 sibling, 0 replies; 4+ messages in thread
From: Oscar Salvador @ 2019-07-17  9:07 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, david, pasha.tatashin, mhocko, aneesh.kumar,
	linux-mm, linux-kernel, Oscar Salvador

deactivate_section checks whether a section is early or not
in order to either call free_map_bootmem() or depopulate_section_memmap().
Being the former for sections added at boot time, and the latter for
sections hotplugged.

The problem is that we zero section_mem_map, so the last early_section()
will always report false and the section will not be removed.

Fix this checking whether a section is early or not at function
entry.

Fixes: mmotm ("mm/sparsemem: Support sub-section hotplug")
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Reviewed-by: Dan Williams <dan.j.wiliams@intel.com>
---
 mm/sparse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index 3267c4001c6d..1e224149aab6 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -738,6 +738,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
 	DECLARE_BITMAP(map, SUBSECTIONS_PER_SECTION) = { 0 };
 	DECLARE_BITMAP(tmp, SUBSECTIONS_PER_SECTION) = { 0 };
 	struct mem_section *ms = __pfn_to_section(pfn);
+	bool section_is_early = early_section(ms);
 	struct page *memmap = NULL;
 	unsigned long *subsection_map = ms->usage
 		? &ms->usage->subsection_map[0] : NULL;
@@ -772,7 +773,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
 	if (bitmap_empty(subsection_map, SUBSECTIONS_PER_SECTION)) {
 		unsigned long section_nr = pfn_to_section_nr(pfn);
 
-		if (!early_section(ms)) {
+		if (!section_is_early) {
 			kfree(ms->usage);
 			ms->usage = NULL;
 		}
@@ -780,7 +781,7 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
 		ms->section_mem_map = sparse_encode_mem_map(NULL, section_nr);
 	}
 
-	if (early_section(ms) && memmap)
+	if (section_is_early && memmap)
 		free_map_bootmem(memmap);
 	else
 		depopulate_section_memmap(pfn, nr_pages, altmap);
-- 
2.12.3


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

* [PATCH v2 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span
  2019-07-17  9:07 [PATCH v2 0/2] Fixes for sub-section hotplug Oscar Salvador
  2019-07-17  9:07 ` [PATCH v2 1/2] mm,sparse: Fix deactivate_section for early sections Oscar Salvador
@ 2019-07-17  9:07 ` Oscar Salvador
  2019-07-17 18:45   ` Dan Williams
  1 sibling, 1 reply; 4+ messages in thread
From: Oscar Salvador @ 2019-07-17  9:07 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, david, pasha.tatashin, mhocko, aneesh.kumar,
	linux-mm, linux-kernel, Oscar Salvador

Since [1], shrink_{zone,node}_span work on PAGES_PER_SUBSECTION granularity.
We need to adapt the loop that checks whether a zone/node contains only holes,
and skip the whole range to be removed.

Otherwise, since sub-sections belonging to the range to be removed have not yet
been deactivated, pfn_valid() will return true on those and we will be left
with a wrong accounting of spanned_pages, both for the zone and the node.

Fixes: mmotm ("mm/hotplug: prepare shrink_{zone, pgdat}_span for sub-section removal")
Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
 mm/memory_hotplug.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index b9ba5b85f9f7..2a9bbddb0e55 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -422,8 +422,8 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (page_zone(pfn_to_page(pfn)) != zone)
 			continue;
 
-		 /* If the section is current section, it continues the loop */
-		if (start_pfn == pfn)
+		/* Skip range to be removed */
+		if (pfn >= start_pfn && pfn < end_pfn)
 			continue;
 
 		/* If we find valid section, we have nothing to do */
@@ -487,8 +487,8 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
 		if (pfn_to_nid(pfn) != nid)
 			continue;
 
-		 /* If the section is current section, it continues the loop */
-		if (start_pfn == pfn)
+		/* Skip range to be removed */
+		if (pfn >= start_pfn && pfn < end_pfn)
 			continue;
 
 		/* If we find valid section, we have nothing to do */
-- 
2.12.3


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

* Re: [PATCH v2 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span
  2019-07-17  9:07 ` [PATCH v2 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span Oscar Salvador
@ 2019-07-17 18:45   ` Dan Williams
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Williams @ 2019-07-17 18:45 UTC (permalink / raw)
  To: Oscar Salvador
  Cc: Andrew Morton, David Hildenbrand, Pavel Tatashin, Michal Hocko,
	Aneesh Kumar K.V, Linux MM, Linux Kernel Mailing List

On Wed, Jul 17, 2019 at 2:07 AM Oscar Salvador <osalvador@suse.de> wrote:
>
> Since [1], shrink_{zone,node}_span work on PAGES_PER_SUBSECTION granularity.
> We need to adapt the loop that checks whether a zone/node contains only holes,
> and skip the whole range to be removed.
>
> Otherwise, since sub-sections belonging to the range to be removed have not yet
> been deactivated, pfn_valid() will return true on those and we will be left
> with a wrong accounting of spanned_pages, both for the zone and the node.
>
> Fixes: mmotm ("mm/hotplug: prepare shrink_{zone, pgdat}_span for sub-section removal")
> Signed-off-by: Oscar Salvador <osalvador@suse.de>

Looks good,

Reviewed-by: Dan Williams <dan.j.williams@intel.com>

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

end of thread, other threads:[~2019-07-17 18:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17  9:07 [PATCH v2 0/2] Fixes for sub-section hotplug Oscar Salvador
2019-07-17  9:07 ` [PATCH v2 1/2] mm,sparse: Fix deactivate_section for early sections Oscar Salvador
2019-07-17  9:07 ` [PATCH v2 2/2] mm,memory_hotplug: Fix shrink_{zone,node}_span Oscar Salvador
2019-07-17 18:45   ` Dan Williams

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).