From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
"Cenk Yılmaz" <cenk@deepfinresearch.com>,
"Zhang Peng" <zippermonkey@icloud.com>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Zi Yan" <ziy@nvidia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Joshua Hahn" <joshua.hahnjy@gmail.com>,
"Byungchul Park" <byungchul@sk.com>,
"Gregory Price" <gourry@gourry.net>,
"Ying Huang" <ying.huang@linux.alibaba.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Chris Li" <chrisl@kernel.org>,
"Kairui Song" <kasong@tencent.com>,
"Kemeng Shi" <shikemeng@huaweicloud.com>,
"Nhat Pham" <nphamcs@gmail.com>,
"Baoquan He" <baoquan.he@linux.dev>,
"Barry Song" <baohua@kernel.org>,
"Youngjun Park" <youngjun.park@lge.com>,
"Mel Gorman" <mgorman@suse.de>,
"Sasha Levin" <sasha.levin@oracle.com>,
"Ingo Molnar" <mingo@kernel.org>, "Peter Xu" <peterx@redhat.com>,
"Hugh Dickins" <hughd@google.com>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Hocko" <mhocko@kernel.org>,
"Qi Zheng" <qi.zheng@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Thomas Gleixner" <tglx@kernel.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
"David Hildenbrand (Arm)" <david@kernel.org>
Subject: [PATCH v2 0/2] mm: fixes for stale TLB entries due to delayed/batched TLB flushes
Date: Tue, 01 Dec 2026 17:25:04 +0100 [thread overview]
Message-ID: <20261201-file_folio_flush-v2-0-994d587aec8e@kernel.org> (raw)
These are the two remaining fixes from v1, whereby we fix two stale TLB
issues with TTU_BATCH_FLUSH during reclaim.
Patch #1: Don't defer TLB flushes when unmapping lazyfree folios. Handles
mapping a new anon folio after reclaim discarded a lazyfree folio
(do_anonymous_page(), migrate_vma_insert_page(), UFFDIO_COPY,
UFFDIO_MOVE).
Patch #2: Unlock unmapped folios only after the deferred TLB flush. Handles
refaulting a new page-cache folio, CoW of a folio that is still
in the page-cache, and swapping in a new folio (do_swap_page(),
unuse_pte(), UFFDIO_CONTINUE). Also handles invalidation
replacing a folio that reclaim kept, and write() modifying a new
page-cache folio.
There is one remaining problem that I describe in the cover letter of
v1 in detail.
Testing
-------
I threw a bunch of selftests at it and had AI generate some stress
tests, in particular for the benchmarks below. I also ran stress-ng to
force reclaim.
I managed to reproduce both issues, as described in the patch descriptions.
Stale reads out of 1024000 checked pages in 2000 iterations:
base series
lazyfree, MGLRU 16242 0
lazyfree, classic LRU 16274 0
swapcache, MGLRU 24076 0
swapcache, classic LRU 23028 0
Performance Impact
------------------
I ran some benchmarks on v1 in an x86-64 VM with limited CPUs, RAM and
zram enabled. Running inside a VM might make TLB flushes more expensive,
so the results below might be a bit exaggerated. AI results below.
Classic LRU, 4 threads randomly touching a working set twice the size of
their memcg for 30 seconds. Pages touched per second:
base series
anon-rw 681k 1055k
anon-ro 1013k 1027k
file-ro 417k 419k
file-rw 173k 183k
lazyfree 1512k 333k
Swapping out dirty anon folios ("anon-rw") is about 55% faster, because
patch #2 now also batches TLB flushes of stale writable TLB entries.
That is what Zhang Peng's series [1] tried to achieve, and his work also
inspired how patch #2 locks folios again, but the used mechanism is
different.
Reclaiming clean anon folios ("anon-ro"), clean page-cache folios
("file-ro") and dirty page-cache folios ("file-rw") is not noticeably
affected.
Reclaiming lazyfree folios ("lazyfree") is about 4.5x slower, because
we stop batching TLB flushes when discarding them entirely, which seems
to be the right thing to do for now. We can look into optimizing this
separately later.
Kairui tested v1 as well on x86-64 under memory pressure (40 GiB in one
process with swap, 4 processes concurrently, and 4 memcg-limited cgroups
reclaiming concurrently) [2]: TLB shootdown IPIs dropped by 90% and wall
time by 30%. Reclaiming clean page-cache folios seemed unchanged, and on
arm64 nothing changed either.
[1] https://lore.kernel.org/linux-mm/20261031-batch-tlb-flush-v6-0-190539839eec@tencent.com/
[2] https://lore.kernel.org/linux-mm/CAMgjq7DWWCF_iB+GmTciuXr=m=uk7mMmidvY=8yg6MH98X4oPg@mail.gmail.com/
---
Changes in v2:
- #1 and #2 are upstream now
- Rebase on top of mm-core/for-next
- "mm/rmap: don't defer TLB flushes when unmapping lazyfree folios"
- Avoid line split
- "mm/vmscan: unlock unmapped folios only after the deferred TLB flush"
- Label the three phases in the comments
- Finish reclaiming a batch before collecting more folios, even if
reclaim added folios to folio_list (e.g., splitting a shmem folio)
- Activate folios that went under writeback while unlocked
- Update the description of (c) and drop the outdated migration
example from the patch description now that that stuff is fixed
upstream
- Collect tags
- Link to v1: https://patch.msgid.link/20261118-file_folio_flush-v1-0-e9e739ed14e0@kernel.org
---
David Hildenbrand (Arm) (2):
mm/rmap: don't defer TLB flushes when unmapping lazyfree folios
mm/vmscan: unlock unmapped folios only after the deferred TLB flush
mm/internal.h | 5 ++
mm/rmap.c | 19 ++++++-
mm/shmem.c | 2 +-
mm/swap.h | 5 +-
mm/swapfile.c | 7 ++-
mm/vmscan.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
6 files changed, 197 insertions(+), 16 deletions(-)
---
base-commit: 40e0fcedf9c39c3a4a0100323c101506b4206394
change-id: 20261114-file_folio_flush-7d1749fab2d8
Best regards,
--
David Hildenbrand (Arm) <david@kernel.org>
next reply other threads:[~2026-12-01 16:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 16:25 David Hildenbrand (Arm) [this message]
2026-12-01 16:25 ` [PATCH v2 1/2] mm/rmap: don't defer TLB flushes when unmapping lazyfree folios David Hildenbrand (Arm)
2026-12-01 16:25 ` [PATCH v2 2/2] mm/vmscan: unlock unmapped folios only after the deferred TLB flush David Hildenbrand (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=20261201-file_folio_flush-v2-0-994d587aec8e@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=bp@alien8.de \
--cc=byungchul@sk.com \
--cc=cenk@deepfinresearch.com \
--cc=chrisl@kernel.org \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kasong@tencent.com \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mgorman@suse.de \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@kernel.org \
--cc=nphamcs@gmail.com \
--cc=peterx@redhat.com \
--cc=qi.zheng@linux.dev \
--cc=rppt@kernel.org \
--cc=sasha.levin@oracle.com \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=ying.huang@linux.alibaba.com \
--cc=youngjun.park@lge.com \
--cc=yuanchu@google.com \
--cc=zippermonkey@icloud.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