From: osalvador@techadventures.net
To: akpm@linux-foundation.org
Cc: mhocko@suse.com, dan.j.williams@intel.com,
pasha.tatashin@oracle.com, jglisse@redhat.com, david@redhat.com,
yasu.isimatu@gmail.com, logang@deltatee.com,
dave.jiang@intel.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Oscar Salvador <osalvador@suse.de>
Subject: [RFC PATCH 3/3] mm/memory_hotplug: Refactor shrink_zone/pgdat_span
Date: Tue, 7 Aug 2018 15:37:57 +0200 [thread overview]
Message-ID: <20180807133757.18352-4-osalvador@techadventures.net> (raw)
In-Reply-To: <20180807133757.18352-1-osalvador@techadventures.net>
From: Oscar Salvador <osalvador@suse.de>
This patch refactors shrink_zone_span and shrink_pgdat_span functions.
In case that find_smallest/biggest_section do not return any pfn,
it means that the zone/pgdat has no online sections left, so we can
set the respective values to 0:
zone case:
zone->zone_start_pfn = 0;
zone->spanned_pages = 0;
pgdat case:
pgdat->node_start_pfn = 0;
pgdat->node_spanned_pages = 0;
Also, the check that loops over all sections to see if we have something left
is moved to an own function, and so the code can be shared by shrink_zone_span
and shrink_pgdat_span.
Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
mm/memory_hotplug.c | 127 +++++++++++++++++++++++++++-------------------------
1 file changed, 65 insertions(+), 62 deletions(-)
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index e33555651e46..ccac36eaac05 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -365,6 +365,29 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
return 0;
}
+static bool has_only_holes(struct zone *zone, int nid, unsigned long zone_start_pfn,
+ unsigned long zone_end_pfn)
+{
+ unsigned long pfn;
+
+ pfn = zone_start_pfn;
+ for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) {
+ struct mem_section *ms = __pfn_to_section(pfn);
+
+ if (unlikely(!online_section(ms)))
+ continue;
+ if (zone && page_zone(pfn_to_page(pfn)) != zone)
+ continue;
+
+ if (pfn_to_nid(pfn) != nid)
+ continue;
+
+ return false;
+ }
+
+ return true;
+}
+
static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
unsigned long end_pfn)
{
@@ -372,7 +395,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 zone_end_pfn = z;
unsigned long pfn;
- struct mem_section *ms;
int nid = zone_to_nid(zone);
zone_span_writelock(zone);
@@ -385,10 +407,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
*/
pfn = find_smallest_section_pfn(nid, zone, end_pfn,
zone_end_pfn);
- if (pfn) {
- zone->zone_start_pfn = pfn;
- zone->spanned_pages = zone_end_pfn - pfn;
- }
+ if (!pfn)
+ goto only_holes;
+
+ zone->zone_start_pfn = pfn;
+ zone->spanned_pages = zone_end_pfn - pfn;
} else if (zone_end_pfn == end_pfn) {
/*
* If the section is biggest section in the zone, it need
@@ -398,38 +421,28 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
*/
pfn = find_biggest_section_pfn(nid, zone, zone_start_pfn,
start_pfn);
- if (pfn)
- zone->spanned_pages = pfn - zone_start_pfn + 1;
- }
-
- /*
- * The section is not biggest or smallest mem_section in the zone, it
- * only creates a hole in the zone. So in this case, we need not
- * change the zone. But perhaps, the zone has only hole data. Thus
- * it check the zone has only hole or not.
- */
- pfn = zone_start_pfn;
- for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) {
- ms = __pfn_to_section(pfn);
-
- if (unlikely(!online_section(ms)))
- continue;
+ if (!pfn)
+ goto only_holes;
- if (page_zone(pfn_to_page(pfn)) != zone)
- continue;
-
- /* If the section is current section, it continues the loop */
- if (start_pfn == pfn)
- continue;
-
- /* If we find valid section, we have nothing to do */
- zone_span_writeunlock(zone);
- return;
+ zone->spanned_pages = pfn - zone_start_pfn + 1;
+ } else {
+ /*
+ * The section is not biggest or smallest mem_section in the zone, it
+ * only creates a hole in the zone. So in this case, we need not
+ * change the zone. But perhaps, the zone has only hole data. Thus
+ * it check the zone has only hole or not.
+ */
+ if (has_only_holes(zone, nid, zone_start_pfn, zone_end_pfn))
+ goto only_holes;
}
+ goto out;
+
+only_holes:
/* The zone has no valid section */
zone->zone_start_pfn = 0;
zone->spanned_pages = 0;
+out:
zone_span_writeunlock(zone);
}
@@ -440,7 +453,6 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
unsigned long p = pgdat_end_pfn(pgdat); /* pgdat_end_pfn namespace clash */
unsigned long pgdat_end_pfn = p;
unsigned long pfn;
- struct mem_section *ms;
int nid = pgdat->node_id;
if (pgdat_start_pfn == start_pfn) {
@@ -452,10 +464,11 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
*/
pfn = find_smallest_section_pfn(nid, NULL, end_pfn,
pgdat_end_pfn);
- if (pfn) {
- pgdat->node_start_pfn = pfn;
- pgdat->node_spanned_pages = pgdat_end_pfn - pfn;
- }
+ if (!pfn)
+ goto only_holes;
+
+ pgdat->node_start_pfn = pfn;
+ pgdat->node_spanned_pages = pgdat_end_pfn - pfn;
} else if (pgdat_end_pfn == end_pfn) {
/*
* If the section is biggest section in the pgdat, it need
@@ -465,35 +478,25 @@ static void shrink_pgdat_span(struct pglist_data *pgdat,
*/
pfn = find_biggest_section_pfn(nid, NULL, pgdat_start_pfn,
start_pfn);
- if (pfn)
- pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1;
- }
-
- /*
- * If the section is not biggest or smallest mem_section in the pgdat,
- * it only creates a hole in the pgdat. So in this case, we need not
- * change the pgdat.
- * But perhaps, the pgdat has only hole data. Thus it check the pgdat
- * has only hole or not.
- */
- pfn = pgdat_start_pfn;
- for (; pfn < pgdat_end_pfn; pfn += PAGES_PER_SECTION) {
- ms = __pfn_to_section(pfn);
-
- if (unlikely(!online_section(ms)))
- continue;
-
- if (pfn_to_nid(pfn) != nid)
- continue;
+ if (!pfn)
+ goto only_holes;
- /* If the section is current section, it continues the loop */
- if (start_pfn == pfn)
- continue;
-
- /* If we find valid section, we have nothing to do */
- return;
+ pgdat->node_spanned_pages = pfn - pgdat_start_pfn + 1;
+ } else {
+ /*
+ * If the section is not biggest or smallest mem_section in the pgdat,
+ * it only creates a hole in the pgdat. So in this case, we need not
+ * change the pgdat.
+ * But perhaps, the pgdat has only hole data. Thus it check the pgdat
+ * has only hole or not.
+ */
+ if (has_only_holes(NULL, nid, pgdat_start_pfn, pgdat_end_pfn))
+ goto only_holes;
}
+ return;
+
+only_holes:
/* The pgdat has no valid section */
pgdat->node_start_pfn = 0;
pgdat->node_spanned_pages = 0;
--
2.13.6
next prev parent reply other threads:[~2018-08-07 13:38 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-07 13:37 [RFC PATCH 0/3] Do not touch pages in remove_memory path osalvador
2018-08-07 13:37 ` [RFC PATCH 1/3] mm/memory_hotplug: Add nid parameter to arch_remove_memory osalvador
2018-08-07 13:37 ` [RFC PATCH 2/3] mm/memory_hotplug: Create __shrink_pages and move it to offline_pages osalvador
2018-08-07 13:52 ` Jerome Glisse
2018-08-07 14:54 ` David Hildenbrand
2018-08-07 15:19 ` Jerome Glisse
2018-08-07 15:28 ` David Hildenbrand
2018-08-07 20:48 ` Oscar Salvador
2018-08-07 22:13 ` Jerome Glisse
2018-08-08 7:38 ` Oscar Salvador
2018-08-08 7:45 ` David Hildenbrand
2018-08-08 7:56 ` Oscar Salvador
2018-08-08 8:08 ` David Hildenbrand
2018-08-08 13:42 ` Oscar Salvador
2018-08-08 17:55 ` Jerome Glisse
2018-08-08 21:29 ` Oscar Salvador
2018-08-09 7:50 ` Oscar Salvador
2018-08-09 7:52 ` Oscar Salvador
2018-08-08 7:51 ` David Hildenbrand
2018-08-08 8:00 ` Oscar Salvador
2018-08-07 14:59 ` Michal Hocko
2018-08-07 15:18 ` Jerome Glisse
2018-08-08 6:47 ` Michal Hocko
2018-08-08 16:58 ` Jerome Glisse
2018-08-08 21:28 ` Oscar Salvador
2018-08-09 8:24 ` Michal Hocko
2018-08-09 14:27 ` Jerome Glisse
2018-08-09 15:09 ` Michal Hocko
2018-08-09 16:58 ` Jerome Glisse
2018-08-09 20:50 ` Oscar Salvador
2018-08-16 14:58 ` Oscar Salvador
2018-08-16 17:32 ` Jerome Glisse
2018-08-08 9:45 ` Oscar Salvador
2018-08-08 17:33 ` Jerome Glisse
2018-08-07 13:37 ` osalvador [this message]
2018-08-07 14:16 ` [RFC PATCH 0/3] Do not touch pages in remove_memory path David Hildenbrand
2018-08-07 14:19 ` Oscar Salvador
2018-08-07 14:20 ` David Hildenbrand
2018-08-07 14:28 ` Oscar Salvador
2018-08-07 14:41 ` David Hildenbrand
2018-08-07 14:52 ` Oscar Salvador
2018-08-15 14:05 ` Pavel Tatashin
2018-08-15 14:32 ` Oscar Salvador
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180807133757.18352-4-osalvador@techadventures.net \
--to=osalvador@techadventures.net \
--cc=akpm@linux-foundation.org \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=david@redhat.com \
--cc=jglisse@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=logang@deltatee.com \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=pasha.tatashin@oracle.com \
--cc=yasu.isimatu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).