Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: david@kernel.org
Cc: liam@infradead.org, vbabka@kernel.org, rppt@kernel.org,
	mhocko@suse.com, akpm@linux-foundation.org, mgorman@suse.de,
	peterz@infradead.org, riel@surriel.com,
	ying.huang@linux.alibaba.com, ziy@nvidia.com,
	baolin.wang@linux.alibaba.com, gourry@gourry.net,
	joshua.hahnjy@gmail.com, rakie.kim@sk.com, linux-mm@kvack.org,
	simon.inizan@arm.com
Subject: Re: [PATCH] mm/memory: don't clear the last cpupid in wp_page_reuse()
Date: Sat,  5 Dec 2026 14:37:39 +0800	[thread overview]
Message-ID: <20261205063739.19315-1-lance.yang@linux.dev> (raw)
In-Reply-To: <20261204-wp_reuse_cpupid-v1-1-c56ab5b5d79f@kernel.org>


On Fri, Dec 04, 2026 at 02:29:52PM +0100, 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().

Cool! Also stops wp_page_reuse() from clobbering the page access time of
folios on slow memory nodes in memory tiering mode :)

>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>
>---

Nice work!

Reviewed-by: Lance Yang <lance.yang@linux.dev>


      reply	other threads:[~2026-12-05  6:37 UTC|newest]

Thread overview: 2+ 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 [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=20261205063739.19315-1-lance.yang@linux.dev \
    --to=lance.yang@linux.dev \
    --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