[PATCH v2 0/5] Misc rework on hugetlb faulting path
From: Oscar Salvador
Date: Fri Jun 20 2025 - 08:30:41 EST
v1 -> v2:
- Addressed feedback from David
- Settle ideas wrt. locking in faulting path after
discussion with David
- Add Acks-by
RFC -> v1:
- Stop looking up folio in the pagecache for detecting a COW
on a private mapping.
- Document the locks
This patchset aims to give some love to the hugetlb faulting path, doing so
by removing obsolete comments that are no longer true, sorting out the folio
lock, and changing the mechanism we use to determine whether we are COWing a
private mapping already.
The most important patch of the series is #1, as it fixes a deadlock that
was described in [1], where two processes were holding the same lock
for the folio in the pagecache, and then deadlocked in the mutex.
Looking up and locking the folio in the pagecache was done to check whether
that folio was the same folio we had mapped in our pagetables, meaning that if it
was different we knew that we already mapped that folio privately, so any
further CoW would be made on a private mapping, which lead us to the question:
__Was the reservation for that address consumed?__
That is all we care about, because if it was indeed consumed and we are the
owner and we cannot allocate more folios, we need to unmap the folio from the
processes pagetables and make it exclusive for us.
We figured we do not need to look up the folio at all, and it is just enough to
check whether the folio we have mapped is anonymous, which means we mapped it
privately, so the reservation was indeed consumed.
Patch#2 sorts out folio locking in the faulting path, reducing the scope of it
,only taking it when we are dealing with an anonymous folio and document it.
More details in the patch.
Patch#3-5 are cleanups.
[1] https://lore.kernel.org/lkml/20250513093448.592150-1-gavinguo@xxxxxxxxxx/
Oscar Salvador (5):
mm,hugetlb: Change mechanism to detect a COW on private mapping
mm,hugetlb: Sort out folio locking in the faulting path
mm,hugetlb: Rename anon_rmap to new_anon_folio and make it boolean
mm,hugetlb: Drop obsolete comment about non-present pte and second
faults
mm,hugetlb: Drop unlikelys from hugetlb_fault
mm/hugetlb.c | 130 ++++++++++++++++++++++-----------------------------
1 file changed, 55 insertions(+), 75 deletions(-)
--
2.50.0