* [PATCH v2] mm/filemap: clear page cache marks once when removing a folio
@ 2026-11-03 0:43 Qiliang Yuan
0 siblings, 0 replies; only message in thread
From: Qiliang Yuan @ 2026-11-03 0:43 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), Jan Kara, Andrew Morton
Cc: linux-fsdevel, linux-mm, linux-kernel, Qiliang Yuan
xas_store() clears the marks of an entry before it replaces the entry
with NULL.
page_cache_delete() calls xas_init_marks() after xas_store() whether it
stored a shadow entry or NULL, so a folio removed without a shadow, as
POSIX_FADV_DONTNEED and drop_caches do, has its marks cleared twice.
With 4K folios that is about 6% of the time it takes to drop clean page
cache.
Call xas_init_marks() only after storing a shadow entry, whose marks
xas_store() leaves alone. Dropping 8 GiB of 4K folios, median of five
runs, averaged over two boots of each kernel, in a 32 vCPU VM:
before after
POSIX_FADV_DONTNEED 1517 ms 1423 ms
drop_caches 1515 ms 1422 ms
Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
V1 -> V2:
- Explain the condition in a comment (Jan Kara)
- Add Reviewed-by from Jan
- Rebase on v7.4-rc1
v1: https://lore.kernel.org/r/20261030-bug-mm-filemap-init-marks-once-v1-1-699835fc6690@gmail.com
---
mm/filemap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index b74bc1e5015c6..c2effedf975a2 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -140,7 +140,9 @@ static void page_cache_delete(struct address_space *mapping,
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
xas_store(&xas, shadow);
- xas_init_marks(&xas);
+ /* If xas_store() didn't clear marks, do it now */
+ if (shadow)
+ xas_init_marks(&xas);
folio->mapping = NULL;
/* Leave folio->index set: truncation lookup relies upon it */
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261030-bug-mm-filemap-init-marks-once-b83c6aa67bab
Best regards,
--
Qiliang Yuan <odys.yuan@gmail.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-03 0:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 0:43 [PATCH v2] mm/filemap: clear page cache marks once when removing a folio Qiliang Yuan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®