Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5912351rwp; Mon, 17 Jul 2023 11:24:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVJ3pxTWR8+cri3FjDnerfJdCDNc//ZkmK1qvV1byMtTvRdT4dU0gXJy3BC77X2vtLJg43 X-Received: by 2002:a05:6a20:938f:b0:133:2a73:fdd5 with SMTP id x15-20020a056a20938f00b001332a73fdd5mr12840787pzh.32.1689618269982; Mon, 17 Jul 2023 11:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689618269; cv=none; d=google.com; s=arc-20160816; b=U0PFxx0Iw2AE+MxjpnFXg/CwdBFxauC7jMmW+pKkjn5He/0dlUAoR0e5PhJ/1Y8Z4H iGADYXfr98aRQImvikKimtKGgjs/cag/qnq/wvRxmFUClnPTRsenC5eTbRGanZZoaR1I r8B1L5l3SEViwJ0IhGoWw3mFREhPmMJBRiG7a4oOoX9IIgHVMmfA/ijVhYcm/3lWsjt/ Sv7Dx0eOcvlnd05xEJhRgUQ0U7IUzeIBJ5Swkk9nxaK6YMEPNPL7O24dvANjeyWjp4pi KAMTJLzGr5nT3bhVuz/MPTY8lTNTj8VKorO0AAvzghcBg3dFh9z8UloU10ltYQHc+dq9 k8Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iIKigVD70eXzG5ab61HBSPOIR6/HFh/5g4/nkhlunxY=; fh=TCyhCXlc+/2tSv8r0W+ai6HHfA/LWvAIwCWb1yprE78=; b=WCd9mWrsMEi1CBQsFmgAsuNRxOI6LOx8oTibAV8uTRKnbq7anXNNUiQ0LezLjR5XTM fLFDj+PsaUGWq1K3XIXfe1FbO8CofHfotq2AUNz/gD9oGYhO8v9so3b8z0l6PA5xzmKg kAs4juC9bG8EsKRCI4oRzzYvWd0ktsUL9DNESSmoIvqdVssT0FsgAx2k8DrvkN6Zsy/2 vA+dvIZfioI/4TCkF6u0/zh5IFLR5yPDBQ0LVr0ztBBUW41riHvHTL95K3f+8SkmdHrQ z2a/Tch56b2ZOkPi4wEI7mU1psHhqPgoKXXNrzK5JTu/7kR2yxxYq5dYUXXd5b6zviUe hhSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OFdPUnn6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o12-20020a170902d4cc00b001ac4f733007si205888plg.549.2023.07.17.11.24.17; Mon, 17 Jul 2023 11:24:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OFdPUnn6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbjGQSF0 (ORCPT + 99 others); Mon, 17 Jul 2023 14:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbjGQSFJ (ORCPT ); Mon, 17 Jul 2023 14:05:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0377198C; Mon, 17 Jul 2023 11:04:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2E217611C6; Mon, 17 Jul 2023 18:04:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92647C433CA; Mon, 17 Jul 2023 18:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689617095; bh=4Rvqpj2uxc7m3FkdSvfRYtUA4WLN8IJWZxpll6G1Oo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OFdPUnn6Y8cXhOeM3B0NMhTg21LZlEPm9YkU9MIchyEwcc0Q90EQBqcl5ggtXzBNk YlSdNx8MH5rIUP2KNizz5raY4yY7TwoPq+Iv2SwIUcg20Ts25G79Dhpb5FcEW4TNDi mWapt47SD2fs/YtoSlZ9vmt0ILEnRbPvQ3Iy1/y55QWveTjOIhGY2hQdsbKDCMnvi+ mG1Rh8Jx5hW5wOPhKmxCKW+3OtfK5lc6l3cazzHtPpR6bNoe21ATS5L6XUOCfagRZA pmg3Xt5Yqjgo0miag0aSO/RANllIbxhHWQgkWI5+fdYTTcpJA5lYiypEphFVstWYPc et3UJ2j/F0saA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 5C269CE0836; Mon, 17 Jul 2023 11:04:55 -0700 (PDT) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" , Alexei Starovoitov , Martin KaFai Lau , Andrii Nakryiko Subject: [PATCH rcu 4/5] rcu-tasks: Cancel callback laziness if too many callbacks Date: Mon, 17 Jul 2023 11:04:53 -0700 Message-Id: <20230717180454.1097714-4-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The various RCU Tasks flavors now do lazy grace periods when there are only asynchronous grace period requests. By default, the system will let 250 milliseconds elapse after the first call_rcu_tasks*() callbacki is queued before starting a grace period. In contrast, synchronous grace period requests such as synchronize_rcu_tasks*() will start a grace period immediately. However, invoking one of the call_rcu_tasks*() functions in a too-tight loop can result in a callback flood, which in turn can exhaust memory if grace periods are delayed for too long. This commit therefore sets a limit so that the grace-period kthread will be awakened when any CPU's callback list expands to contain rcupdate.rcu_task_lazy_lim callbacks elements (defaulting to 32, set to -1 to disable), the grace-period kthread will be awakened, thus cancelling any ongoing laziness and getting out in front of the potential callback flood. Cc: Alexei Starovoitov Cc: Martin KaFai Lau Cc: Andrii Nakryiko Signed-off-by: Paul E. McKenney --- Documentation/admin-guide/kernel-parameters.txt | 7 +++++++ kernel/rcu/tasks.h | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a0f427e1a562..44705a3618b9 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5264,6 +5264,13 @@ number avoids disturbing real-time workloads, but lengthens grace periods. + rcupdate.rcu_task_lazy_lim= [KNL] + Number of callbacks on a given CPU that will + cancel laziness on that CPU. Use -1 to disable + cancellation of laziness, but be advised that + doing so increases the danger of OOM due to + callback flooding. + rcupdate.rcu_task_stall_info= [KNL] Set initial timeout in jiffies for RCU task stall informational messages, which give some indication diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h index 28e986627e3f..291d536b1789 100644 --- a/kernel/rcu/tasks.h +++ b/kernel/rcu/tasks.h @@ -176,6 +176,8 @@ static int rcu_task_contend_lim __read_mostly = 100; module_param(rcu_task_contend_lim, int, 0444); static int rcu_task_collapse_lim __read_mostly = 10; module_param(rcu_task_collapse_lim, int, 0444); +static int rcu_task_lazy_lim __read_mostly = 32; +module_param(rcu_task_lazy_lim, int, 0444); /* RCU tasks grace-period state for debugging. */ #define RTGS_INIT 0 @@ -354,8 +356,9 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func, cblist_init_generic(rtp); raw_spin_lock_rcu_node(rtpcp); // irqs already disabled. } - needwake = func == wakeme_after_rcu; - if (havekthread && !timer_pending(&rtpcp->lazy_timer)) { + needwake = (func == wakeme_after_rcu) || + (rcu_segcblist_n_cbs(&rtpcp->cblist) == rcu_task_lazy_lim); + if (havekthread && !needwake && !timer_pending(&rtpcp->lazy_timer)) { if (rtp->lazy_jiffies) mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp)); else -- 2.40.1