mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Juri Lelli <juri.lelli@redhat.com>,
	 Vincent Guittot <vincent.guittot@linaro.org>,
	Mel Gorman <mgorman@suse.de>,
	 K Prateek Nayak <kprateek.nayak@amd.com>,
	 David Hildenbrand <david@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>,
	 Valentin Schneider <vschneid@redhat.com>,
	Zi Yan <ziy@nvidia.com>,  Gregory Price <gourry@gourry.net>,
	 Ying Huang <ying.huang@linux.alibaba.com>,
	 Kefeng Wang <wangkefeng.wang@huawei.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH 5/8] sched/numa: Track whether the memory of a task can follow it
Date: Sun, 06 Dec 2026 06:38:42 -0500	[thread overview]
Message-ID: <20261206-feat-numab-series-v1-5-2af21ad24718@linux.dev> (raw)
In-Reply-To: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev>

Placement and load balancing for NUMA assume that memory follows a task:
moving a task off its preferred node costs locality only until hinting
faults migrate its pages over.

Memory that is pinned, hugetlb or DAX backed, and memory whose migration
failed, stays where it is, so moving its user away keeps every access
remote. Nothing tells placement and load balancing which tasks are in
that situation.

Record that: sampled accesses are now accounted with a new
TNF_UNMOVABLE flag, and faults with TNF_UNMOVABLE or TNF_MIGRATE_FAIL
add to numa_faults_stuck. At the end of each scan period, when
update_task_scan_period() resets the fault locality counters, fold the
period into sums of such faults and of all faults that are halved every
period like numa_faults, and set numa_mem_stuck while the former are the
majority. The counters of one period are not enough: they are reset
right before placement reads them, and samples arrive with the scans,
so some periods see none and would flip the verdict. Nothing uses
numa_mem_stuck yet.

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 include/linux/sched.h                |  7 +++++++
 include/linux/sched/numa_balancing.h |  1 +
 kernel/sched/fair.c                  | 17 +++++++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index e4f6323d78555..6b10159dc34de 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1434,6 +1434,13 @@ struct task_struct {
 	 * weights depending on whether they were shared or private faults
 	 */
 	unsigned long			numa_faults_locality[3];
+	/* Faults on memory that cannot migrate, reset with numa_faults_locality */
+	unsigned long			numa_faults_stuck;
+	/* Decayed counts of unmovable and of all faults over scan periods */
+	unsigned long			numa_stuck_avg;
+	unsigned long			numa_total_avg;
+	/* Most faults of the last scan period hit memory that cannot move */
+	bool				numa_mem_stuck;
 
 	unsigned long			numa_pages_migrated;
 #endif /* CONFIG_NUMA_BALANCING */
diff --git a/include/linux/sched/numa_balancing.h b/include/linux/sched/numa_balancing.h
index 52b22c5c396db..35cdb3db98276 100644
--- a/include/linux/sched/numa_balancing.h
+++ b/include/linux/sched/numa_balancing.h
@@ -14,6 +14,7 @@
 #define TNF_SHARED	0x04
 #define TNF_FAULT_LOCAL	0x08
 #define TNF_MIGRATE_FAIL 0x10
+#define TNF_UNMOVABLE	0x20
 
 enum numa_vmaskip_reason {
 	NUMAB_SKIP_UNSUITABLE,
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 520728ada00fb..ea483c8dabcf9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3710,8 +3710,15 @@ static void update_task_scan_period(struct task_struct *p,
 			task_scan_min(p), task_scan_max(p));
 
 out:
+	/* Decay like numa_faults so that one quiet period cannot flip it */
+	p->numa_stuck_avg = p->numa_stuck_avg / 2 + p->numa_faults_stuck;
+	p->numa_total_avg = p->numa_total_avg / 2 +
+			    p->numa_faults_locality[0] +
+			    p->numa_faults_locality[1];
+	p->numa_mem_stuck = p->numa_stuck_avg * 2 > p->numa_total_avg;
 	memset(p->numa_faults_locality, 0,
 	       sizeof(p->numa_faults_locality));
+	p->numa_faults_stuck = 0;
 }
 
 /*
@@ -4175,6 +4182,10 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
 
 		p->total_numa_faults = 0;
 		memset(p->numa_faults_locality, 0, sizeof(p->numa_faults_locality));
+		p->numa_faults_stuck = 0;
+		p->numa_stuck_avg = 0;
+		p->numa_total_avg = 0;
+		p->numa_mem_stuck = false;
 	}
 
 	/*
@@ -4214,6 +4225,8 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
 		p->numa_pages_migrated += pages;
 	if (flags & TNF_MIGRATE_FAIL)
 		p->numa_faults_locality[2] += pages;
+	if (flags & (TNF_MIGRATE_FAIL | TNF_UNMOVABLE))
+		p->numa_faults_stuck += pages;
 
 	p->numa_faults[task_faults_idx(NUMA_MEMBUF, mem_node, priv)] += pages;
 	p->numa_faults[task_faults_idx(NUMA_CPUBUF, cpu_node, priv)] += pages;
@@ -4553,8 +4566,8 @@ static void task_numa_work(struct callback_head *work)
 			if (!node_pages[nid])
 				continue;
 			task_numa_fault(-1 & LAST_CPUPID_MASK, nid,
-					node_pages[nid],
-					nid == task_node(p) ? TNF_FAULT_LOCAL : 0);
+					node_pages[nid], TNF_UNMOVABLE |
+					(nid == task_node(p) ? TNF_FAULT_LOCAL : 0));
 		}
 		kfree(node_pages);
 	}

-- 
2.43.0


  parent reply	other threads:[~2026-12-06 11:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 11:38 [PATCH 0/8] sched/numa: Placement signal for memory that NUMA balancing cannot migrate Qiliang Yuan
2026-12-06 11:38 ` [PATCH 1/8] sched/numa: Sample the accessed bits of pinned memory Qiliang Yuan
2026-12-06 11:38 ` [PATCH 2/8] sched/numa: Cover hugetlb mappings with accessed-bit sampling Qiliang Yuan
2026-12-06 11:38 ` [PATCH 3/8] sched/numa: Extend accessed-bit sampling to DAX mappings Qiliang Yuan
2026-12-06 11:38 ` [PATCH 4/8] mm/mempolicy: consult secondary MMUs when sampling accessed bits Qiliang Yuan
2026-12-06 11:38 ` Qiliang Yuan [this message]
2026-12-06 11:38 ` [PATCH 6/8] sched/numa: Keep tasks near memory that cannot follow them Qiliang Yuan
2026-12-06 11:38 ` [PATCH 7/8] sched/fair: Avoid pulling tasks away from " Qiliang Yuan
2026-12-06 11:38 ` [PATCH 8/8] sched/numa: Share sampled accesses between the threads of a process Qiliang Yuan

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=20261206-feat-numab-series-v1-5-2af21ad24718@linux.dev \
    --to=qiliang.yuan@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=bsegall@google.com \
    --cc=david@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=gourry@gourry.net \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.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

all inboxes | Powered by JetHome®