On Sun, Aug 11, 2024 at 8:51 PM David Hildenbrand <david@xxxxxxxxxx> wrote: > > > the correct place should be: > > > > @@ -1329,6 +1326,10 @@ static int migrate_folio_move(free_folio_t > > put_new_folio, unsigned long private, > > if (anon_vma) > > put_anon_vma(anon_vma); > > folio_unlock(src); > > + > > + if (folio_test_anon(src)) > > + mod_mthp_stat(folio_order(src), MTHP_STAT_NR_ANON, 1); > > + > > migrate_folio_done(src, reason); > > > > return rc; > > > > Without this modification in migration code, my tests fail, anon_num can > > become negative. > > I was wondering if we should do it in __folio_migrate_mapping(). > > There, we set newfolio->mapping. Correct! To handle cases where the destination might not be migrated to but could be put or freed, migrate_folio_undo_dst() will be called to release the destination earlier. It's better to simply place the count where the anon mapping is set and cleared. --- a/mm/migrate.c +++ b/mm/migrate.c @@ -423,6 +423,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, /* No turning back from here */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; + if (folio_test_anon(folio) && folio_test_large(folio)) + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); if (folio_test_swapbacked(folio)) __folio_set_swapbacked(newfolio); @@ -446,6 +448,9 @@ static int __folio_migrate_mapping(struct address_space *mapping, * no turning back from here. */ newfolio->index = folio->index; + + if (folio_test_anon(folio) && folio_test_large(folio)) + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); newfolio->mapping = folio->mapping; folio_ref_add(newfolio, nr); /* add cache reference */ if (folio_test_swapbacked(folio)) { > > -- > Cheers, > > David / dhildenb >