[PATCH RFC 6/8] mm/huge_memory: rearrange split routine handling for better optimization
From: Kairui Song via B4 Relay
Date: Fri Nov 13 2026 - 17:12:33 EST
From: Kairui Song <kasong@xxxxxxxxxxx>
Anonymous folios never use a mapping or an xarray, so combine the is_anon
and xas conditions into a single if/else-if chain. The compiler cannot do
this on its own because the xarray split calls sit between the two
conditions and the anon mTHP stat update comes after the split helpers.
./scripts/bloat-o-meter on mm/huge_memory.o (x86-64 KVM test config) shows
__split_frozen_folio() shrinking from 1077 to 996 bytes.
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/huge_memory.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 7270baa20d80..e16b93318613 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3929,13 +3929,17 @@ static int __split_frozen_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);
+ if (is_anon) {
+ int nr_new_folios = 1UL << (old_order - split_order);
- /* order-1 anonymous folio is not supported */
- if (is_anon && split_order == 1)
- continue;
+ /* order-1 anonymous folio is not supported */
+ if (split_order == 1)
+ continue;
- if (xas) {
+ /* Split can't fail at this point, update counters now */
+ mod_mthp_stat(old_order, MTHP_STAT_NR_ANON, -1);
+ mod_mthp_stat(split_order, MTHP_STAT_NR_ANON, nr_new_folios);
+ } else if (xas) {
/*
* uniform split has xas_split_alloc() called before
* irq is disabled to allocate enough memory, whereas
@@ -3960,10 +3964,6 @@ static int __split_frozen_folio(struct folio *folio, int new_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);
- }
/*
* If uniform split, the process is complete.
* If non-uniform, continue splitting the folio at @split_at
--
2.56.1