Skip to contentSkip to conversation

mm/hotplug: Adjust shrink_zone_span() to keep the old logic

PATCH NAK Baoquan He 4 participants 10 messages Feb 6, 2020

Subsystems (2)
lore
Share & tools
lore

Baoquan He

author
#0 lore raw

PATCH 1/1 mm/hotplug: Adjust shrink_zone_span() to keep the old logic

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
 	}
 	zone_span_writeunlock(zone);
 }
Signature · 1 line
2.17.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

Quoted 7 lines

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

Quoted 45 lines

---
mm/memory_hotplug.c | 14 ++++++--------

1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
 	}
 	zone_span_writeunlock(zone);
 }
Signature · 1 line
2.17.2
Signature · 2 lines
Wei Yang
Help you, Help me
#2 lore raw
In reply to Baoquan He
Quoted 46 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +1 -6
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 10 lines
mm/memory_hotplug.c +5 -2
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Signature · 3 lines
Thanks,

David / dhildenb
author
#3 lore raw
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
Quoted 8 lines

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Hmm, pfn is initialized as zone->zone_start_pfn, does it matter? The impossible empty zone won't go wrong if it really happen.

#4 lore raw
Quoted 63 lines · Baoquan He
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
Quoted 8 lines

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Quoted 3 lines

Hmm, pfn is initialized as zone->zone_start_pfn, does it matter? The impossible empty zone won't go wrong if it really happen.

If you offline any memory block that belongs to the lowest zone (zone->zone_start_pfn == 0) but does not fall on a boundary (so that you can actually shrink), you would mark the whole zone offline. That's broken unless I am missing something.

Signature · 3 lines
Thanks,

David / dhildenb
author
#5 lore raw
Quoted 64 lines · David Hildenbrand
Quoted 63 lines · Baoquan He
Quoted 61 lines · David Hildenbrand
Quoted 46 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +1 -6
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 10 lines
mm/memory_hotplug.c +5 -2
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Quoted 8 lines
Quoted 3 lines

Hmm, pfn is initialized as zone->zone_start_pfn, does it matter? The impossible empty zone won't go wrong if it really happen.

If you offline any memory block that belongs to the lowest zone (zone->zone_start_pfn == 0) but does not fall on a boundary (so that you can actually shrink), you would mark the whole zone offline. That's broken unless I am missing something.

AFAIK, the page 0 is reserved. No valid zone can start at 0, only empty zone is. Please correct me if I am wrong.

#6 lore raw
Quoted 69 lines · Baoquan He
Quoted 68 lines · David Hildenbrand
Quoted 66 lines · Baoquan He
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
Quoted 8 lines

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Hmm, pfn is initialized as zone->zone_start_pfn, does it matter? The impossible empty zone won't go wrong if it really happen.

Quoted 7 lines
Quoted 4 lines

If you offline any memory block that belongs to the lowest zone (zone->zone_start_pfn == 0) but does not fall on a boundary (so that you can actually shrink), you would mark the whole zone offline. That's broken unless I am missing something.

AFAIK, the page 0 is reserved. No valid zone can start at 0, only empty zone is. Please correct me if I am wrong.

At least on x86 it indeed is :) So if this holds true for all archs

Thanks!

Signature · 3 lines
Thanks,

David / dhildenb
Nacked-by NAK
#7 lore raw
Quoted 75 lines · David Hildenbrand
Quoted 74 lines · Baoquan He
Quoted 72 lines · David Hildenbrand
Quoted 63 lines · Baoquan He
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
Quoted 8 lines

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Quoted 3 lines

Hmm, pfn is initialized as zone->zone_start_pfn, does it matter? The impossible empty zone won't go wrong if it really happen.

If you offline any memory block that belongs to the lowest zone (zone->zone_start_pfn == 0) but does not fall on a boundary (so that you can actually shrink), you would mark the whole zone offline. That's broken unless I am missing something.

Quoted 10 lines
Quoted 2 lines

AFAIK, the page 0 is reserved. No valid zone can start at 0, only empty zone is. Please correct me if I am wrong.

