[PATCH] mm/zsmalloc: keep fullness stats consistent with CONFIG_ZSMALLOC_STAT
From: Xueyuan Chen
Date: Fri Nov 06 2026 - 05:12:48 EST
The fullness-group counters are only used by the debugfs classes report,
which is enabled by CONFIG_ZSMALLOC_STAT. However, these counters are
stored and updated even when the option is disabled.
Make the counter storage and updates conditional on CONFIG_ZSMALLOC_STAT.
Keep ZS_OBJS_ALLOCATED and ZS_OBJS_INUSE, since zs_can_compact()
still needs these counters.
The behavior with CONFIG_ZSMALLOC_STAT=y remains unchanged.
Signed-off-by: Xueyuan Chen <xueyuan.chen21@xxxxxxxxx>
---
mm/zsmalloc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7ef80e0da626..eb77d7cd948c 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -212,8 +212,12 @@ enum fullness_group {
};
enum class_stat_type {
+#ifdef CONFIG_ZSMALLOC_STAT
/* NOTE: stats for 12 fullness groups here: from inuse 0 to 100 */
ZS_OBJS_ALLOCATED = NR_FULLNESS_GROUPS,
+#else
+ ZS_OBJS_ALLOCATED,
+#endif
ZS_OBJS_INUSE,
NR_CLASS_STAT_TYPES,
};
@@ -721,7 +725,9 @@ static void insert_zspage(struct size_class *class,
struct zspage *zspage,
int fullness)
{
+#ifdef CONFIG_ZSMALLOC_STAT
class_stat_add(class, fullness, 1);
+#endif
list_add(&zspage->list, &class->fullness_list[fullness]);
zspage->fullness = fullness;
}
@@ -737,7 +743,9 @@ static void remove_zspage(struct size_class *class, struct zspage *zspage)
VM_BUG_ON(list_empty(&class->fullness_list[fullness]));
list_del_init(&zspage->list);
+#ifdef CONFIG_ZSMALLOC_STAT
class_stat_sub(class, fullness, 1);
+#endif
}
/*
@@ -1896,7 +1904,9 @@ static void async_free_zspage(struct work_struct *work)
class = zspage_class(pool, zspage);
spin_lock(&class->lock);
+#ifdef CONFIG_ZSMALLOC_STAT
class_stat_sub(class, ZS_INUSE_RATIO_0, 1);
+#endif
__free_zspage(pool, class, zspage);
spin_unlock(&class->lock);
}
---
base-commit: 21a7f44fd0765fcc5194130b28767786eba1d1e7
--
Best regards,
Xueyuan