mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/numa: Fix scan period for remote private faults
@ 2026-08-04  3:07 Hongling Zeng
  2026-08-04  3:44 ` Zhan Xusheng
  0 siblings, 1 reply; 3+ messages in thread
From: Hongling Zeng @ 2026-08-04  3:07 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, kprateek.nayak
  Cc: linux-kernel, zhongling0719, Hongling Zeng

The early return condition in update_task_scan_period() incorrectly
slows down NUMA scanning for workloads with pure remote private memory
accesses.

Current condition:
    if (local + shared == 0 || p->numa_faults_locality[2])

For a workload accessing only private memory on remote nodes:
- shared = 0 (no shared accesses)
- local = 0 (all accesses are remote)
- Result: condition is TRUE, scan period doubles (slower)

This is wrong because for remote private memory, we should continue
to the ratio calculation which can speed up scanning to migrate the
memory to the local node.

The fix checks if there are actual faults (local + remote > 0) before
slowing down the scan rate. If there are faults, we should continue
to the ratio calculation logic to make an informed decision.

Also update the comments for ps_ratio and lr_ratio checks which appear
to be swapped - ps_ratio checks private/shared ratio not local accesses,
and lr_ratio checks local/remote ratio not shared accesses.

Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 kernel/sched/fair.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 37001c63452e..1fafaeb8d645 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3505,9 +3505,13 @@ static void update_task_scan_period(struct task_struct *p,
 	 * completely idle or all activity is in areas that are not of interest
 	 * to automatic numa balancing. Related to that, if there were failed
 	 * migration then it implies we are migrating too quickly or the local
-	 * node is overloaded. In either case, scan slower
+	 * node is overloaded. In either case, scan slower.
+	 *
+	 * Slow down if there are no actual memory faults (local + remote == 0),
+	 * or if previous migrations failed. Otherwise, use the locality ratios
+	 * to decide whether the scan rate should be adjusted.
 	 */
-	if (local + shared == 0 || p->numa_faults_locality[2]) {
+	if (local + remote == 0 || p->numa_faults_locality[2]) {
 		p->numa_scan_period = min(p->numa_scan_period_max,
 			p->numa_scan_period << 1);
 
@@ -3529,8 +3533,8 @@ static void update_task_scan_period(struct task_struct *p,
 
 	if (ps_ratio >= NUMA_PERIOD_THRESHOLD) {
 		/*
-		 * Most memory accesses are local. There is no need to
-		 * do fast NUMA scanning, since memory is already local.
+		 * Most memory accesses are private. Slow down NUMA scanning
+		 * since there is little shared memory to rebalance.
 		 */
 		int slot = ps_ratio - NUMA_PERIOD_THRESHOLD;
 		if (!slot)
@@ -3538,8 +3542,9 @@ static void update_task_scan_period(struct task_struct *p,
 		diff = slot * period_slot;
 	} else if (lr_ratio >= NUMA_PERIOD_THRESHOLD) {
 		/*
-		 * Most memory accesses are shared with other tasks.
-		 * There is no point in continuing fast NUMA scanning,
+		 * Most memory accesses are local. There is no need to
+		 * do fast NUMA scanning, since memory is already local.
+		 * Also, shared memory may be moved by other tasks anyway,
 		 * since other tasks may just move the memory elsewhere.
 		 */
 		int slot = lr_ratio - NUMA_PERIOD_THRESHOLD;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-04  6:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-04  3:07 [PATCH] sched/numa: Fix scan period for remote private faults Hongling Zeng
2026-08-04  3:44 ` Zhan Xusheng
2026-08-04  6:07   ` Hongling Zeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®