mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Guenter Roeck <groeck@google.com>
Subject: [PATCH 2/3] perf/core: Try to allocate task_ctx_data quickly
Date: Wed, 11 Feb 2026 14:32:20 -0800	[thread overview]
Message-ID: <20260211223222.3119790-3-namhyung@kernel.org> (raw)
In-Reply-To: <20260211223222.3119790-1-namhyung@kernel.org>

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>
---
 kernel/events/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index b8498e9891e21c18..5b05a71edeb47955 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5489,6 +5489,13 @@ attach_global_ctx_data(struct kmem_cache *ctx_cache)
 					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;
 			}
-- 
2.53.0.273.g2a3d683680-goog


  parent reply	other threads:[~2026-02-11 22:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-11 22:32 [PATCH 0/3] perf/core: Optimize LBR callstack handling Namhyung Kim
2026-02-11 22:32 ` [PATCH 1/3] perf/core: Pass GFP flags to attach_task_ctx_data() Namhyung Kim
2026-02-28 10:56   ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2026-02-11 22:32 ` Namhyung Kim [this message]
2026-02-28 10:56   ` [tip: perf/core] perf/core: Try to allocate task_ctx_data quickly tip-bot2 for Namhyung Kim
2026-02-11 22:32 ` [PATCH 3/3] perf/core: Simplify __detach_global_ctx_data() Namhyung Kim
2026-02-28 10:56   ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2026-02-26 12:07 ` [PATCH 0/3] perf/core: Optimize LBR callstack handling Peter Zijlstra
2026-02-26 18:26   ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260211223222.3119790-3-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=groeck@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®