]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf/core: Try to allocate task_ctx_data quickly
authorNamhyung Kim <namhyung@kernel.org>
Wed, 11 Feb 2026 22:32:20 +0000 (14:32 -0800)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 27 Feb 2026 15:40:21 +0000 (16:40 +0100)
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
kernel/events/core.c

index 90b0c9324cbf7c4aa5a2aadd4399c364480ff496..d357714fc02ebeb496c4d6440fafed471dd6f3e0 100644 (file)
@@ -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;
                        }