Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp483551pxa; Wed, 19 Aug 2020 06:58:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCZuQe436jOb2ukr8JC/N8uEGRHZdjSGZ4wZesAFPec3Oh3SzjGrT8eopwmX1jnGN/jIV5 X-Received: by 2002:a17:906:9399:: with SMTP id l25mr25120694ejx.212.1597845492685; Wed, 19 Aug 2020 06:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597845492; cv=none; d=google.com; s=arc-20160816; b=Q2AkQ46nszisgKDZxtBUr+hIDJGyfj33QR0StteUm5HbvM/gdrNMNK0wpY5WRtMB/m PbRcRdOz6V7lB+CEZRwYmcrCUHrq4TzYBcD5s/gXcum+NE+nPgABCl8kVmGbhSrNFzne gTyZOl4GwNNtMQW/hLsWqTDeIMQdtNtH5d+EHjwJNUKCwvRl5uNKocrA5dn9Q+S7XaLA dpuivy84g5XQPeKQA5ewenXO0EgJiJw14JcrMFZHQ32TaEmchIav9doY8TwC5AVDOJDk DJJsIk/s2uGhdd/yNnqCER60+aU2dRABCaPOr1rcbJxY48Is+uSlcA3e60QqjNr09w85 NG9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8EXV56NXvSonVGTOIjFMHLBEIS4AGNmsqbp4b0UfWho=; b=UHW+6SmnenQYi1ko5t8lFLI6u1EF0/E+KrEc/DHtJBldp1jIuvylSsSnhRwu+7p529 zr1xoKE1YEzP4Audptz01O5FOoMdmIZPEzVc7saap6Y8MIN8SagENA1dXDG8oH/U9EK8 aSQB+XEJMcdQQ30+RDg0Tu773QpVBRjdZ4rvfE5jmGf2jYDCYHp+rT2jp1DYiA8f224F c4V09SDsI4LJbm8FmeBOb/1+mQNDxu83izJ7QQ9ppJLtSY7N/eqPvFbFtApPNSLkPWUV e3oB3MeRAJRu2FnUyiBTEGSbMV446s/YBodIhz9OYYKq8i7MEeUi1sYkxj7ldsuGlf/A pEgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b="wbv/PHxB"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si15024653eds.283.2020.08.19.06.57.47; Wed, 19 Aug 2020 06:58:12 -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=@joelfernandes.org header.s=google header.b="wbv/PHxB"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727975AbgHSN5B (ORCPT + 99 others); Wed, 19 Aug 2020 09:57:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727078AbgHSN47 (ORCPT ); Wed, 19 Aug 2020 09:56:59 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 338FDC061383 for ; Wed, 19 Aug 2020 06:56:56 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id c12so17809430qtn.9 for ; Wed, 19 Aug 2020 06:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=8EXV56NXvSonVGTOIjFMHLBEIS4AGNmsqbp4b0UfWho=; b=wbv/PHxBEJ9DrjsUo/ReyX4iunRVcZ8rfNh381cnz8Gqm3X2tV3yCcIUOoEUXHU+3D oxAHYALSCfaUZgjToik14tSy9bVt+KnPbUUNdzG4kS/qUiM8+iiSDiy52XgNfaXREhWd /GOr3d6U7x6pwIz/L5yxwBa5C8rR3ywlV/xU8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=8EXV56NXvSonVGTOIjFMHLBEIS4AGNmsqbp4b0UfWho=; b=nYd87tda1VdwaLP5HVFcmK3PhDMPjLq7tBVgw6qKZnPQ42Q318WhpyFt/7pIxKDhdi JARVEiG68mshGKbPNzmS2vaKWYHHmDMQfJ4O46M7oeYFIpkqpODarXH9kNwTKehvLM8P EZ/91+9MDnZCFuCmFrrlg0X1rzH4EP6RossmJgBFjs8ACerwbbCrPGih+WDWr1XClvnn rEHY5Y6Qj+jH0n69gdPn8dfVS88Qni5/VwmmXsf7r/5NA5E/1qrjRWerDxyAoxHq2q4i eNOLu2cLevLXnCdTptvAJfQFAFWAcvTpqv6zalFYf2+0muHm7qUwHiOtNZ31RAba54Lf 1vsw== X-Gm-Message-State: AOAM530JCe7k0ys327TRg1/2S9H12U5pFHDRBVa6jc7LJIhnOEVID+c8 MaACOUtLeLVo8zXj0hIgXk8VfA== X-Received: by 2002:aed:3461:: with SMTP id w88mr22401781qtd.180.1597845415324; Wed, 19 Aug 2020 06:56:55 -0700 (PDT) Received: from localhost ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id c22sm22364551qke.2.2020.08.19.06.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 06:56:54 -0700 (PDT) Date: Wed, 19 Aug 2020 09:56:54 -0400 From: Joel Fernandes To: "Zhang, Qiang" Cc: "Paul E. McKenney" , Uladzislau Rezki , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , rcu , LKML Subject: Re: =?utf-8?B?5Zue5aSN?= =?utf-8?Q?=3A?= [PATCH] rcu: shrink each possible cpu krcp Message-ID: <20200819135654.GB3875610@google.com> References: <20200814064557.17365-1-qiang.zhang@windriver.com> <20200814185124.GA2113@pc636> <20200818171807.GI27891@paulmck-ThinkPad-P72> <20200818210355.GM27891@paulmck-ThinkPad-P72> <20200818215511.GA2538@pc636> <20200818220245.GO27891@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 19, 2020 at 03:00:55AM +0000, Zhang, Qiang wrote: > > > ________________________________________ > 发件人: linux-kernel-owner@vger.kernel.org 代表 Joel Fernandes > 发送时间: 2020年8月19日 8:04 > 收件人: Paul E. McKenney > 抄送: Uladzislau Rezki; Zhang, Qiang; Josh Triplett; Steven Rostedt; Mathieu Desnoyers; Lai Jiangshan; rcu; LKML > 主题: Re: [PATCH] rcu: shrink each possible cpu krcp > > On Tue, Aug 18, 2020 at 6:02 PM Paul E. McKenney wrote: > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > index b8ccd7b5af82..6decb9ad2421 100644 > > > --- a/kernel/rcu/tree.c > > > +++ b/kernel/rcu/tree.c > > > @@ -2336,10 +2336,15 @@ int rcutree_dead_cpu(unsigned int cpu) > > > { > > > struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); > > > struct rcu_node *rnp = rdp->mynode; /* Outgoing CPU's rdp & rnp. */ > > > + struct kfree_rcu_cpu *krcp; > > > > > > if (!IS_ENABLED(CONFIG_HOTPLUG_CPU)) > > > return 0; > > > > > > + /* Drain the kcrp of this CPU. IRQs should be disabled? */ > > > + krcp = this_cpu_ptr(&krc) > > > + schedule_delayed_work(&krcp->monitor_work, 0); > > > + > > > > > > A cpu can be offlined and its krp will be stuck until a shrinker is involved. > > > Maybe be never. > > > > Does the same apply to its kmalloc() per-CPU caches? If so, I have a > > hard time getting too worried about it. ;-) > > >Looking at slab_offline_cpu() , that calls cancel_delayed_work_sync() > >on the cache reaper who's job is to flush the per-cpu caches. So I > >believe during CPU offlining, the per-cpu slab caches are flushed. > > > >thanks, > > > >- Joel > > When cpu going offline, the slub or slab only flush free objects in offline > cpu cache, put these free objects in node list or return buddy system, > for those who are still in use, they still stay offline cpu cache. > > If we want clean per-cpu "krcp" objects when cpu going offline. we should > free "krcp" cache objects in "rcutree_offline_cpu", this func be called > before other rcu cpu offline func. and then "rcutree_offline_cpu" will be > called in "cpuhp/%u" per-cpu thread. > Could you please wrap text properly when you post to mailing list, thanks. I fixed it for you above. > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index 8ce77d9ac716..1812d4a1ac1b 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -3959,6 +3959,7 @@ int rcutree_offline_cpu(unsigned int cpu) > unsigned long flags; > struct rcu_data *rdp; > struct rcu_node *rnp; > + struct kfree_rcu_cpu *krcp; > > rdp = per_cpu_ptr(&rcu_data, cpu); > rnp = rdp->mynode; > @@ -3970,6 +3971,11 @@ int rcutree_offline_cpu(unsigned int cpu) > > // nohz_full CPUs need the tick for stop-machine to work quickly > tick_dep_set(TICK_DEP_BIT_RCU); > + > + krcp = per_cpu_ptr(&krc, cpu); > + raw_spin_lock_irqsave(&krcp->lock, flags); > + schedule_delayed_work(&krcp->monitor_work, 0); > + raw_spin_unlock_irqrestore(&krcp->lock, flags); > return 0; I realized the above is not good enough for what this is trying to do. Unlike the slab, the new kfree_rcu objects cannot always be drained / submitted to RCU because the previous batch may still be waiting for a grace period. So the above code could very well return with the yet-to-be-submitted kfree_rcu objects still in the cache. One option is to spin-wait here for monitor_todo to be false and keep calling kfree_rcu_drain_unlock() till then. But then that's not good enough either, because if new objects are queued when interrupts are enabled in the CPU offline path, then the cache will get new objects after the previous set was drained. Further, spin waiting may introduce deadlocks. Another option is to switch the kfree_rcu() path to non-batching (so new objects cannot be cached in the offline path and are submitted directly to RCU), wait for a GP and then submit the work. But then not sure if 1-argument kfree_rcu() will like that. Probably Qian's original fix for for_each_possible_cpus() is good enough for the shrinker case, and then we can tackle the hotplug one. thanks, - Joel