Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp182887rwl; Thu, 6 Apr 2023 17:08:10 -0700 (PDT) X-Google-Smtp-Source: AKy350bWtKPoBiw1AmI73OLMIZXqdNgQYpbHYRvZIHaZ1QNeTEJ7kPf1R41CxdaMaxaiEnNMTBYO X-Received: by 2002:a17:90b:3908:b0:23d:500f:e826 with SMTP id ob8-20020a17090b390800b0023d500fe826mr415417pjb.14.1680826089845; Thu, 06 Apr 2023 17:08:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680826089; cv=none; d=google.com; s=arc-20160816; b=XG218d7d7EsHnXQsyCV9zMXSgTNqHhHb9ll6fWJGw8Bld0FgBnn3VJ900OnybiVQMx lAFq7qTNEkV0OxF8zOSWrFkNjFotaq/4ueFPDOzQhsBZv7c8Lj9wSfZvVS/Pp8i0T13j 5htTI8tkvoH5G3fOebzRpAlGujpC6ldSnpEz7mwrCvM6eFuKIYsDaeyj9g+TQp0OhpJv o3BV5f6O29VGI5sIdPQHgjdwJBIFxgy9NVgIbm2FyJH87DVd0TC2IwwGyl8ejr4io7V+ l1aRjNmWThQHnr1JiMWEr76trH/RD+c3WPi0OIPYQy3oQQI1SgAcApil/d0DtBdto47E yYEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=v3aP28cs+Ak44f50dlsTNA5J3AcKdpi3T/ZAXI7CEU4=; b=WJXA9kuraFrSTXN/roEH3BWPQZ+MawzU7inkqgCobLTfTzdHVEGrhaptmI86eQ0kZf +BC80fPYGb6I5uIhbUlfinS8Y6wQqis9WvQX9OY4LD1wZBhyxP6VBwPAI0jTt8bZXfQi cgrIA3hsmKtCwmA4j2DU+aLtPqL8lvVbrHV0yT+zkRNYd77EOATkeJniEJo9z2RM0ieO 2Tqsat5Hv3BJF2gAEQsG2GEo8OqtZiKD8rbLu1Mq9Yp2PnOsW7Id0ftlfNLbt7i6OUsY PxyFGLKMPAl6/tD6UCPBweDWJgWeH9qM8yjwqj+ICL7BTEbxVCLfxNchW86odDMBH1hI x8Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tiKF+xsO; 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 u21-20020a63ef15000000b0051339e73e3asi2258833pgh.314.2023.04.06.17.07.57; Thu, 06 Apr 2023 17:08:09 -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=tiKF+xsO; 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 S236924AbjDGAEH (ORCPT + 99 others); Thu, 6 Apr 2023 20:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjDGAEF (ORCPT ); Thu, 6 Apr 2023 20:04:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 788F04C17; Thu, 6 Apr 2023 17:04:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0FD5964BED; Fri, 7 Apr 2023 00:04:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71ED7C433EF; Fri, 7 Apr 2023 00:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680825843; bh=FWUEkRBFDu2x6pG40HBgPb+eVz+cSo+aWV9AS+aHaOA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=tiKF+xsO+dsER8y8XiUE2qlTqy37WXxFezjqqoE0gPUFClUJfYmE2e4fIYtIo8GyX sSkYZkhQz4yS1bK8jMRJ1La599hCwrv7++Q9nPLv4ps/vEIyoRb8SWTqQMwjg45LEg H9L+EgzuvcAAgX5N0kZax6iwMNY2A+L4/b14ACMN3dNpKcXLKS7lPH97gjDsL3aiag 6rGcKCC39QwBg9TytGrzpYx7CGtLxXGafhH6uApIVK4oWXF7l8Nyf1lBD4OCHXl/V0 X4aawZ+rIgrPB2/dWi14X5OhRlH150S/yEoXIoRl6Vw5XhXhJrzFq1Wafzi4fu1eAx 1HzStrfF5SZTA== Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 09340154047D; Thu, 6 Apr 2023 17:04:03 -0700 (PDT) Date: Thu, 6 Apr 2023 17:04:03 -0700 From: "Paul E. McKenney" To: "Zhang, Qiang1" Cc: Uladzislau Rezki , "frederic@kernel.org" , "joel@joelfernandes.org" , "qiang.zhang1211@gmail.com" , "rcu@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] rcu/kvfree: Prevents cache growing when the backoff_page_cache_fill is set Message-ID: <9427c261-0395-4e03-8f93-2e0588fadd1f@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20230406001238.647536-1-qiang1.zhang@intel.com> <8da4b48a-820c-461f-9dc0-a5afaf335177@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 On Thu, Apr 06, 2023 at 11:11:37PM +0000, Zhang, Qiang1 wrote: > >>On Thu, Apr 06, 2023 at 06:37:53AM +0200, Uladzislau Rezki wrote: > > On Thu, Apr 06, 2023 at 08:12:38AM +0800, Zqiang wrote: > > > Currently, in kfree_rcu_shrink_scan(), the drain_page_cache() is > > > executed before kfree_rcu_monitor() to drain page cache, if the bnode > > > structure's->gp_snap has done, the kvfree_rcu_bulk() will fill the > > > page cache again in kfree_rcu_monitor(), this commit add a check > > > for krcp structure's->backoff_page_cache_fill in put_cached_bnode(), > > > if the krcp structure's->backoff_page_cache_fill is set, prevent page > > > cache growing. > > > > > > Signed-off-by: Zqiang > > > --- > > > kernel/rcu/tree.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > index 9cc0a7766fd2..f25430ae1936 100644 > > > --- a/kernel/rcu/tree.c > > > +++ b/kernel/rcu/tree.c > > > @@ -2907,6 +2907,8 @@ static inline bool > > > put_cached_bnode(struct kfree_rcu_cpu *krcp, > > > struct kvfree_rcu_bulk_data *bnode) > > > { > > > + if (atomic_read(&krcp->backoff_page_cache_fill)) > > > + return false; > > > // Check the limit. > > > if (krcp->nr_bkv_objs >= rcu_min_cached_objs) > > > return false; > > > -- > > > 2.32.0 > > > > > Reviewed-by: Uladzislau Rezki (Sony) > > > >Thank you both! > > > >One question, though. Might it be better to instead modify the "for" > >loop in fill_page_cache_func() to start at krcp->nr_bkv_objs instead > >of starting at zero? That way, we still provide a single page under > >low-memory conditions, but provide rcu_min_cached_objs of them if memory > >is plentiful. > > > >Alternatively, if we really don't want to allow any pages at all under > >low-memory conditions, shouldn't the fill_page_cache_func() set nr_pages > >to zero (instead of the current 1) when the krcp->backoff_page_cache_fill > >flag is set? > > Hi, Paul > > If the krcp->backoff_page_cache_fill is true, the put_cached_bnode () return false, > the allocated single page will also be freed in fill_page_cache_func(). > > or it would be better not to allocate under memory pressure. That was my thought. ;-) > How about like this? > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index 9cc0a7766fd2..94aedbc3da36 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -2907,6 +2907,8 @@ static inline bool > put_cached_bnode(struct kfree_rcu_cpu *krcp, > struct kvfree_rcu_bulk_data *bnode) > { > + if (atomic_read(&krcp->backoff_page_cache_fill)) > + return false; > // Check the limit. > if (krcp->nr_bkv_objs >= rcu_min_cached_objs) > return false; > @@ -3220,7 +3222,7 @@ static void fill_page_cache_func(struct work_struct *work) > int i; > > nr_pages = atomic_read(&krcp->backoff_page_cache_fill) ? > - 1 : rcu_min_cached_objs; > + 0 : rcu_min_cached_objs; > > for (i = 0; i < nr_pages; i++) { The other question is why this loop does not allow for any pages that might already be allocated, thus perhaps looking like this: for (i = krcp->nr_bkv_objs; i < nr_pages; i++) { Or do we somehow know that krcp->nr_bkv_objs is equal to zero? (I am not seeing this, but I do feel the need to ask.) Thanx, Paul > bnode = (struct kvfree_rcu_bulk_data *) > > Thanks > Zqiang > > >This would likely mean also breaking out of that loop if > >krcp->backoff_page_cache_fill was set in the meantime (which happens > >implicitly with Zqiang's patch). > > > >Or am I missing something subtle here? > > > > Thanx, Paul