Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mel Gorman <mgorman@suse.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Rik van Riel <riel@surriel.com>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Gregory Price <gourry@gourry.net>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Rakie Kim <rakie.kim@sk.com>
Cc: linux-mm@kvack.org, Simon Inizan <simon.inizan@arm.com>
Subject: Re: [PATCH] mm/memory: don't clear the last cpupid in wp_page_reuse()
Date: Sat, 5 Dec 2026 13:31:58 +0100	[thread overview]
Message-ID: <09c07ddd-36bf-483b-bb98-7adaf856e1c8@gmail.com> (raw)
In-Reply-To: <20261204-wp_reuse_cpupid-v1-1-c56ab5b5d79f@kernel.org>

On 12/4/26 2:29 PM, David Hildenbrand (Arm) wrote:
> NUMA balancing remembers the lower PID bits of the task that last triggered
> a NUMA hinting fault on a folio alongside the CPU.
> 
> Since 2013 through commit 8c8a743c5087 ("sched/numa: Use {cpu, pid} to
> create task groups for shared faults"), we reset that folio information
> when reusing a folio during a write fault.
> 
> That can result in some suboptimal behavior especially for anon folios:
> 
>   (a) NUMA balancing records the task+CPU and decides to migrate the folio.
> 
>   (b) Migration code maps the folio R/O, and on next write access we
>       reset that information.
> 
>   (c) The next NUMA hinting fault then looks like a first access,
>       so a single access from another node can be enough to trigger the
>       NUMA balancing migration machinery again.
> 
> As Simon Inizan reports, that can result in some unexpected folio
> migration back and forth between NUMA nodes for some workloads.
> 
> The original reasoning why we added that NUMA-hinting information reset was
> that the folio might now belong to an unrelated task. For example, after
> fork() a child might reuse an anonymous folio that its parent last
> accessed, and we don't want to group both tasks.
> 
> However, since commit dabe1d992414 ("sched/numa: Be more careful about
> joining numa groups"), task_numa_group() only groups tasks that share the
> MM or that share the folio through a MAP_SHARED mapping, so a stale cpupid
> can no longer group tasks that merely shared an anonymous folio after
> fork().
> 
> The child's first NUMA hinting fault might still see the stale information,
> such that we treat it as a shared fault and delay migration until a later
> fault. CoW-reuse in the child is less common, so it shouldn't move the
> needle. If we ever care, we could decide based on whether we likely saw
> fork() before, because then we have to set PageAnonExclusive again.
> 
> Further:
> 
>   (1) do_huge_pmd_wp_page() doesn't reset that metadata, so our handling
>       is inconsistent.
>   (2) there are other valid cases where we run into wp_page_reuse()
>       without ever involving fork(), where that information is still
>       perfectly fine.
>   (3) In the context of pte-mapped THPs where we reuse individual pages,
>       it doesn't quite make sense.
> 
> So let's just stop resetting that information in wp_page_reuse().
> 
> Note that task_numa_group() will now also see accesses from different
> tasks that we previously treated as private first accesses, which is how
> it is supposed to work.
> 
> While at it, convert the VM_BUG_ON() to a VM_WARN_ON_ONCE().
> 
> Cc: Simon Inizan <simon.inizan@arm.com>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> ---
> Hi,
> 
> this was reported internally; I don't really consider it a BUG, so
> no Fixes.
> 
> This resolves the issue with repeated migration back and forth that
> Simon was seeing.
> 
> I don't really know which benchmarks to run where we could see a
> regression through this change. Migration might now be delayed until a
> later NUMA hinting fault when a child reuses a folio after fork(), but I
> don't expect that to matter in practice.
> 
> I'd assume most performance-sensitive workloads will use plenty of
> PMD-mapped THPs where the behavior was always like that.
> 
> So in the end this just makes the handling consistent.

LGTM:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>

-- 
cheers,
jose a. p-a


      parent reply	other threads:[~2026-12-05 12:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:29 [PATCH] mm/memory: don't clear the last cpupid in wp_page_reuse() David Hildenbrand (Arm)
2026-12-05  6:37 ` Lance Yang
2026-12-05 12:31 ` Jose A. Perez de Azpillaga [this message]

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=09c07ddd-36bf-483b-bb98-7adaf856e1c8@gmail.com \
    --to=azpijr@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --cc=joshua.hahnjy@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=peterz@infradead.org \
    --cc=rakie.kim@sk.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=simon.inizan@arm.com \
    --cc=vbabka@kernel.org \
    --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