Folio splitting requires both the folio's original order (@old_order) and the new target order (@split_order). In the current implementation, @old_order is repeatedly retrieved using folio_order(). However, for every iteration after the first, the folio being split is the result of the previous split, meaning its order is already known to be equal to the previous iteration's @split_order. This commit optimizes the logic: * Instead of calling folio_order(), we now set @old_order directly to the value of @split_order from the previous iteration. * The initial @split_order (which was previously handled by a separate @start_order variable) is now directly used, and the redundant @start_order variable is removed. This change avoids unnecessary function calls and simplifies the loop setup. Signed-off-by: Wei Yang Cc: Zi Yan --- mm/huge_memory.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 482a734b61ac..63380b185df1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3528,8 +3528,7 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, struct address_space *mapping, bool uniform_split) { bool is_anon = folio_test_anon(folio); - int order = folio_order(folio); - int start_order = uniform_split ? new_order : order - 1; + int old_order = folio_order(folio); int split_order; folio_clear_has_hwpoisoned(folio); @@ -3538,10 +3537,9 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, * split to new_order one order at a time. For uniform split, * folio is split to new_order directly. */ - for (split_order = start_order; + for (split_order = uniform_split ? new_order : old_order - 1; split_order >= new_order; split_order--) { - int old_order = folio_order(folio); int new_folios = 1UL << (old_order - split_order); /* order-1 anonymous folio is not supported */ @@ -3576,6 +3574,7 @@ static int __split_unmapped_folio(struct folio *folio, int new_order, mod_mthp_stat(split_order, MTHP_STAT_NR_ANON, new_folios); } folio = page_folio(split_at); + old_order = split_order; } return 0; -- 2.34.1