From: Pranith Kumar <bobby.prani@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Rik van Riel <riel@surriel.com>,
Harry Yoo <harry@kernel.org>, Jann Horn <jannh@google.com>,
Lance Yang <lance.yang@linux.dev>,
Richard Cochran <richardcochran@gmail.com>,
linux-mm@kvack.org (open list:MEMORY MANAGEMENT - CORE),
linux-kernel@vger.kernel.org (open list),
netdev@vger.kernel.org (open list:PTP HARDWARE CLOCK
SUPPORT:Keyword:(?:\b|_)ptp(?:\b|_))
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [RFC PATCH] mm/rmap: use release ordering for small-folio mapcount removal
Date: Tue, 3 Nov 2026 17:31:38 -0800 [thread overview]
Message-ID: <20261104013139.1341582-1-bobby.prani@gmail.com> (raw)
Removing a PTE mapping must precede lowering its folio's mapcount.
The COW path relies on this order to keep the old page from being
reused while a stale translation can still access it. The mapcount
update needs release ordering for that edge, rather than the full
ordering of atomic_add_negative().
Use atomic_add_negative_release() for non-large folios removed at PTE
level. Leave large-folio operations fully ordered; their path can
queue a partially mapped folio for deferred splitting. Update the
COW ordering comment to describe the required guarantee.
In an arm64 page map/unmap microbenchmark with 20,480 minor
faults, simulated cycles fell by 1.54%.
Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
mm/memory.c | 4 ++--
mm/rmap.c | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index b65b56fe9714..9e23c64bc743 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4158,9 +4158,9 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)
* threads.
*
* The critical issue is to order this
- * folio_remove_rmap_pte() with the ptp_clear_flush
+ * folio_remove_rmap_pte() with the ptep_clear_flush
* above. Those stores are ordered by (if nothing else,)
- * the barrier present in the atomic_add_negative
+ * the release ordering of the mapcount decrement
* in folio_remove_rmap_pte();
*
* Then the TLB flush in ptep_clear_flush ensures that
diff --git a/mm/rmap.c b/mm/rmap.c
index 1131b76bbbc2..62e623d7563b 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1794,7 +1794,8 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
switch (level) {
case PGTABLE_LEVEL_PTE:
if (!folio_test_large(folio)) {
- nr = atomic_add_negative(-1, &folio->_mapcount);
+ /* Publish the PTE removal before lowering mapcount. */
+ nr = atomic_add_negative_release(-1, &folio->_mapcount);
break;
}
--
2.47.3
next reply other threads:[~2026-11-04 1:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 1:31 Pranith Kumar [this message]
2026-11-04 9:16 ` [RFC PATCH] mm/rmap: use release ordering for small-folio mapcount removal David Hildenbrand (Arm)
2026-11-04 9:46 ` Pranith Kumar
2026-11-04 13:37 ` David Hildenbrand (Arm)
2026-11-04 13:55 ` Lorenzo Stoakes (ARM)
2026-11-04 16:51 ` Pranith Kumar
2026-11-04 17:08 ` Pedro Falcato
2026-11-04 17:15 ` Lorenzo Stoakes (ARM)
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=20261104013139.1341582-1-bobby.prani@gmail.com \
--to=bobby.prani@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/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