On Mon, 11 May 2026 12:58:06 -0600 Nico Pache <[email protected]> wrote:
> Pass an order and offset to collapse_huge_page to support collapsing anon > memory to arbitrary orders within a PMD. order indicates what mTHP size we > are attempting to collapse to, and offset indicates were in the PMD to > start the collapse attempt. > > For non-PMD collapse we must leave the anon VMA write locked until after > we collapse the mTHP-- in the PMD case all the pages are isolated, but in > the mTHP case this is not true, and we must keep the lock to prevent > access/changes to the page tables. This can happen if the rmap walkers hit > a pmd_none while the PMD entry is currently unavailable due to being > temporarily removed during the collapse phase. > > Signed-off-by: Nico Pache <[email protected]> > --- > mm/khugepaged.c | 93 +++++++++++++++++++++++++++++-------------------- > 1 file changed, 55 insertions(+), 38 deletions(-) > The patch did 2 things: Make it work with any order and not just PMD order. Keeps anon_vma_write held across the copy and install for non-PMD orders, as mTHP leaves the out-of-range PTEs mapped while the PMD is temporarily none. rmap walkers cannot reach here until PMD is isntalled. Acked-by: Usama Arif <[email protected]>
