diff options
| author | Kairui Song <kasong@tencent.com> | 2026-09-23 23:32:43 +0200 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-10-08 22:55:21 -0700 |
| commit | fea0f0ed65e88ccb01c31450d0fec0d5754f3976 (patch) | |
| tree | 0db7f8186874f5a4b29263694aadc4aa6967ae0b /tools/perf/scripts/python | |
| parent | 550a041c774bba1b79766dd86dc8e4b4fcedf262 (diff) | |
mm/huge_memory: move anon_vma handling into the anon split helper
Only anon split needs the anon_vma, and it only needs it to unmap and
remap. Move the folio_get_anon_vma()/anon_vma_lock_write() pair out of
__folio_split() into the anon helper next to the folio_mapped() check that
already gates unmap_folio().
This makes the anon_vma conditional on folio_mapped(), which is a
behaviour change but should be fine. folio_get_anon_vma() returns NULL
whenever !folio_mapped(), so an anon folio with folio_mapcount() == 0 used
to get -EBUSY from split_huge_page() and is now split instead. A
realistic case is a THP that has been fully swapped out and is still in
the swap cache: swap PTEs do not contribute mapcount, so it is
!folio_mapped() but still alive.
That should be safe and right to have because:
- folio_ref_freeze() below still rejects a folio that picked up any
reference, a mapping or a GUP pin, in the meantime.
- A parallel split is excluded by the folio lock. The anon_vma
write lock was added to serialize split in commit 062f1af2170a
("mm: thp: acquire the anon_vma rwsem for write during split"), when
split_huge_page() did not hold the folio lock throughout. commit
e9b61f19858a ("thp: reintroduce split_huge_page()") later made the
folio lock a caller requirement and added the folio_ref_freeze()
scheme, so that has been covered ever since.
- Unmapped path is already exercised by folio_split_unmapped(),
and the swap cache split already runs well for a partially
swapped-out mapped THP.
- A !folio_mapped() folio cannot become mapped meanwhile: mapping it
requires the folio lock.
For mapped folios the anon_vma write lock is now released before
__folio_split() unlocks the after-split sub-folios, where previously it
was held across that loop; that window is harmless as the sub-folios stay
folio-locked and referenced until it.
Link: https://lore.kernel.org/20260923-swap-thp-cleanup-v6-12-ba1b4ba72c6f@tencent.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Barry Song <baohua@kernel.org>
Cc: Youngjun Park <youngjun.park@lge.com>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Shivam Kalra <shivamkalra98@zohomail.in>
Cc: Kairui Song <ryncsn@gmail.com>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
