On 2025-11-07 10:53, Mathieu Desnoyers wrote:
[...]
It would make sense to call an explicit percpu counter tree init
function from start_kernel() between the call to mm_core_init() and the
call to maple_tree_init(). This way it would be initialized right after
mm, but given that the hierarchical counter tree is a lib that can be
used for other purposes than mm accounting, I think it makes sense
to call its init explicitly from start_kernel() rather than bury
it within mm_core_init().
See the following diff. If nobody object, I'll prepare a v8 which
includes it.
diff --git a/include/linux/percpu_counter_tree.h
b/include/linux/percpu_counter_tree.h
index 8795e782680a..40fcdd6456b6 100644
--- a/include/linux/percpu_counter_tree.h
+++ b/include/linux/percpu_counter_tree.h
@@ -41,6 +41,7 @@ int percpu_counter_tree_precise_compare(struct
percpu_counter_tree *a, struct pe
int percpu_counter_tree_precise_compare_value(struct
percpu_counter_tree *counter, int v);
void percpu_counter_tree_set(struct percpu_counter_tree *counter, int v);
unsigned int percpu_counter_tree_inaccuracy(struct percpu_counter_tree
*counter);
+int percpu_counter_tree_subsystem_init(void);
/* Fast paths */
@@ -191,6 +192,12 @@ int percpu_counter_tree_approximate_sum(struct
percpu_counter_tree *counter)
return percpu_counter_tree_precise_sum(counter);
}
+static inline
+int percpu_counter_tree_subsystem_init(void)
+{
+ return 0;
+}
+
#endif /* CONFIG_SMP */
static inline
diff --git a/init/main.c b/init/main.c
index 07a3116811c5..204d9f913130 100644
--- a/init/main.c
+++ b/init/main.c
@@ -104,6 +104,7 @@
#include <linux/pidfs.h>
#include <linux/ptdump.h>
#include <linux/time_namespace.h>
+#include <linux/percpu_counter_tree.h>
#include <net/net_namespace.h>
#include <asm/io.h>
@@ -969,6 +970,7 @@ void start_kernel(void)
sort_main_extable();
trap_init();
mm_core_init();
+ percpu_counter_tree_subsystem_init();
maple_tree_init();
poking_init();
ftrace_init();
diff --git a/lib/percpu_counter_tree.c b/lib/percpu_counter_tree.c
index 9577d94251d1..05c3db0ce5b1 100644
--- a/lib/percpu_counter_tree.c
+++ b/lib/percpu_counter_tree.c
@@ -379,7 +379,7 @@ static unsigned int __init
calculate_inaccuracy_multiplier(void)
return inaccuracy;
}
-static int __init percpu_counter_startup(void)
+int __init percpu_counter_tree_subsystem_init(void)
{
nr_cpus_order = get_count_order(nr_cpu_ids);
@@ -391,4 +391,3 @@ static int __init percpu_counter_startup(void)
inaccuracy_multiplier = calculate_inaccuracy_multiplier();
return 0;
}
-module_init(percpu_counter_startup);
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com