The folio splitting process involves several related tasks that are executed together: Adjusting memcg (memory control group) accounting. Updating page owner tracking. Splitting the folio to the target size (new_order). Updating necessary folio statistics. This commit introduces the new helper function, __split_folio_and_update_stats(), to gather all these tasks. This consolidation improves modularity and is a necessary preparation step for further cleanup and simplification of the surrounding folio splitting logic. Signed-off-by: Wei Yang Cc: Lorenzo Stoakes Cc: Zi Yan --- mm/huge_memory.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c37fe6ad0c96..abde0f1aa8ff 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3567,6 +3567,22 @@ static void __split_folio_to_order(struct folio *folio, int old_order, ClearPageCompound(&folio->page); } +static void __split_folio_and_update_stats(struct folio *folio, int old_order, + int new_order, bool is_anon) +{ + int nr_new_folios = 1UL << (old_order - new_order); + + folio_split_memcg_refs(folio, old_order, new_order); + split_page_owner(&folio->page, old_order, new_order); + pgalloc_tag_split(folio, old_order, new_order); + __split_folio_to_order(folio, old_order, new_order); + + if (is_anon) { + mod_mthp_stat(old_order, MTHP_STAT_NR_ANON, -1); + mod_mthp_stat(new_order, MTHP_STAT_NR_ANON, nr_new_folios); + } +} + /** * __split_unmapped_folio() - splits an unmapped @folio to lower order folios in * two ways: uniform split or non-uniform split. @@ -3623,8 +3639,6 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, for (split_order = start_order; split_order >= new_order; split_order--) { - int nr_new_folios = 1UL << (old_order - split_order); - /* order-1 anonymous folio is not supported */ if (is_anon && split_order == 1) continue; @@ -3645,15 +3659,7 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, } } - folio_split_memcg_refs(folio, old_order, split_order); - split_page_owner(&folio->page, old_order, split_order); - pgalloc_tag_split(folio, old_order, split_order); - __split_folio_to_order(folio, old_order, split_order); - - if (is_anon) { - mod_mthp_stat(old_order, MTHP_STAT_NR_ANON, -1); - mod_mthp_stat(split_order, MTHP_STAT_NR_ANON, nr_new_folios); - } + __split_folio_and_update_stats(folio, old_order, split_order, is_anon); /* * If uniform split, the process is complete. * If non-uniform, continue splitting the folio at @split_at -- 2.34.1