On Wed, Sep 22, 2021 at 12:29:35PM -0700, Yang Shi wrote: > khugepqged does remove the pgtables. Please check out > retract_page_tables(). The pmd will be cleared and the ptes will be > freed otherwise the collapsed THP won't get PMD mapped by later > access. Indeed. I should probably still properly disable khugepaged for at least VM_SHARED && VM_UFFD_WP, then I'd keep the anonymous && minor mode behavior untouched. The other problem is even if current mm/vma doesn't have UFFD_WP registered, some other mm/vma could have UFFD_WP enabled there that mapped the same file. Checking that up within retract_page_tables() on all VMAs seems to be a bit too late. Checking it early may not trivially work too - I can walk the vma interval tree at the entry of khugepaged_scan_file(), making sure no vma has UFFD_WP set. However I don't see how it'll stop some of the vma from having UFFD_WP registered later after that point but before retract_page_tables(). I'll need to think about it, but thanks for the input, Yang. That's a very important point. -- Peter Xu