Skip to contentSkip to conversation

hugetlbfs: skip VMAs without shareable locks in hugetlb_vmdelete_list

PATCH Deepanshu Kartikey 1 participant 1 message Oct 3, 2025 Memory management

lore
Share & tools
lore
#0 lore raw

Hi,

My previous patch dd83609b8898 ("hugetlbfs: skip VMAs without shareable locks in hugetlb_vmdelete_list") fixed a WARNING but introduced a regression where pages aren't freed during punch hole operations, as reported by Mark Brown.

The issue is that skipping the entire VMA means pages don't get unmapped, so they can't be freed.

I'm considering the following fix approach:

1. Add a new ZAP_FLAG_NO_UNSHARE flag
2. In hugetlb_vmdelete_list(), try to get the shareable lock
3. If we can't get it, set ZAP_FLAG_NO_UNSHARE and proceed anyway
4. In __unmap_hugepage_range(), skip huge_pmd_unshare() if flag is set
5. But still clear page table entries so pages get freed

This way:
- For truncate: same behavior as before (might skip unsharing)
- For punch hole: pages get freed immediately (fixes regression)
- No WARNING (we don't call huge_pmd_unshare without lock)

The trade-off is that PMD metadata may not be cleaned up immediately when we can't get the shareable lock, but it will be freed when the VMA is destroyed.

Does this approach seem reasonable? Or is there a better way to handle this?

Thanks,
Deepanshu