Result of tools/testing/selftests/mm/cow.c tests: # [RUN] Basic COW after fork() when collapsing before fork() ok 145 No leak from parent into child # [RUN] Basic COW after fork() when collapsing after fork() (fully shared) ok 146 No leak from parent into child # [RUN] Basic COW after fork() when collapsing after fork() (lower shared) ok 147 No leak from parent into child # [RUN] Basic COW after fork() when collapsing after fork() (upper shared) ok 148 No leak from parent into child Debug messages (simply with printk, will add tracepoints later) show that THP in case 145 and 146 is remapped with pmd in place. To be honest, I'm not sure some of the conditions are handled properly, such as pin and uffd. And I send out this workable patchset to get more comments. Many thanks! Changes since v1: - Deal with PageAnonExclusive properly, as suggested by David. Xu Yu (2): mm/khugepaged: attempt to map anonymous pte-mapped THPs by pmds mm/khugepaged: add case for mapping anonymous pte-mapped THPs by pmds mm/khugepaged.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) -- 2.37.1