[PATCH v2 3/4] sched/numa: scan read-only file mappings in tiering mode

From: Gregory Price

Date: Thu Sep 10 2026 - 20:22:53 EST


From: "Gregory Price (Meta)" <gourry@xxxxxxxxxx>

Commit 4591ce4f2d22 ("sched/numa: Do not trap hinting faults for
shared libraries") excludes read-only file mappings from NUMA hinting to
prevent placement bouncing. This also hides hot file folios on slow memory
from the tiering code.

Scan these mappings when memory tiering is enabled, but make their scans
promotion-only. Ordinary NUMA placement retains the existing restriction.

On a host with 768 GB of DRAM and 256 GB of CXL memory running a roughly
430 GB database service, 169 MB of its 185 MB main binary accumulated on
CXL before this change. Afterwards its tier residency tracked runtime load.

Fixes: c574bbe91703 ("NUMA balancing: optimize page placement for memory tiering system")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: LLM
Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
kernel/sched/fair.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 81359b414947..e636e8de53f1 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4061,6 +4061,16 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
p->numa_faults_locality[local] += pages;
}

+/*
+ * Read-only file-backed mappings are expected to be cache replicated between
+ * accessor nodes, so they are not worth sampling for placement. They can
+ * still strand on the slow tier like anything else.
+ */
+static bool vma_is_ro_file(struct vm_area_struct *vma)
+{
+ return vma->vm_file && (vma->vm_flags & (VM_READ | VM_WRITE)) == VM_READ;
+}
+
static void reset_ptenuma_scan(struct task_struct *p)
{
/*
@@ -4220,13 +4230,13 @@ static void task_numa_work(struct callback_head *work)
}

/*
- * Shared library pages mapped by multiple processes are not
- * migrated as it is expected they are cache replicated. Avoid
- * hinting faults in read-only file-backed mappings or the vDSO
- * as migrating the pages will be of marginal benefit.
+ * Read-only file-backed folios are poor NUMA placement
+ * candidates, but slow-tier folios still need to be scanned for
+ * promotion.
*/
if (!vma->vm_mm ||
- (vma->vm_file && (vma->vm_flags & (VM_READ|VM_WRITE)) == (VM_READ))) {
+ (vma_is_ro_file(vma) &&
+ !(numab_mode & NUMA_BALANCING_MEMORY_TIERING))) {
trace_sched_skip_vma_numa(mm, vma, NUMAB_SKIP_SHARED_RO);
continue;
}
@@ -4306,7 +4316,8 @@ static void task_numa_work(struct callback_head *work)
continue;
}

- promo_only = !(numab_mode & NUMA_BALANCING_NORMAL);
+ promo_only = !(numab_mode & NUMA_BALANCING_NORMAL) ||
+ vma_is_ro_file(vma);

do {
start = max(start, vma->vm_start);
--
2.55.0