Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp20093pxa; Tue, 18 Aug 2020 14:25:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzurLgCs3Z3c4q51qvhrfINPzhfgf3wIl/xDEstKf+Nqd3tQxjWTtHEbE+yo9usCuTHRWOB X-Received: by 2002:a17:906:95d4:: with SMTP id n20mr23296652ejy.485.1597785904780; Tue, 18 Aug 2020 14:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597785904; cv=none; d=google.com; s=arc-20160816; b=IZX2UlFKL/+v8Il3qnONAkfRdETBuZybY9Ux2HOaeOA6R0MyHPBkbJjy1it05cZY4L O1q5rxQ5vGQ+hbYdLaXNrcX/cLdPg1/QtGDGQmhaX0JWUguBEBSlrIqnbKBL3kygkcUd cxV860uNdFixJA/3ZahdqKLBpkdbq3yuybUnXeNfxA72NHuABhFAzpnVIKjy7SHX3I0n Qb4LhSjpKXhfXd9pRCggXWlaIoOEFuvZ+Gg4JBHfuBljrzIq/nbJeYEqOZneTnqNqINR Dbw68aCP5EmcvNJr5hjOjLERNIUsC+N2UHzAxNzjPn1frvCdmHahjXwnn9ejcg/H/yAp Lkrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=dLSn+7kmcj0QYO/82zy2KIuRopfvS0OPzVE9D2L4cDY=; b=NQLONIfdFNnFnF0IOp+YG/8I9tjRyeiqY70TgygEGKGxsOaz3H81wDzeX1ZIOpyJPc vt+tdCL/QF1pyDz7VHIoVJxJeryZHAcgF24qTz7kFzw+XV76iJd18IkbdH15irHAtDtK mc1WlW//5BO1vY33t+8CnUFUJaXIhI6klNNk6UKY8rODlDTDcnNMQCrhICn56Qb4vRvW k8lnr2EnloqvNvvY4cMESJIGnwjfqsTpPHu+GfdPQHKdH6pAwLPzB9jungqp6dvJejr7 nEE7UGwn0sw89KrY0rYAJXt+Ui3zAp5rQ2a3H3MNh+zBRFctiDSleKaF+26RdtAfpZ7y ogSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KY9Y7Q//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f1si13831075edq.182.2020.08.18.14.24.40; Tue, 18 Aug 2020 14:25:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KY9Y7Q//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726605AbgHRVD5 (ORCPT + 99 others); Tue, 18 Aug 2020 17:03:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:57088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgHRVD4 (ORCPT ); Tue, 18 Aug 2020 17:03:56 -0400 Received: from paulmck-ThinkPad-P72.home (unknown [50.45.173.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 40935205CB; Tue, 18 Aug 2020 21:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597784635; bh=HPr9VORaCJTq4ADIyzNh0P8W6nvrS9HdzdYwLMApPxQ=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=KY9Y7Q//gHTdu/nCTRm12otNIzpXnWe7WOs5r0rBgXhzavzNXdoW1SAxyM2WXltQ6 2bL2HZajS0Nos2oTvrg0Ht58bBTdcA6IctVu1XLfH5cYve6pYfNYl/uZTUpitnIIyB RqjuJnhRUP9hyJ3p6JIL7QlFzOwE2O3Lt9ZczcB4= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 1CCA535228F5; Tue, 18 Aug 2020 14:03:55 -0700 (PDT) Date: Tue, 18 Aug 2020 14:03:55 -0700 From: "Paul E. McKenney" To: Joel Fernandes Cc: Uladzislau Rezki , qiang.zhang@windriver.com, Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , rcu , LKML Subject: Re: [PATCH] rcu: shrink each possible cpu krcp Message-ID: <20200818210355.GM27891@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200814064557.17365-1-qiang.zhang@windriver.com> <20200814185124.GA2113@pc636> <20200818171807.GI27891@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 18, 2020 at 03:00:35PM -0400, Joel Fernandes wrote: > On Tue, Aug 18, 2020 at 1:18 PM Paul E. McKenney wrote: > > > > On Mon, Aug 17, 2020 at 06:03:54PM -0400, Joel Fernandes wrote: > > > On Fri, Aug 14, 2020 at 2:51 PM Uladzislau Rezki wrote: > > > > > > > > > From: Zqiang > > > > > > > > > > Due to cpu hotplug. some cpu may be offline after call "kfree_call_rcu" > > > > > func, if the shrinker is triggered at this time, we should drain each > > > > > possible cpu "krcp". > > > > > > > > > > Signed-off-by: Zqiang > > > > > --- > > > > > kernel/rcu/tree.c | 6 +++--- > > > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > > > index 8ce77d9ac716..619ccbb3fe4b 100644 > > > > > --- a/kernel/rcu/tree.c > > > > > +++ b/kernel/rcu/tree.c > > > > > @@ -3443,7 +3443,7 @@ kfree_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc) > > > > > unsigned long count = 0; > > > > > > > > > > /* Snapshot count of all CPUs */ > > > > > - for_each_online_cpu(cpu) { > > > > > + for_each_possible_cpu(cpu) { > > > > > struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); > > > > > > > > > > count += READ_ONCE(krcp->count); > > > > > @@ -3458,7 +3458,7 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) > > > > > int cpu, freed = 0; > > > > > unsigned long flags; > > > > > > > > > > - for_each_online_cpu(cpu) { > > > > > + for_each_possible_cpu(cpu) { > > > > > int count; > > > > > struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); > > > > > > > > > > @@ -3491,7 +3491,7 @@ void __init kfree_rcu_scheduler_running(void) > > > > > int cpu; > > > > > unsigned long flags; > > > > > > > > > > - for_each_online_cpu(cpu) { > > > > > + for_each_possible_cpu(cpu) { > > > > > struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); > > > > > > > > > > raw_spin_lock_irqsave(&krcp->lock, flags); > > > > > > > > > I agree that it can happen. > > > > > > > > Joel, what is your view? > > > > > > Yes I also think it is possible. The patch LGTM. Another fix could be > > > to drain the caches in the CPU offline path and save the memory. But > > > then it will take hit during __get_free_page(). If CPU > > > offlining/online is not frequent, then it will save the lost memory. > > > > > > I wonder how other per-cpu caches in the kernel work in such scenarios. > > > > > > Thoughts? > > > > Do I count this as an ack or a review? If not, what precisely would > > you like the submitter to do differently? > > Hi Paul, > The patch is correct and is definitely an improvement. I was thinking > about whether we should always do what the patch is doing when > offlining CPUs to save memory but now I feel that may not be that much > of a win to justify more complexity. > > You can take it with my ack: > > Acked-by: Joel Fernandes Thank you all! I wordsmithed a bit as shown below, so please let me know if I messed anything up. Thanx, Paul ------------------------------------------------------------------------ commit fe5d89cc025b3efe682cac122bc4d39f4722821e Author: Zqiang Date: Fri Aug 14 14:45:57 2020 +0800 rcu: Shrink each possible cpu krcp CPUs can go offline shortly after kfree_call_rcu() has been invoked, which can leave memory stranded until those CPUs come back online. This commit therefore drains the kcrp of each CPU, not just the ones that happen to be online. Acked-by: Joel Fernandes Signed-off-by: Zqiang Signed-off-by: Paul E. McKenney diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 02ca8e5..d9f90f6 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3500,7 +3500,7 @@ kfree_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc) unsigned long count = 0; /* Snapshot count of all CPUs */ - for_each_online_cpu(cpu) { + for_each_possible_cpu(cpu) { struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); count += READ_ONCE(krcp->count); @@ -3515,7 +3515,7 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) int cpu, freed = 0; unsigned long flags; - for_each_online_cpu(cpu) { + for_each_possible_cpu(cpu) { int count; struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); @@ -3548,7 +3548,7 @@ void __init kfree_rcu_scheduler_running(void) int cpu; unsigned long flags; - for_each_online_cpu(cpu) { + for_each_possible_cpu(cpu) { struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu); raw_spin_lock_irqsave(&krcp->lock, flags);