From nobody Sun Nov 24 01:10:54 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 ED155197A82 for ; Fri, 8 Nov 2024 10:42:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062546; cv=none; b=Y6G/NFJGfYC0dujj2pO0blRQvR48mbq64m367oRv1nes0pNc5TXPKi8+lNQSfne3XbZXbfIpBJDnF/eV9ekjQEq7704lI3orJRjbFcQw9ypDRZIseFaNoB+041bANiWWbtXcRxu13oLjW7i4XV/UM3Vfzw9QcKLwpW6yG5k8HZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062546; c=relaxed/simple; bh=l1hA+3w6YqDgs7wKbP/EcIpLbeETSQ63y0Ow7Athh74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tXNN2bT+DwcM15nlfi6il5gAvdzXdVt1zXQUuqrfba9FP87EeCWgluz4tHhq3la6W2C60/AwQg5fcGe6YkH8N0GUPwf2JcCbIyjMjlmrheZsji66rbkhDJc2tLzz3wgpdOqRXiTmcnJzDGywI95Jm3ZVN6OCtCr54DaDITiSGn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aHiJn/o/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JhRs5HBi; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aHiJn/o/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JhRs5HBi" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1731062543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcYB5rXKKViOk7fZRL5jGg/tydDAGzhBkw56NFEZwc4=; b=aHiJn/o/+6onX0kCs8A1AF+dH4PkQZuCiqCHE9SqK55ncLjfpg1wXCj+mytiP4POXPWxIc LasvbEFflpW2QiawiJuNUBoYqo1LUSNMMCVWNe3HjnWCKBB74ZIQMT3QcqqtESkoTT5Svu pmnNyPkgjHw6sSu7gSRm/y0Yl422xMRqXizzfJSFS4t6H2wQ883iWHWoZQdRCYNVyZbcPL Y8bnx2oBAeXr6UTD5sFgH34hxBDtIlwRwtIAE3KjLB2td+B63DBzRDh9/8dp8+mGmXJTKf u8j9HEE/1HP71YQv3nRjyx9c6Q8bbr238ij/G1P8w+aAPZvsilvIpQ1Z7WEVsw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1731062543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CcYB5rXKKViOk7fZRL5jGg/tydDAGzhBkw56NFEZwc4=; b=JhRs5HBiMYA0iJy0GGk0/CmAR2p7t7xPyc7Y9NrbJck2tkOJxhBw3tKEnOcV16A4OpkPAo kXbaprGbEnguLkCQ== To: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Paul E. McKenney" , Boqun Feng , Marco Elver , Peter Zijlstra , Tomas Gleixner , Vlastimil Babka , akpm@linux-foundation.org, cl@linux.com, iamjoonsoo.kim@lge.com, longman@redhat.com, penberg@kernel.org, rientjes@google.com, sfr@canb.auug.org.au, Sebastian Andrzej Siewior Subject: [PATCH v3 1/4] scftorture: Avoid additional div operation. Date: Fri, 8 Nov 2024 11:39:31 +0100 Message-ID: <20241108104217.3759904-2-bigeasy@linutronix.de> In-Reply-To: <20241108104217.3759904-1-bigeasy@linutronix.de> References: <20241108104217.3759904-1-bigeasy@linutronix.de> 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" Replace "scfp->cpu % nr_cpu_ids" with "cpu". This has been computed earlier. Tested-by: Paul E. McKenney Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Boqun Feng Tested-by: Boqun Feng --- kernel/scftorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/scftorture.c b/kernel/scftorture.c index 44e83a6462647..455cbff35a1a2 100644 --- a/kernel/scftorture.c +++ b/kernel/scftorture.c @@ -463,7 +463,7 @@ static int scftorture_invoker(void *arg) =20 // Make sure that the CPU is affinitized appropriately during testing. curcpu =3D raw_smp_processor_id(); - WARN_ONCE(curcpu !=3D scfp->cpu % nr_cpu_ids, + WARN_ONCE(curcpu !=3D cpu, "%s: Wanted CPU %d, running on %d, nr_cpu_ids =3D %d\n", __func__, scfp->cpu, curcpu, nr_cpu_ids); =20 --=20 2.45.2 From nobody Sun Nov 24 01:10:54 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 C8BB71C9EB9 for ; Fri, 8 Nov 2024 10:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062547; cv=none; b=N3wAVp0MLBRClTmD4qOJhTUqohZ+CXG2VJxv24ayZQYIBRVsMH0BCx5h/OiVlSvRFAJmDqNvr+1Yuyb9zDEx6nexIKbBSCgQxjecrRDfrE71qKwei2Sg4qDkN9vYICt+ESrAi6wNWGzMqHVSO0HWwNlUEUPv6jtR0FWlrT6P3fk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062547; c=relaxed/simple; bh=07fZDXRaDdbifNMW16jTx+iBkICOz9AKdzdzRjzV52M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hxS+FLRf6FOndKklLEys0xR5A8Mzw0pgMwsqlFIwGRDtK5Zu/btk6AyiBEruhxMxcZPnoaN6mMaRUufdxAlh1w6lto7JEZKcw2BTyIRu/W9XYsNQxV2JhMXk4IavUiql291mzmuRXh1hkrEFxlCgA44IfFc0wu2a1J0XzAsX18U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hhcP8+Wo; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KFvBYwKh; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hhcP8+Wo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KFvBYwKh" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1731062543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hZ7T3n9ji38bfDcEZMnrKQTiWeEv9uEaf9nIoN35Fps=; b=hhcP8+WoqQYG//gIZ0hHGdOdSyU2yj6omU1f7N5TVMdwHq2GbxdOEikXD6YyWgpRoXeyiy dLlWDR8Mnb0SccFh//hL0bR+W6vDt+fSiWqO7IjsrNA9Mik/wvg0YoqaWNNZhVvEMuQX2w 3frFc2smwspd0i3FXDtJ5icHSdqxqc9zIlLPIuf7b0OmBAN3nmL/e1RearU3oZyaZ21muY kDYmRG5HpF9447N78GlGMvSlYTuHLO6b6pTL2fIjcZa9/hNcSOU2PX46X7XXtzWA6z0Voi Qs27evJIdEGul1EmaRMj8gaet8r1RlZS3qb6pnTF1iiheLiQLKsDwI6q3EYCCw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1731062543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hZ7T3n9ji38bfDcEZMnrKQTiWeEv9uEaf9nIoN35Fps=; b=KFvBYwKhT7evOVi+BwnX0Mn/HduihryDoCDR9Lz7a5rjCyAy9P1BX5rp+JCGEycl5yXTZ3 4hHU0Jgn84MXGsBw== To: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Paul E. McKenney" , Boqun Feng , Marco Elver , Peter Zijlstra , Tomas Gleixner , Vlastimil Babka , akpm@linux-foundation.org, cl@linux.com, iamjoonsoo.kim@lge.com, longman@redhat.com, penberg@kernel.org, rientjes@google.com, sfr@canb.auug.org.au, Sebastian Andrzej Siewior Subject: [PATCH v3 2/4] scftorture: Wait until scf_cleanup_handler() completes. Date: Fri, 8 Nov 2024 11:39:32 +0100 Message-ID: <20241108104217.3759904-3-bigeasy@linutronix.de> In-Reply-To: <20241108104217.3759904-1-bigeasy@linutronix.de> References: <20241108104217.3759904-1-bigeasy@linutronix.de> 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 smp_call_function() needs to be invoked with the wait flag set to wait until scf_cleanup_handler() is done. This ensures that all SMP function calls, that have been queued earlier, complete at this point. Tested-by: Paul E. McKenney Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Boqun Feng Tested-by: Boqun Feng --- kernel/scftorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/scftorture.c b/kernel/scftorture.c index 455cbff35a1a2..654702f75c54b 100644 --- a/kernel/scftorture.c +++ b/kernel/scftorture.c @@ -523,7 +523,7 @@ static void scf_torture_cleanup(void) torture_stop_kthread("scftorture_invoker", scf_stats_p[i].task); else goto end; - smp_call_function(scf_cleanup_handler, NULL, 0); + smp_call_function(scf_cleanup_handler, NULL, 1); torture_stop_kthread(scf_torture_stats, scf_torture_stats_task); scf_torture_stats_print(); // -After- the stats thread is stopped! kfree(scf_stats_p); // -After- the last stats print has completed! --=20 2.45.2 From nobody Sun Nov 24 01:10:54 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4EA0B1E2600 for ; Fri, 8 Nov 2024 10:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062547; cv=none; b=dAe7XcrkEZJIfcuu8mPZaRzLU+Dae7KCHFKDcM/AcEV9+Y6AJexJs7962NH+cCw/nJEhpadpV9XdBqdQ1wQSPPDgXgaHdc87fsFY9qJ17UoGgfLNBZ0PTHQBI7YW6KH8hqUGaEtvGVNGDHGjy1eZLz45t7rZq8Re7lD30DRhxRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062547; c=relaxed/simple; bh=ug0G8pZx8Oc0rUK6VfL9LeNKmZ3uj6cetPA4cXxckek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cmtzVUsJ7U+NPMbC2XiEa0spyu2aTTMtmv/PHu9Y9oDXn3vTXQ9SEs9jX1TCWNEbeZ/SuwgROjq1klpJIfOKThFRMF2bwTL50yHeWEVNslFK+LuN5uUzed8oY/M01wC5GZ2Uv9cCKlE85uMQ6sIaohx5asoCnqBL0c6ULeJ+Kic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kM8bbPnu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rKChvvll; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kM8bbPnu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rKChvvll" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1731062544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rPuXJvFylkEjsJn/hxrBzgh+RNHJWlCC5YCBuHj3y5U=; b=kM8bbPnufm7rZrkKjsXsZE0yKOyGiuiZ4C+yL7LJ1yWKIx/YdkQSuDCmdjbRW91ME5CD2H fxcdcTsdEcgRz8DSUt38kG0VDpFFk/lHtAPUuDaksn06IPihgPwwagqZoJbkOiE7/qZNlv QffE6A6AT3LOAopHbq/1AtNJtu8TPDq0S9YXx+kZkMp5YC32qqsZcwfWpnquL4DqAcrv2c 7WD46sCmUYEHSl6kLqHi0nmn1NziAglMGNNeP12h04KFRWebfze3o5Q9/NqiEK2xAo3FxD sh5uLzu6YHSGCmw7H4+NfxOj2xvGM61PZFBo7HI+AAri+19EPVhNGQVSYsS9+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1731062544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rPuXJvFylkEjsJn/hxrBzgh+RNHJWlCC5YCBuHj3y5U=; b=rKChvvllSS+AA7SRc/2g+HuioD3b44nZ0BQwWt2Y6+ZFARiyQ7h1vvWHdDrsJ8n195Ta10 V18leTB7Ofvpa6CA== To: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Paul E. McKenney" , Boqun Feng , Marco Elver , Peter Zijlstra , Tomas Gleixner , Vlastimil Babka , akpm@linux-foundation.org, cl@linux.com, iamjoonsoo.kim@lge.com, longman@redhat.com, penberg@kernel.org, rientjes@google.com, sfr@canb.auug.org.au, Sebastian Andrzej Siewior Subject: [PATCH v3 3/4] scftorture: Move memory allocation outside of preempt_disable region. Date: Fri, 8 Nov 2024 11:39:33 +0100 Message-ID: <20241108104217.3759904-4-bigeasy@linutronix.de> In-Reply-To: <20241108104217.3759904-1-bigeasy@linutronix.de> References: <20241108104217.3759904-1-bigeasy@linutronix.de> 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" Memory allocations can not happen within regions with explicit disabled preemption PREEMPT_RT. The problem is that the locking structures underneath are sleeping locks. Move the memory allocation outside of the preempt-disabled section. Keep the GFP_ATOMIC for the allocation to behave like a "ememergncy allocation". Tested-by: Paul E. McKenney Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Boqun Feng Tested-by: Boqun Feng --- kernel/scftorture.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/scftorture.c b/kernel/scftorture.c index 654702f75c54b..e3c60f6dd5477 100644 --- a/kernel/scftorture.c +++ b/kernel/scftorture.c @@ -320,10 +320,6 @@ static void scftorture_invoke_one(struct scf_statistic= s *scfp, struct torture_ra struct scf_check *scfcp =3D NULL; struct scf_selector *scfsp =3D scf_sel_rand(trsp); =20 - if (use_cpus_read_lock) - cpus_read_lock(); - else - preempt_disable(); if (scfsp->scfs_prim =3D=3D SCF_PRIM_SINGLE || scfsp->scfs_wait) { scfcp =3D kmalloc(sizeof(*scfcp), GFP_ATOMIC); if (!scfcp) { @@ -337,6 +333,10 @@ static void scftorture_invoke_one(struct scf_statistic= s *scfp, struct torture_ra scfcp->scfc_rpc =3D false; } } + if (use_cpus_read_lock) + cpus_read_lock(); + else + preempt_disable(); switch (scfsp->scfs_prim) { case SCF_PRIM_RESCHED: if (IS_BUILTIN(CONFIG_SCF_TORTURE_TEST)) { --=20 2.45.2 From nobody Sun Nov 24 01:10:54 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 4EA981E2827 for ; Fri, 8 Nov 2024 10:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062548; cv=none; b=loPkWmdItSPPOSFQptLTDQqb05ZjZVgXf9kTvbH+6kFa5FNgndHwWwIiuldmJLvm8c75S9vYPI7WdJk39t7nNvroPDn9ooRoGJ9Uy8OMbNn/EhwJ6VXUckGYYQov+gfNsCtKoKo5AMVR0gfeAj+chTJwa1hgYUoDypTmOAVhCLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731062548; c=relaxed/simple; bh=JFVR1zGFp7skboDzHve0FaCWnfWzqjqAx8p6gEqk04Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sd1tdPJ9VAlleVNuAyui6lAJFnzgzLTcAkG9EHPixLRCumP1OnXpvLLdyzaqSQGpk/CgR2wi4FsmBNe6VjJnzU3smtvcrrxkc98h1W7Ds2k6UE/ar1nm0gU7CbB3RW8aFxlkb/+YJWtCuLEMXEq+xY6cG8nyZCMkCIlbIzzLNZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xdgOfCvu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VHh+O/Et; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xdgOfCvu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VHh+O/Et" From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1731062544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5s/mGxOR1k0iGJwjIgx4Nn5xFVAEP6Fy1K6QavY6cWI=; b=xdgOfCvuilQldzQOMpNfqbhLBJWQ8hWgfi7YAXGqIUVsXt8dH2HKhMMZK1UbFE9QY6fyIt Ndu0wL+sCgqAC/jf70Ab7g3JUc+RIBuysBK44EcaCDJDT6QpDFHGFZyaI9tYZrJRVNE0lH 1rvDfnBEtTP6crwTrkM2orUoU4mRhm015yD54+bkX+3gmce+fqFYPLFiSYlI4gn3V7gkBc X843XtQxebo2ejvgd4+2eT99hArk1xL+U1CP8B3rFM4QTQx9MG1wmepd/myNImYUo38nYr SB702ECMD7Wr1hbu4ix/ZGEtwoN9OAKQ5fZgPEdov9XmG257QZwRqDb8c9qcPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1731062544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5s/mGxOR1k0iGJwjIgx4Nn5xFVAEP6Fy1K6QavY6cWI=; b=VHh+O/EtWZ3A16mOSU7KTf672Jd4VxY+gi5vSUz+Zg2VvhVa/0tjSabgMacEJVyXoKHUPJ JWW3RE0D3a8cazBw== To: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Paul E. McKenney" , Boqun Feng , Marco Elver , Peter Zijlstra , Tomas Gleixner , Vlastimil Babka , akpm@linux-foundation.org, cl@linux.com, iamjoonsoo.kim@lge.com, longman@redhat.com, penberg@kernel.org, rientjes@google.com, sfr@canb.auug.org.au, Sebastian Andrzej Siewior Subject: [PATCH v3 4/4] scftorture: Use a lock-less list to free memory. Date: Fri, 8 Nov 2024 11:39:34 +0100 Message-ID: <20241108104217.3759904-5-bigeasy@linutronix.de> In-Reply-To: <20241108104217.3759904-1-bigeasy@linutronix.de> References: <20241108104217.3759904-1-bigeasy@linutronix.de> 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" scf_handler() is used as a SMP function call. This function is always invoked in IRQ-context even with forced-threading enabled. This function frees memory which not allowed on PREEMPT_RT because the locking underneath is using sleeping locks. Add a per-CPU scf_free_pool where each SMP functions adds its memory to be freed. This memory is then freed by scftorture_invoker() on each iteration. On the majority of invocations the number of items is less than five. If the thread sleeps/ gets delayed the number exceed 350 but did not reach 400 in testing. These were the spikes during testing. The bulk free of 64 pointers at once should improve the give-back if the list grows. The list size is ~1.3 items per invocations. Having one global scf_free_pool with one cleaning thread let the list grow to over 10.000 items with 32 CPUs (again, spikes not the average) especially if the CPU went to sleep. The per-CPU part looks like a good compromise. Reported-by: "Paul E. McKenney" Closes: https://lore.kernel.org/lkml/41619255-cdc2-4573-a360-7794fc3614f7@p= aulmck-laptop/ Tested-by: Paul E. McKenney Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Boqun Feng Tested-by: Boqun Feng --- kernel/scftorture.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/kernel/scftorture.c b/kernel/scftorture.c index e3c60f6dd5477..eeafd3fc16820 100644 --- a/kernel/scftorture.c +++ b/kernel/scftorture.c @@ -97,6 +97,7 @@ struct scf_statistics { static struct scf_statistics *scf_stats_p; static struct task_struct *scf_torture_stats_task; static DEFINE_PER_CPU(long long, scf_invoked_count); +static DEFINE_PER_CPU(struct llist_head, scf_free_pool); =20 // Data for random primitive selection #define SCF_PRIM_RESCHED 0 @@ -133,6 +134,7 @@ struct scf_check { bool scfc_wait; bool scfc_rpc; struct completion scfc_completion; + struct llist_node scf_node; }; =20 // Use to wait for all threads to start. @@ -148,6 +150,31 @@ static DEFINE_TORTURE_RANDOM_PERCPU(scf_torture_rand); =20 extern void resched_cpu(int cpu); // An alternative IPI vector. =20 +static void scf_add_to_free_list(struct scf_check *scfcp) +{ + struct llist_head *pool; + unsigned int cpu; + + cpu =3D raw_smp_processor_id() % nthreads; + pool =3D &per_cpu(scf_free_pool, cpu); + llist_add(&scfcp->scf_node, pool); +} + +static void scf_cleanup_free_list(unsigned int cpu) +{ + struct llist_head *pool; + struct llist_node *node; + struct scf_check *scfcp; + + pool =3D &per_cpu(scf_free_pool, cpu); + node =3D llist_del_all(pool); + while (node) { + scfcp =3D llist_entry(node, struct scf_check, scf_node); + node =3D node->next; + kfree(scfcp); + } +} + // Print torture statistics. Caller must ensure serialization. static void scf_torture_stats_print(void) { @@ -296,7 +323,7 @@ static void scf_handler(void *scfc_in) if (scfcp->scfc_rpc) complete(&scfcp->scfc_completion); } else { - kfree(scfcp); + scf_add_to_free_list(scfcp); } } =20 @@ -363,7 +390,7 @@ static void scftorture_invoke_one(struct scf_statistics= *scfp, struct torture_ra scfp->n_single_wait_ofl++; else scfp->n_single_ofl++; - kfree(scfcp); + scf_add_to_free_list(scfcp); scfcp =3D NULL; } break; @@ -391,7 +418,7 @@ static void scftorture_invoke_one(struct scf_statistics= *scfp, struct torture_ra preempt_disable(); } else { scfp->n_single_rpc_ofl++; - kfree(scfcp); + scf_add_to_free_list(scfcp); scfcp =3D NULL; } break; @@ -428,7 +455,7 @@ static void scftorture_invoke_one(struct scf_statistics= *scfp, struct torture_ra pr_warn("%s: Memory-ordering failure, scfs_prim: %d.\n", __func__, scfs= p->scfs_prim); atomic_inc(&n_mb_out_errs); // Leak rather than trash! } else { - kfree(scfcp); + scf_add_to_free_list(scfcp); } barrier(); // Prevent race-reduction compiler optimizations. } @@ -479,6 +506,8 @@ static int scftorture_invoker(void *arg) VERBOSE_SCFTORTOUT("scftorture_invoker %d started", scfp->cpu); =20 do { + scf_cleanup_free_list(cpu); + scftorture_invoke_one(scfp, &rand); while (cpu_is_offline(cpu) && !torture_must_stop()) { schedule_timeout_interruptible(HZ / 5); @@ -529,6 +558,9 @@ static void scf_torture_cleanup(void) kfree(scf_stats_p); // -After- the last stats print has completed! scf_stats_p =3D NULL; =20 + for (i =3D 0; i < nr_cpu_ids; i++) + scf_cleanup_free_list(i); + if (atomic_read(&n_errs) || atomic_read(&n_mb_in_errs) || atomic_read(&n_= mb_out_errs)) scftorture_print_module_parms("End of test: FAILURE"); else if (torture_onoff_failures()) --=20 2.45.2