The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] mm: don't apply task mempolicy to unmovable kernel allocations
@ 2026-07-01 22:21 Gregory Price
  2026-07-01 22:21 ` [PATCH 1/2] mm/filemap: place page-cache folios via an explicit mempolicy Gregory Price
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Gregory Price @ 2026-07-01 22:21 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, linux-fsdevel, kernel-team, willy, jack, akpm,
	david, ziy, matthew.brost, joshua.hahnjy, rakie.kim, byungchul,
	gourry, ying.huang, apopple, Johannes Weiner

This series stops a task's NUMA mempolicy from steering incidental,
global kernel allocations that have no real relationship to the task.

VMA-less allocations (alloc_pages(), folio_alloc(), vmalloc(), slab
refils) - fall back to the current task's mempolicy as their only
placement hint.

This sweeps in kernel memory that is not the task's:
  - unaccounted slab
  - kernel page tables
  - driver GFP_KERNEL buffers
  - one-off global structures
  - etc

On a uniform multi-socket system this is not implicitly harmful.
On a tiered-memory system a task's interleave/bind can push these
incidental allocations onto slower tiers and cause regressions.

The memory may outlive the task, or be shared by others, yet a single
task's policy dictated where it landed.  

The fix is to only follow the task policy for allocations that are
plausibly the task's:

  - movable allocations (mostly user data), and
  - allocations explicitly tied to the task via __GFP_ACCOUNT.

Everything else (unmovable and unaccounted) prefers node-local.

Cpuset still enforces any hard confinements (ALLOC_CPUSET), and
fallback allocations may still cause spillage, but this at least
prevents interleave policies from making poor placements.

Patch 1 makes page-cache placement explicit in filemap to retain
existing behavior (pagecache and metadata still end up following
the task mempolicy).  Since the metadata can be significant on
some systems, retaining this behavior will ensure there are no
surprises for existing users.

If we want to change this behavior, this patch is droppable.

Patch 2 adds the alloc_task_policy() filter for bare allocations.

Test 1: Page cache follows the task policy (unchanged)
======
A process running on node0 but bound to node1:
   (numactl --cpunodebind=0 --membind=1) writes a 1.2G file.

  membind=1 (non-local):  FilePages  node0 +0MB     node1 +1200MB
  membind=0 (control):    FilePages  node0 +1200MB  node1 +0MB 


Test 2: Incidental kernel allocations no longer follow it (changed)
======
Added a debugfs interface to do movable and kernel allocations:

 w/ --cpunodebind=0
 numactl ... --membind=1      echo 100000 > .../alloc_kernel
 numactl ... --membind=1      echo 100000 > .../alloc_movable
 numactl ... --interleave=all echo 100000 > .../alloc_kernel

                       GFP_KERNEL          GFP_HIGHUSER_MOVABLE
membind=1    base:     node1 (follows)     node1
             patched:  node0 (local)       node1 (follows)

interleave   base:     50/50 (follows)     50/50
             patched:  node0 (local)       50/50 (follows)

Movable (user) allocations are unaffected in every case.

The unmovable unaccounted kernel allocations stop following the
task policy and place node-local. With no policy set, both place
node-local as before.

Suggested-by: Johannes Weiner <hannes@cmpxchg.org>

Gregory Price (2):
  mm/filemap: place page-cache folios via an explicit mempolicy
  mm/mempolicy: skip task mempolicy for unmovable unaccounted kernel
    allocations

 mm/filemap.c   |  5 ++++-
 mm/mempolicy.c | 40 ++++++++++++++++++++++++++++------------
 2 files changed, 32 insertions(+), 13 deletions(-)

--
2.53.0-Meta


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

end of thread, other threads:[~2026-07-09 17:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 22:21 [PATCH 0/2] mm: don't apply task mempolicy to unmovable kernel allocations Gregory Price
2026-07-01 22:21 ` [PATCH 1/2] mm/filemap: place page-cache folios via an explicit mempolicy Gregory Price
2026-07-01 22:21 ` [PATCH 2/2] mm/mempolicy: skip task mempolicy for unmovable unaccounted kernel allocations Gregory Price
2026-07-09 11:09 ` [PATCH 0/2] mm: don't apply task mempolicy to unmovable " Huang, Ying
2026-07-09 17:32   ` Gregory Price

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