At wp-fault time, when we find that a folio is exclusively mapped, we move folio->mapping to the faulting VMA's anon_vma, so that rmap overhead reduces. This is currently done for small folios (base pages) and PMD-mapped THPs. Do this for mTHP too. Signed-off-by: Dev Jain --- mm-selftests pass. mm/memory.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 7e32eb79ba99..ec04d2cec6b1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4014,6 +4014,11 @@ static bool __wp_can_reuse_large_anon_folio(struct folio *folio, * an additional folio reference and never ended up here. */ exclusive = true; + + if (folio_trylock(folio)) { + folio_move_anon_rmap(folio, vma); + folio_unlock(folio); + } unlock: folio_unlock_large_mapcount(folio); return exclusive; -- 2.30.2