summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2026-02-11 14:32:20 -0800
committerPeter Zijlstra <peterz@infradead.org>2026-02-27 16:40:21 +0100
commitbec2ee2390c95ed0c44494340464e69e79802e4a (patch)
treefdb7001b7fc00b57d4d74a4e75db0f04152bd90c /kernel
parent28c75fbfec8f024db1278194918e5f6eda4c570f (diff)
perf/core: Try to allocate task_ctx_data quickly
The attach_global_ctx_data() has O(N^2) algorithm to allocate the context data for each thread. This caused perfomance problems on large systems with O(100k) threads. Because kmalloc(GFP_KERNEL) can go sleep it cannot be called under the RCU lock. So let's try with GFP_NOWAIT first so that it can proceed in normal cases. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20260211223222.3119790-3-namhyung@kernel.org
Diffstat (limited to 'kernel')
-rw-r--r--kernel/events/core.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 90b0c9324cbf..d357714fc02e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5489,6 +5489,12 @@ again:
cd = NULL;
}
if (!cd) {
+ /*
+ * Try to allocate context quickly before
+ * traversing the whole thread list again.
+ */
+ if (!attach_task_ctx_data(p, ctx_cache, true, GFP_NOWAIT))
+ continue;
get_task_struct(p);
goto alloc;
}