On Wed, May 21, 2025 at 08:10:46AM -0700, Hugh Dickins wrote:
Unless you have a very strong argument why this folio is invisible to the rest of the world, including speculative accessors like compaction (and the name "pagecache_folio" suggests very much the reverse): the pattern of unlocking a lock when you see it locked is like (or worse than) having no locking at all - it is potentially unlocking someone else's lock.
hugetlb_fault() locks 'pagecache_folio' and unlocks it after returning from hugetlb_wp(). This patch introduces the possibility that hugetlb_wp() can also unlock it for the reasons explained. So, when hugetlb_wp() returns back to hugetlb_fault(), we
1) either still hold the lock (because hugetlb_fault() took it) 2) or we do not anymore because hugetlb_wp() unlocked it for us.
So it is not that we are unlocking anything blindly, because if the lock is still 'taken' (folio_test_locked() returned true) it is because we, hugetlb_fault() took it and we are still holding it.