mm/hotplug: prepare shrink_{zone, pgdat}_span for sub-section removal

Sub-section hotplug support reduces the unit of operation of hotplug
from section-sized-units (PAGES_PER_SECTION) to sub-section-sized units
(PAGES_PER_SUBSECTION).  Teach shrink_{zone,pgdat}_span() to consider
PAGES_PER_SUBSECTION boundaries as the points where pfn_valid(), not
valid_section(), can toggle.

[osalvador@suse.de: fix shrink_{zone,node}_span]
  Link: http://lkml.kernel.org/r/20190717090725.23618-3-osalvador@suse.de
Link: http://lkml.kernel.org/r/156092351496.979959.12703722803097017492.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>	[ppc64]
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jane Chu <jane.chu@oracle.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Toshi Kani <toshi.kani@hpe.com>
Cc: Wei Yang <richardw.yang@linux.intel.com>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Dan Williams 2019-07-18 15:58:07 -07:00 committed by Linus Torvalds
parent f46edbd1b1
commit 49ba3c6b37
1 changed files with 12 additions and 25 deletions

View File

@ -318,12 +318,8 @@ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
unsigned long start_pfn, unsigned long start_pfn,
unsigned long end_pfn) unsigned long end_pfn)
{ {
struct mem_section *ms; for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SUBSECTION) {
if (unlikely(!pfn_valid(start_pfn)))
for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) {
ms = __pfn_to_section(start_pfn);
if (unlikely(!valid_section(ms)))
continue; continue;
if (unlikely(pfn_to_nid(start_pfn) != nid)) if (unlikely(pfn_to_nid(start_pfn) != nid))
@ -343,15 +339,12 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
unsigned long start_pfn, unsigned long start_pfn,
unsigned long end_pfn) unsigned long end_pfn)
{ {
struct mem_section *ms;
unsigned long pfn; unsigned long pfn;
/* pfn is the end pfn of a memory section. */ /* pfn is the end pfn of a memory section. */
pfn = end_pfn - 1; pfn = end_pfn - 1;
for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) { for (; pfn >= start_pfn; pfn -= PAGES_PER_SUBSECTION) {
ms = __pfn_to_section(pfn); if (unlikely(!pfn_valid(pfn)))
if (unlikely(!valid_section(ms)))
continue; continue;
if (unlikely(pfn_to_nid(pfn) != nid)) if (unlikely(pfn_to_nid(pfn) != nid))
@ -373,7 +366,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */ unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */
unsigned long zone_end_pfn = z; unsigned long zone_end_pfn = z;
unsigned long pfn; unsigned long pfn;
struct mem_section *ms;
int nid = zone_to_nid(zone); int nid = zone_to_nid(zone);
zone_span_writelock(zone); zone_span_writelock(zone);
@ -410,17 +402,15 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
* it check the zone has only hole or not. * it check the zone has only hole or not.
*/ */
pfn = zone_start_pfn; pfn = zone_start_pfn;
for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) { for (; pfn < zone_end_pfn; pfn += PAGES_PER_SUBSECTION) {
ms = __pfn_to_section(pfn); if (unlikely(!pfn_valid(pfn)))
if (unlikely(!valid_section(ms)))
continue; continue;
if (page_zone(pfn_to_page(pfn)) != zone) if (page_zone(pfn_to_page(pfn)) != zone)
continue; continue;
/* If the section is current section, it continues the loop */ /* Skip range to be removed */
if (start_pfn == pfn) if (pfn >= start_pfn && pfn < end_pfn)
continue; continue;
/* If we find valid section, we have nothing to do */ /* If we find valid section, we have nothing to do */
@ -441,7 +431,6 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */ unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */
unsigned long pgdat_end_pfn = p; unsigned long pgdat_end_pfn = p;
unsigned long pfn; unsigned long pfn;
struct mem_section *ms;
int nid = pgdat->node_id; int nid = pgdat->node_id;
if (pgdat_start_pfn == start_pfn) { if (pgdat_start_pfn == start_pfn) {
@ -478,17 +467,15 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
* has only hole or not. * has only hole or not.
*/ */
pfn = pgdat_start_pfn; pfn = pgdat_start_pfn;
for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) { for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SUBSECTION) {
ms = __pfn_to_section(pfn); if (unlikely(!pfn_valid(pfn)))
if (unlikely(!valid_section(ms)))
continue; continue;
if (pfn_to_nid(pfn) != nid) if (pfn_to_nid(pfn) != nid)
continue; continue;
/* If the section is current section, it continues the loop */ /* Skip range to be removed */
if (start_pfn == pfn) if (pfn >= start_pfn && pfn < end_pfn)
continue; continue;
/* If we find valid section, we have nothing to do */ /* If we find valid section, we have nothing to do */