At least on x86 it indeed is :) So if this holds true for all archs

Thanks!

Correction

s390x:
[linux1@rhkvm01 ~]$ cat /proc/zoneinfo
Node 0, zone DMA
per-node stats
[...]
node_unreclaimable: 0
start_pfn: 0

Signature · 3 lines
Thanks,

David / dhildenb
author
#8 lore raw
Quoted 91 lines · David Hildenbrand
Quoted 75 lines · David Hildenbrand
Quoted 74 lines · Baoquan He
Quoted 72 lines · David Hildenbrand
Quoted 63 lines · Baoquan He
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
Quoted 8 lines

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Quoted 3 lines

Hmm, pfn is initialized as zone->zone_start_pfn, does it matter? The impossible empty zone won't go wrong if it really happen.

If you offline any memory block that belongs to the lowest zone (zone->zone_start_pfn == 0) but does not fall on a boundary (so that you can actually shrink), you would mark the whole zone offline. That's broken unless I am missing something.

Quoted 10 lines
Quoted 2 lines

AFAIK, the page 0 is reserved. No valid zone can start at 0, only empty zone is. Please correct me if I am wrong.

At least on x86 it indeed is :) So if this holds true for all archs

Thanks!

Correction

Quoted 7 lines

s390x:
[linux1@rhkvm01 ~]$ cat /proc/zoneinfo
Node 0, zone DMA
per-node stats
[...]
node_unreclaimable: 0
start_pfn: 0

OK, it's very interesting, and good to know. This should be discarded.

#9 lore raw
In reply to David Hildenbrand
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · Baoquan He

In commit 950b68d9178b ("mm/memory_hotplug: don't check for "all holes" in shrink_zone_span()"), the zone->zone_start_pfn/->spanned_pages resetting is moved into the if()/else if() branches, if the zone becomes empty. However the 2nd resetting code block may cause misunderstanding.

So take the resetting codes out of the conditional checking and handling branches just as the old code does, the find_smallest_section_pfn()and find_biggest_section_pfn() searching have done the the same thing as the old for loop did, the logic is kept the same as the old code. This can remove the possible confusion.

---
 mm/memory_hotplug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/memory_hotplug.c +6 -8
index 089b6c826a9e..475d0d68a32c 100644
@@ -398,7 +398,7 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
 static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 			     unsigned long end_pfn)
 {
-	unsigned long pfn;
+	unsigned long pfn = zone->zone_start_pfn;
 	int nid = zone_to_nid(zone);
 
 	zone_span_writelock(zone);
@@ -414,9 +414,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 		if (pfn) {
 			zone->spanned_pages = zone_end_pfn(zone) - pfn;
 			zone->zone_start_pfn = pfn;
-		} else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
 		}
 	} else if (zone_end_pfn(zone) == end_pfn) {
 		/*
@@ -429,10 +426,11 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
 					       start_pfn);
 		if (pfn)
 			zone->spanned_pages = pfn - zone->zone_start_pfn + 1;
-		else {
-			zone->zone_start_pfn = 0;
-			zone->spanned_pages = 0;
-		}
+	}
+
+	if (!pfn) {
+		zone->zone_start_pfn = 0;
+		zone->spanned_pages = 0;
Quoted 9 lines

mm/memory_hotplug.c static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, · line 436

Quoted 4 lines
mm/memory_hotplug.c +0 -0
 	}
 	zone_span_writeunlock(zone);
 }

So, what if your zone starts at pfn 0? Unlikely that we can actually offline that, but still it is more confusing than the old code IMHO. Then I prefer to drop the second else case as discussed instead.

Sorry, I just catch up with this thread.

If zone starts at 0, find_smallest_section_pfn() will be called only when we want to remove the first section [0, secion_size].

Then find_smallest_section_pfn() return value has two possibilities:

* a non-0 section pfn if it still has
* 0 if the zone is empty

This looks good to me.

Or I may misunderstand your point, would you mind sharing more light on your finding?

Thanks :-)

Quoted 4 lines
Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Wei Yang
Help you, Help me