On Wed, Jul 16, 2025 at 8:32 AM David Hildenbrand <david@xxxxxxxxxx> wrote: > > On 14.07.25 02:32, Nico Pache wrote: > > khugepaged may try to collapse a mTHP to a smaller mTHP, resulting in > > some pages being unmapped. Skip these cases until we have a way to check > > if its ok to collapse to a smaller mTHP size (like in the case of a > > partially mapped folio). > > > > This patch is inspired by Dev Jain's work on khugepaged mTHP support [1]. > > > > [1] https://lore.kernel.org/lkml/20241216165105.56185-11-dev.jain@xxxxxxx/ > > > > Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx> > > Co-developed-by: Dev Jain <dev.jain@xxxxxxx> > > Signed-off-by: Dev Jain <dev.jain@xxxxxxx> > > Signed-off-by: Nico Pache <npache@xxxxxxxxxx> > > --- > > mm/khugepaged.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > > index 5d7c5be9097e..a701d9f0f158 100644 > > --- a/mm/khugepaged.c > > +++ b/mm/khugepaged.c > > @@ -612,7 +612,12 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, > > folio = page_folio(page); > > VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); > > > > - /* See hpage_collapse_scan_pmd(). */ > > + if (order != HPAGE_PMD_ORDER && folio_order(folio) >= order) { > > + result = SCAN_PTE_MAPPED_HUGEPAGE; > > + goto out; > > + } > > Probably worth adding a TODO in the code like > > /* > * TODO: In some cases of partially-mapped folios, we'd actually > * want to collapse. > */ Done! Good idea with these TODOs! > > Acked-by: David Hildenbrand <david@xxxxxxxxxx> Thank you :) > > -- > Cheers, > > David / dhildenb >