From nobody Thu Apr 2 18:46:23 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ECB13563F1 for ; Wed, 11 Feb 2026 22:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770849144; cv=none; b=R7PSp2lz4vMXOwMOuRtC4xSOhJypuhcFZKilCEG3lrFB8VO7A8iA1LT1MfaHvMAJb0wFlVe0d2d10nR7OL6pXPqAmRIIZhETxtD84f9Dw/X9wqemr5dmSgI/hVDDUf+wKJVHbrSMpj+sovceJnbNawMnQ05pRz8n+QKy/viNkTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770849144; c=relaxed/simple; bh=h01KiB6pCoCVMtu+V2L+yDlsgIpolKK800+M0ocd0oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQ/RMLsTBeiqv1Dmf1F8ZPst0zOl9ZqVDJVMNWn0A4yGfrMVzphGFmZAQWOMe7yMfD0YjL08EF5hYLOGnUC6BPPvk+P47YjhPXjst0cTSsN/5n1zpcyEMsSoPFGAhFKIAxnIXPrvV/3sBKfMgL6+iHUUT8685+x48/gxdAKQLsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JaGHAZa5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JaGHAZa5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA3DC16AAE; Wed, 11 Feb 2026 22:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770849144; bh=h01KiB6pCoCVMtu+V2L+yDlsgIpolKK800+M0ocd0oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JaGHAZa5Pm4v3VXoOBI/5pfytK17uUmLtI7xZ+Cs6KtHW953ajdh24FYelP9tPFxK /jszR4Fu5rZ+Hf2Gw9OfOFoQ+RSU9WQVAAcadLgebVx/UgHe+Gi/OS6IrFLTT7y4+E PPrORUsAnskCL7O040JRR5cRKeg8u7Ld+AOEd1RxDhzzrdwI8bvZy2n/PbnMP01lpd LlVw/v9E7lOxLlzATNQ/4sLJ06+ITAYaHyqbij5DHMYgpN5eh/mwZqmktxRmIwOckV 0x6jLGtg0uhvcNIr7dKk5gW8gtHa6nTLwfZzOdDXhS6UOzIpRxOaAcAcFtLI/nrfGd /4OaozgkH74Vg== From: Namhyung Kim To: Peter Zijlstra , Ingo Molnar Cc: Mark Rutland , Alexander Shishkin , Arnaldo Carvalho de Melo , LKML , Guenter Roeck Subject: [PATCH 2/3] perf/core: Try to allocate task_ctx_data quickly Date: Wed, 11 Feb 2026 14:32:20 -0800 Message-ID: <20260211223222.3119790-3-namhyung@kernel.org> X-Mailer: git-send-email 2.53.0.273.g2a3d683680-goog In-Reply-To: <20260211223222.3119790-1-namhyung@kernel.org> References: <20260211223222.3119790-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D 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; } --=20 2.53.0.273.g2a3d683680-goog