Skip to contentSkip to conversation

Hierarchical percpu counters preparation

PATCH Applied Mathieu Desnoyers 1 participant 2 messages Dec 24, 2025 Memory management

lore
Share & tools
lore
#0 lore raw

cover Hierarchical percpu counters preparation

Hi Andrew,

This patch is a preparation step for HPCC, for the OOM killer improvements. I suspect that this patch is useful on its own, because it really makes no sense to sum up accounting statistics of use_mm within kernel threads which are only temporarily using those mm.

Thanks,

Mathieu

Cc Andrew Morton <[email protected]>
Cc Mark Brown <[email protected]>

Mathieu Desnoyers (1):
tsacct: Skip all kernel threads

 kernel/tsacct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH 1/1 tsacct: Skip all kernel threads

When we hit acct_account_cputime within a irq handler over a kthread that happens to use a userspace mm, we end up summing up the mm's RSS into the tsk acct_rss_mem1, which eventually decays.

I don't see a good rationale behind tracking the mm's rss in that way when a kthread use a userspace mm temporarily through use_mm.

It causes issues with init_mm and efi_mm which only partially initialize their mm_struct when introducing the new hierarchical percpu counters to replace RSS counters, which requires a pointer dereference when reading the approximate counter sum. The current percpu counters simply load a zeroed atomic counter, which happen to work.

Skip all kernel threads in acct_account_cputime(), not just those that happen to have a NULL mm.

This is a preparation step before introducing the hierarchical percpu counters.

---
 kernel/tsacct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/tsacct.c +1 -1
index 6ea2f6363b90..5c153106e642 100644
@@ -125,7 +125,7 @@ static void __acct_update_integrals(struct task_struct *tsk,
 {
 	u64 time, delta;
 
-	if (!likely(tsk->mm))
+	if (unlikely(!tsk->mm || (tsk->flags & PF_KTHREAD)))
 		return;
 
 	time = stime + utime;
Signature · 1 line
2.39.5