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 0/8] sched/numa: Placement signal for memory that NUMA balancing cannot migrate
Date: Sun, 06 Dec 2026 06:38:37 -0500	[thread overview]
Message-ID: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev> (raw)

NUMA balancing finds out where the memory of a task lives through
hinting faults, so it has nothing to go on for memory it never makes
fault: DMA pinned folios (VFIO, RDMA, io_uring registered buffers),
hugetlb pages and DAX mappings. A task working on such memory gets no
preferred node from it, and the load balancer moves it wherever CPUs are
idle, often to the other package, where every access stays remote
because the memory cannot follow.

This matters most on machines with several NUMA nodes per package, where
every die has its own memory controller (SLIT 10/15/25/27 for 2 packages
of 4 dies), and for workloads that pin or use hugetlb memory by design:
VMs with hugetlb and VFIO, RDMA and io_uring users, DAX.

Patches 1-4 sample the accessed bits of such memory from
task_numa_work() instead of making it fault: no hinting PTE is installed
and nothing is migrated, which keeps the reason for commit 03aa8e4f2732
("mm: mprotect: always skip dma pinned folio in prot_numa_skip()"), and
the accessed pages are accounted as faults on their node. Secondary MMUs
are tested, not cleared. Patches 5-7 record when most faults of a task
hit memory that cannot move, and keep such tasks inside the lowest NUMA
domain around their preferred node, in NUMA placement and in load
balancing alike; within that domain they are still spread as usual.
Patch 8 shares the samples between the threads of a process, so that all
of them get the signal and the protection, not only the one that ran the
scan.

Tested in a VM with 2 packages of 4 nodes (8 vCPUs and 4 LLCs per node,
SLIT 10/15/25/27, guest memory on host huge pages), all numbers from one
run alternating the kernels. Single tasks copying within 3-4 GiB of
pinned, hugetlb or DAX memory on another node (patches 1-3) settle on it
in every run, and the slowest of 6-9 runs copies 43-52% faster. A nested
guest copying in the part of its hugetlb memory on the other package
follows it there in every run and copies 35% faster (patch 4). Patches
5-7 act only on threads that have samples of their own, so in
multi-threaded processes their effect shows together with patch 8.

For processes where each thread pins 1 GiB on node 0 or maps it from
hugetlb and times 2^20 dependent loads through it starting from node 4,
the table compares mainline with the whole series: median (range) of
per-thread means over 3 alternating rounds of 25 s, cache-aware
scheduling off; "worst" is the slowest thread. Copy loops over the same
memory, bound by bandwidth, change by -14% to +0%, and hackbench with 16
groups takes 0.957 s against 0.959 s. With cache-aware scheduling on,
the medians change by -34%, -38%, -9% and -26% and the worst threads by
-49%, -36%, -43% and -42%, with 92-95% of run time on the package:

                    before          after  median   worst  on package (%)
  threads       chase (ms)     chase (ms)  change  change   before  after
  pinned 4   211 (111-229)  122 (117-130)    -42%    -43%       31     96
  pinned 8   212 (122-231)  142 (131-149)    -33%    -35%       41     94
  hugetlb 4  126 (115-222)  115 (113-125)     -9%    -44%       62     96
  hugetlb 8  132 (116-223)  124 (116-130)     -6%    -42%       61     92

Cache-aware scheduling (CONFIG_SCHED_CACHE) aggregates the threads of a
process in one LLC by their CPU time and steps aside for processes whose
footprint exceeds the LLC; this series is about which node holds DRAM
the task uses, typically gigabytes. They meet in can_migrate_task(),
where migrate_strands_memory() is checked before migrate_degrades_llc().

Tried and dropped:
- Packing such tasks onto the memory node by allowing an imbalance up to
  imb_numa_nr instead of NUMA_IMBALANCE_MIN. On top of this series it
  leaves pointer chasing within 2% and makes copy loops 10-19% slower.
- Clearing accessed bits of secondary MMUs instead of testing them: the
  same placement and copy times (133 ms against 134 ms) when the L1
  memory is backed by huge pages, but with a 4K-backed L1 copy rounds of
  about 285 ms in the L2 guest took 406-841 ms every 2.5-4.8 s.
- Device memory mappings (VM_IO/VM_PFNMAP, e.g. VFIO BARs) through a new
  vm_operations_struct callback: implemented, not pursued.

Limitations:
- Measured in VMs only, on an AMD host; same-package remote latency
  there is 5-13% over local.
- Threads that share pinned memory cannot be told apart, so the samples
  are split evenly: when each thread uses memory on a different node,
  every thread gets the same mixed signal.

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
Qiliang Yuan (8):
      sched/numa: Sample the accessed bits of pinned memory
      sched/numa: Cover hugetlb mappings with accessed-bit sampling
      sched/numa: Extend accessed-bit sampling to DAX mappings
      mm/mempolicy: consult secondary MMUs when sampling accessed bits
      sched/numa: Track whether the memory of a task can follow it
      sched/numa: Keep tasks near memory that cannot follow them
      sched/fair: Avoid pulling tasks away from memory that cannot follow them
      sched/numa: Share sampled accesses between the threads of a process

 include/linux/mm.h                   |   3 +
 include/linux/mm_types.h             |  10 ++
 include/linux/sched.h                |  11 ++
 include/linux/sched/numa_balancing.h |   1 +
 kernel/fork.c                        |   7 ++
 kernel/sched/fair.c                  | 218 ++++++++++++++++++++++++++++++++++-
 mm/mempolicy.c                       | 154 +++++++++++++++++++++++++
 7 files changed, 400 insertions(+), 4 deletions(-)
---
base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
change-id: 20261201-feat-numab-series-56b943ff20f5

Best regards,
-- 
Qiliang Yuan <qiliang.yuan@linux.dev>


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

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 11:38 Qiliang Yuan [this message]
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 ` [PATCH 5/8] sched/numa: Track whether the memory of a task can follow it Qiliang Yuan
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-0-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®