[RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters
From: Eric Curtin
Date: Mon Nov 30 2026 - 20:52:59 EST
From: Ryan Roberts <ryan.roberts@xxxxxxx>
THREAD_SIZE depends on PAGE_SIZE when boot-time page size selection is
used, so it is not a compile-time constant and cannot be used in C
preprocessor conditionals.
Test THREAD_SIZE_MAX instead in the #if directives that decide which
KSTACK_nK vm event items exist, in vm_event_item.h, vmstat_text[] in
mm/vmstat.c, and kstack_histogram() in kernel/exit.c. With a smaller
runtime THREAD_SIZE, the counters for sizes above it are still defined
but simply never incremented.
No functional change for compile-time page sizes.
Signed-off-by: Ryan Roberts <ryan.roberts@xxxxxxx>
Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
(cherry picked from commit bf0856284bb664002b756e3785d35aa050d766c9)
---
include/linux/vm_event_item.h | 14 +++++++-------
kernel/exit.c | 14 +++++++-------
mm/vmstat.c | 14 +++++++-------
3 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 2628ccda076a..d1bca28052ef 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -153,25 +153,25 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
#endif
#ifdef CONFIG_DEBUG_STACK_USAGE
KSTACK_1K,
-#if THREAD_SIZE > 1024
+#if THREAD_SIZE_MAX > 1024
KSTACK_2K,
#endif
-#if THREAD_SIZE > 2048
+#if THREAD_SIZE_MAX > 2048
KSTACK_4K,
#endif
-#if THREAD_SIZE > 4096
+#if THREAD_SIZE_MAX > 4096
KSTACK_8K,
#endif
-#if THREAD_SIZE > 8192
+#if THREAD_SIZE_MAX > 8192
KSTACK_16K,
#endif
-#if THREAD_SIZE > 16384
+#if THREAD_SIZE_MAX > 16384
KSTACK_32K,
#endif
-#if THREAD_SIZE > 32768
+#if THREAD_SIZE_MAX > 32768
KSTACK_64K,
#endif
-#if THREAD_SIZE > 65536
+#if THREAD_SIZE_MAX > 65536
KSTACK_REST,
#endif
#endif /* CONFIG_DEBUG_STACK_USAGE */
diff --git a/kernel/exit.c b/kernel/exit.c
index d5e7bc2af804..a8453363d1fd 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -813,31 +813,31 @@ static inline void kstack_histogram(unsigned long used_stack)
#ifdef CONFIG_VM_EVENT_COUNTERS
if (used_stack <= 1024)
count_vm_event(KSTACK_1K);
-#if THREAD_SIZE > 1024
+#if THREAD_SIZE_MAX > 1024
else if (used_stack <= 2048)
count_vm_event(KSTACK_2K);
#endif
-#if THREAD_SIZE > 2048
+#if THREAD_SIZE_MAX > 2048
else if (used_stack <= 4096)
count_vm_event(KSTACK_4K);
#endif
-#if THREAD_SIZE > 4096
+#if THREAD_SIZE_MAX > 4096
else if (used_stack <= 8192)
count_vm_event(KSTACK_8K);
#endif
-#if THREAD_SIZE > 8192
+#if THREAD_SIZE_MAX > 8192
else if (used_stack <= 16384)
count_vm_event(KSTACK_16K);
#endif
-#if THREAD_SIZE > 16384
+#if THREAD_SIZE_MAX > 16384
else if (used_stack <= 32768)
count_vm_event(KSTACK_32K);
#endif
-#if THREAD_SIZE > 32768
+#if THREAD_SIZE_MAX > 32768
else if (used_stack <= 65536)
count_vm_event(KSTACK_64K);
#endif
-#if THREAD_SIZE > 65536
+#if THREAD_SIZE_MAX > 65536
else
count_vm_event(KSTACK_REST);
#endif
diff --git a/mm/vmstat.c b/mm/vmstat.c
index c6beac6be2bc..248ab936410c 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1481,25 +1481,25 @@ const char * const vmstat_text[] = {
#endif
#ifdef CONFIG_DEBUG_STACK_USAGE
[I(KSTACK_1K)] = "kstack_1k",
-#if THREAD_SIZE > 1024
+#if THREAD_SIZE_MAX > 1024
[I(KSTACK_2K)] = "kstack_2k",
#endif
-#if THREAD_SIZE > 2048
+#if THREAD_SIZE_MAX > 2048
[I(KSTACK_4K)] = "kstack_4k",
#endif
-#if THREAD_SIZE > 4096
+#if THREAD_SIZE_MAX > 4096
[I(KSTACK_8K)] = "kstack_8k",
#endif
-#if THREAD_SIZE > 8192
+#if THREAD_SIZE_MAX > 8192
[I(KSTACK_16K)] = "kstack_16k",
#endif
-#if THREAD_SIZE > 16384
+#if THREAD_SIZE_MAX > 16384
[I(KSTACK_32K)] = "kstack_32k",
#endif
-#if THREAD_SIZE > 32768
+#if THREAD_SIZE_MAX > 32768
[I(KSTACK_64K)] = "kstack_64k",
#endif
-#if THREAD_SIZE > 65536
+#if THREAD_SIZE_MAX > 65536
[I(KSTACK_REST)] = "kstack_rest",
#endif
#endif /* CONFIG_DEBUG_STACK_USAGE */