Skip to content

mm: clarify folio_add_new_anon_rmap() and __folio_add_anon_rmap()

Barry Song linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 12 repliesIn review 1 of 3 applied
  2. v1 RFC3 patches 17 repliesSuperseded

Patches in v2 1 of 3 applied

#Subject and filesSizeRepliesApplied
1/3mm: extend rmap flags arguments for folio_add_new_anon_rmapinclude/linux/rmap.h kernel/events/uprobes.c mm/huge_memory.c +6 more+22 -192 replies
2/3mm: use folio_add_new_anon_rmap() if folio_test_anon(folio)==falsemm/memory.c mm/swapfile.c+19 -29 replies
3/3mm: remove folio_test_anon(folio)==false path in __folio_add_anon_rmap()mm/rmap.c+3 -141 replyApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchShuai YuanDavid Hildenbrand
1/3T-b A-b
2/3T-b A-b
3/3T-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] mm: clarify folio_add_new_anon_rmap() and __folio_add_anon_rmap()

From: Barry Song <[email protected]>

The whole thing was originally suggested by David while we tried to weaken the WARN_ON in __folio_add_anon_rmap() while bringing up mTHP swapin[1]. This patchset is also preparatory work for mTHP swapin.

folio_add_new_anon_rmap() assumes that new anon rmaps are always exclusive. However, this assumption doesn’t hold true for cases like do_swap_page(), where a new anon might be added to the swapcache and is not necessarily exclusive.

The patchset extends the rmap flags to allow folio_add_new_anon_rmap() to handle both exclusive and non-exclusive new anon folios. The do_swap_page() function is updated to use this extended API with rmap flags. Consequently, all new anon folios now consistently use folio_add_new_anon_rmap().
The special case for !folio_test_anon() in __folio_add_anon_rmap() can be safely removed.

In conclusion, new anon folios always use folio_add_new_anon_rmap(), regardless of exclusivity. Old anon folios continue to use __folio_add_anon_rmap() via folio_add_anon_rmap_pmd() and folio_add_anon_rmap_ptes().

[1] https://lore.kernel.org/linux-mm/[email protected]/

-v2:
* fix crashes reported by Yuan Shuai during swapoff, thanks; David also commented unuse_pte() for swapoff;
* add comments for !anon according to David, thanks;
* add Yuan Shuai's tested-by tags, thanks for Yuan Shuai's testing on real phones;
* refine changelog;

-v1(RFC):
https://lore.kernel.org/linux-mm/[email protected]/

Barry Song (3):
mm: extend rmap flags arguments for folio_add_new_anon_rmap
mm: use folio_add_new_anon_rmap() if folio_test_anon(folio)==false
mm: remove folio_test_anon(folio)==false path in

    __folio_add_anon_rmap()
 include/linux/rmap.h    |  2 +-
 kernel/events/uprobes.c |  2 +-
 mm/huge_memory.c        |  2 +-
 mm/khugepaged.c         |  2 +-
 mm/memory.c             | 18 +++++++++++++-----
 mm/migrate_device.c     |  2 +-
 mm/rmap.c               | 34 +++++++++++++---------------------
 mm/swapfile.c           | 15 ++++++++++++---
 mm/userfaultfd.c        |  2 +-
 9 files changed, 44 insertions(+), 35 deletions(-)
Signature · 1 line
2.34.1