Skip to contentSkip to conversation

Some small improvements for compaction

PATCH Applied Baolin Wang 3 participants 11 messages Jan 10, 2023 – Jan 11, 2023

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/5 mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()

In reply to Baolin Wang

The compaction_suitable() will never return values other than COMPACT_SUCCESS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_suitable().

---
 mm/compaction.c | 3 ---
 1 file changed, 3 deletions(-)
mm/compaction.c +0 -3
index 62a61de44658..5e6f5e35748d 100644
@@ -2313,9 +2313,6 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
 	if (ret == COMPACT_SUCCESS || ret == COMPACT_SKIPPED)
 		return ret;
 
-	/* huh, compaction_suitable is returning something unexpected */
-	VM_BUG_ON(ret != COMPACT_CONTINUE);
-
 	/*
 	 * Clear pageblock skip if there were failures recently and compaction
 	 * is about to be retried after being deferred.
Signature · 1 line
2.27.0
#7 lore raw

PATCH 2/5 mm: compaction: Move list validation into compact_zone()

In reply to Baolin Wang

Move the cc.freepages and cc.migratepages list validation into compact_zone() to remove some duplicate code.

---
 mm/compaction.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
mm/compaction.c +3 -12
index 5e6f5e35748d..f8e8addc8664 100644
@@ -2488,6 +2488,9 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
 
 	trace_mm_compaction_end(cc, start_pfn, end_pfn, sync, ret);
 
+	VM_BUG_ON(!list_empty(&cc->freepages));
+	VM_BUG_ON(!list_empty(&cc->migratepages));
+
 	return ret;
 }
 
@@ -2526,9 +2529,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order,
 
 	ret = compact_zone(&cc, &capc);
 
-	VM_BUG_ON(!list_empty(&cc.freepages));
-	VM_BUG_ON(!list_empty(&cc.migratepages));
-
 	/*
 	 * Make sure we hide capture control first before we read the captured
 	 * page pointer, otherwise an interrupt could free and capture a page
@@ -2659,9 +2659,6 @@ static void proactive_compact_node(pg_data_t *pgdat)
 		cc.zone = zone;
 
 		compact_zone(&cc, NULL);
-
-		VM_BUG_ON(!list_empty(&cc.freepages));
-		VM_BUG_ON(!list_empty(&cc.migratepages));
 	}
 }
 
@@ -2689,9 +2686,6 @@ static void compact_node(int nid)
 		cc.zone = zone;
 
 		compact_zone(&cc, NULL);
-
-		VM_BUG_ON(!list_empty(&cc.freepages));
-		VM_BUG_ON(!list_empty(&cc.migratepages));
 	}
 }
 
@@ -2868,9 +2862,6 @@ static void kcompactd_do_work(pg_data_t *pgdat)
 				     cc.total_migrate_scanned);
 		count_compact_events(KCOMPACTD_FREE_SCANNED,
 				     cc.total_free_scanned);
-
-		VM_BUG_ON(!list_empty(&cc.freepages));
-		VM_BUG_ON(!list_empty(&cc.migratepages));
 	}
 
 	/*
Signature · 1 line
2.27.0
#0 lore raw

cover Some small improvements for compaction

Hi,

When I did some compaction testing, I found some small rooms to improve as well as some code cleanups. Please help to review. Thanks.

Baolin Wang (5):
mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()
mm: compaction: Move list validation into compact_zone()
mm: compaction: Count the migration scaned pages events for proactive
compaction
mm: compaction: Add missing kcompactd wakeup trace event
mm: compaction: Avoid fragmentation score calculation for empty zones

 mm/compaction.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
Signature · 1 line
2.27.0
#10 lore raw

PATCH 5/5 mm: compaction: Avoid fragmentation score calculation for empty zones

There is no need to calculate the fragmentation score for empty zones.

---
 mm/compaction.c | 2 ++
 1 file changed, 2 insertions(+)
mm/compaction.c +2 -0
index 0fd6c81a7809..b758b00a4885 100644
@@ -2025,6 +2025,8 @@ static unsigned int fragmentation_score_node(pg_data_t *pgdat)
 		struct zone *zone;
 
 		zone = &pgdat->node_zones[zoneid];
+		if (!populated_zone(zone))
+			continue;
 		score += fragmentation_score_zone_weighted(zone);
 	}
 
Signature · 1 line
2.27.0
#8 lore raw

PATCH 3/5 mm: compaction: Count the migration scanned pages events for proactive compaction

In reply to Baolin Wang

The proactive compaction will reuse per-node kcompactd threads, so we should also count the KCOMPACTD_MIGRATE_SCANNED and KCOMPACTD_FREE_SCANNED events for proactive compaction.

---
 mm/compaction.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/compaction.c +5 -0
index f8e8addc8664..62f6bb68c9cb 100644
@@ -2659,6 +2659,11 @@ static void proactive_compact_node(pg_data_t *pgdat)
 		cc.zone = zone;
 
 		compact_zone(&cc, NULL);
+
+		count_compact_events(KCOMPACTD_MIGRATE_SCANNED,
+				     cc.total_migrate_scanned);
+		count_compact_events(KCOMPACTD_FREE_SCANNED,
+				     cc.total_free_scanned);
 	}
 }
 
Signature · 1 line
2.27.0
#9 lore raw

PATCH 4/5 mm: compaction: Add missing kcompactd wakeup trace event

In reply to Baolin Wang

Add missing kcompactd wakeup trace event for proactive compaction, meanwhile use order = -1 and the highest zone index of the pgdat for the kcompactd wakeup trace event by proactive compaction.

---
 mm/compaction.c | 2 ++
 1 file changed, 2 insertions(+)
mm/compaction.c +2 -0
index 62f6bb68c9cb..0fd6c81a7809 100644
@@ -2730,6 +2730,8 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write,
 				continue;
 
 			pgdat->proactive_compact_trigger = true;
+			trace_mm_compaction_wakeup_kcompactd(pgdat->node_id, -1,
+							     pgdat->nr_zones - 1);
 			wake_up_interruptible(&pgdat->kcompactd_wait);
 		}
 	}
Signature · 1 line
2.27.0
#2 lore raw

Re: [PATCH 1/5] mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()

In reply to Baolin Wang
Quoted 4 lines · Baolin Wang

The compaction_suitable() will never return values other than COMPACT_SUCCESS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_suitable().

I don't understand why we'd remove this check.

Quoted 23 lines
---
 mm/compaction.c | 3 ---
 1 file changed, 3 deletions(-)
mm/compaction.c +0 -3
index 62a61de44658..5e6f5e35748d 100644
@@ -2313,9 +2313,6 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
 	if (ret == COMPACT_SUCCESS || ret == COMPACT_SKIPPED)
 		return ret;
 
-	/* huh, compaction_suitable is returning something unexpected */
-	VM_BUG_ON(ret != COMPACT_CONTINUE);
-
 	/*
 	 * Clear pageblock skip if there were failures recently and compaction
 	 * is about to be retried after being deferred.
Signature · 1 line
2.27.0
maintainer
#3 lore raw

Re: [PATCH 1/5] mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()

Quoted 7 lines · On Tue, 10 Jan 2023 13:37:57 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 4 lines · Baolin Wang

The compaction_suitable() will never return values other than COMPACT_SUCCESS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_suitable().

I don't understand why we'd remove this check.

Well, just from code inspection it serves no purpose.

Such an assertion might be useful during early code development, but I think we can consider compaction_suitable() to adequately debugged by now?

#4 lore raw

Re: [PATCH 1/5] mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()

Quoted 8 lines · Andrew Morton
Quoted 6 lines · On Tue, 10 Jan 2023 13:37:57 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 4 lines · Baolin Wang

The compaction_suitable() will never return values other than COMPACT_SUCCESS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_suitable().

Quoted 7 lines
Quoted 1 line

I don't understand why we'd remove this check.

Well, just from code inspection it serves no purpose.

Such an assertion might be useful during early code development, but I think we can consider compaction_suitable() to adequately debugged by now?

What if compaction_suitable() is modified to return another value? This seems like a relatively innocuous check.

#5 lore raw

Re: [PATCH 1/5] mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()

Quoted 11 lines · Matthew Wilcox
Quoted 10 lines · Andrew Morton
Quoted 7 lines · On Tue, 10 Jan 2023 13:37:57 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 4 lines · Baolin Wang

The compaction_suitable() will never return values other than COMPACT_SUCCESS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_suitable().

I don't understand why we'd remove this check.

Quoted 7 lines
Quoted 5 lines

Well, just from code inspection it serves no purpose.

Such an assertion might be useful during early code development, but I think we can consider compaction_suitable() to adequately debugged by now?

What if compaction_suitable() is modified to return another value?

Then this will be an expected value which should be handled by caller, and IMO we can not make such assumption for future to keep this unhelpful check.

maintainer
#6 lore raw

Re: [PATCH 1/5] mm: compaction: Remove redundant VM_BUG_ON() in compact_zone()

Quoted 20 lines · On Wed, 11 Jan 2023 14:40:20 +0800 Baolin Wang <[email protected]>…
Quoted 17 lines · Matthew Wilcox
Quoted 15 lines · Andrew Morton
Quoted 7 lines · On Tue, 10 Jan 2023 13:37:57 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 4 lines · Baolin Wang

The compaction_suitable() will never return values other than COMPACT_SUCCESS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_suitable().

I don't understand why we'd remove this check.

Well, just from code inspection it serves no purpose.

Such an assertion might be useful during early code development, but I think we can consider compaction_suitable() to adequately debugged by now?

Quoted 5 lines
Quoted 1 line

What if compaction_suitable() is modified to return another value?

Then this will be an expected value which should be handled by caller, and IMO we can not make such assumption for future to keep this unhelpful check.

One way of looking at this: if the assertion wasn't there and someone sent a patch which added it, would we merge the patch?

"[patch] add check for compaction_suitable() return value"

"why"

"it might be wrong"

"it isn't"

"but we might make it wrong later"

"the same can be said of every function in the kernel"

And if we wouldn't merge a hypothetical patch which adds some code, we shouldn't retain that code, no?