Skip to contentSkip to conversation

mmzone: simplify zone_intersects()

PATCH In review Wei Yang 3 participants 6 messages Jun 16, 2017 – Jun 22, 2017

Subsystems (4)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/2 mmzone: simplify zone_intersects()

To make sure a range intersects a zone, only two comparison is necessary.

This patch simplifies the function a little.

---
 include/linux/mmzone.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
include/linux/mmzone.h +3 -7
index 0176a2933c61..7e8f100cb56d 100644
@@ -541,15 +541,11 @@ static inline bool zone_intersects(struct zone *zone,
 {
 	if (zone_is_empty(zone))
 		return false;
-	if (start_pfn >= zone_end_pfn(zone))
+	if (start_pfn >= zone_end_pfn(zone) ||
+	    start_pfn + nr_pages <= zone->zone_start_pfn)
 		return false;
 
-	if (zone->zone_start_pfn <= start_pfn)
-		return true;
-	if (start_pfn + nr_pages > zone->zone_start_pfn)
-		return true;
-
-	return false;
+	return true;
 }
 
 /*
Signature · 7 lines
2.11.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#1 lore raw

PATCH 2/2 mm/memory_hotplug: remove duplicate call for set_page_links

In function move_pfn_range_to_zone(), memmap_init_zone() will call set_page_links for each page. This means we don't need to call it on each page explicitly.

This patch just removes the loop.

---
 mm/memory_hotplug.c | 4 ----
 1 file changed, 4 deletions(-)
mm/memory_hotplug.c +0 -4
index d61509752112..4fb1fb2b2b53 100644
@@ -914,10 +914,6 @@ void __ref move_pfn_range_to_zone(struct zone *zone,
 	 * are reserved so nobody should be touching them so we should be safe
 	 */
 	memmap_init_zone(nr_pages, nid, zone_idx(zone), start_pfn, MEMMAP_HOTPLUG);
-	for (i = 0; i < nr_pages; i++) {
-		unsigned long pfn = start_pfn + i;
-		set_page_links(pfn_to_page(pfn), zone_idx(zone), nid, pfn);
-	}
 
 	set_zone_contiguous(zone);
 }
Signature · 7 lines
2.11.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#2 lore raw

Re: [PATCH 2/2] mm/memory_hotplug: remove duplicate call for set_page_links

Quoted 2 lines · On Fri, 16 Jun 2017 17:23:35 +0800 Wei Yang <[email protected]> wrote:

In function move_pfn_range_to_zone(), memmap_init_zone() will call set_page_links for each page.

Well, no. There are several types of pfn's for which memmap_init_zone() will not call __init_single_page()->set_page_links(). Probably the code is OK, as those are pretty screwy pfn types. But I'd like to see some confirmation that this patch is OK for all such pfns, now and in the future?

Quoted 10 lines

This means we don't need to call it on each
page explicitly.

This patch just removes the loop.

...

mm/memory_hotplug.c void __ref move_pfn_range_to_zone(struct zone *zone, · line 919

Quoted 10 lines
mm/memory_hotplug.c +0 -4
@@ -914,10 +914,6 @@ void __ref move_pfn_range_to_zone(struct zone *zone,
 	 * are reserved so nobody should be touching them so we should be safe
 	 */
 	memmap_init_zone(nr_pages, nid, zone_idx(zone), start_pfn, MEMMAP_HOTPLUG);
-	for (i = 0; i < nr_pages; i++) {
-		unsigned long pfn = start_pfn + i;
-		set_page_links(pfn_to_page(pfn), zone_idx(zone), nid, pfn);
-	}
 
 	set_zone_contiguous(zone);
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#3 lore raw

Re: [PATCH 2/2] mm/memory_hotplug: remove duplicate call for set_page_links

Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Fri, 16 Jun 2017 17:23:35 +0800 Wei Yang <[email protected]> wrote:

In function move_pfn_range_to_zone(), memmap_init_zone() will call set_page_links for each page.

Quoted 7 lines

Well, no. There are several types of pfn's for which memmap_init_zone() will not call __init_single_page()->set_page_links(). Probably the code is OK, as those are pretty screwy pfn types. But I'd like to see some confirmation that this patch is OK for all such pfns, now and in the future?

Hmm... when memmap_init_zone() is called during hotplug, this means (context != MEMMAP_EARLY). So it will jump to the end and call __init_single_page().

Is my understanding corrent?

Quoted 20 lines
Quoted 20 lines

This means we don't need to call it on each
page explicitly.

This patch just removes the loop.

...

mm/memory_hotplug.c +0 -4
@@ -914,10 +914,6 @@ void __ref move_pfn_range_to_zone(struct zone *zone,
 	 * are reserved so nobody should be touching them so we should be safe
 	 */
 	memmap_init_zone(nr_pages, nid, zone_idx(zone), start_pfn, MEMMAP_HOTPLUG);
-	for (i = 0; i < nr_pages; i++) {
-		unsigned long pfn = start_pfn + i;
-		set_page_links(pfn_to_page(pfn), zone_idx(zone), nid, pfn);
-	}
 
 	set_zone_contiguous(zone);
 }
Signature · 2 lines
Wei Yang
Help you, Help me
Acked-by
#4 lore raw

Re: [PATCH 2/2] mm/memory_hotplug: remove duplicate call for set_page_links

In reply to Andrew Morton
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Fri, 16 Jun 2017 17:23:35 +0800 Wei Yang <[email protected]> wrote:

In function move_pfn_range_to_zone(), memmap_init_zone() will call set_page_links for each page.

Well, no. There are several types of pfn's for which memmap_init_zone() will not call __init_single_page()->set_page_links(). Probably the code is OK, as those are pretty screwy pfn types. But I'd like to see some confirmation that this patch is OK for all such pfns, now and in the future?

Yes it work properly for the hotplugable memory. If not then it is memmap_init_zone to be fixed rather than duplicate the thig outside of this function.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/2
#5 lore raw
In reply to Wei Yang
Quoted 5 lines · Wei Yang

To make sure a range intersects a zone, only two comparison is necessary.

This patch simplifies the function a little.

Quoted 29 lines
---
 include/linux/mmzone.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
include/linux/mmzone.h +3 -7
index 0176a2933c61..7e8f100cb56d 100644
@@ -541,15 +541,11 @@ static inline bool zone_intersects(struct zone *zone,
 {
 	if (zone_is_empty(zone))
 		return false;
-	if (start_pfn >= zone_end_pfn(zone))
+	if (start_pfn >= zone_end_pfn(zone) ||
+	    start_pfn + nr_pages <= zone->zone_start_pfn)
 		return false;
 
-	if (zone->zone_start_pfn <= start_pfn)
-		return true;
-	if (start_pfn + nr_pages > zone->zone_start_pfn)
-		return true;
-
-	return false;
+	return true;
 }
 
 /*
Signature · 1 line
2.11.0
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>