Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2096381ybz; Thu, 23 Apr 2020 11:30:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIsZr2EtZ4Rrvm8nDKQu0VZDlfcP7CkB7QrrIucAS8AGTVXQCHr8q7gnybCjYydBex1X1/6 X-Received: by 2002:a17:906:1d4c:: with SMTP id o12mr3951063ejh.357.1587666637212; Thu, 23 Apr 2020 11:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587666637; cv=none; d=google.com; s=arc-20160816; b=BAW+dPG8PI2VUhjp/Xl4tVu2+WL1256U7gq/6dGYQ+WsBt5UQOk0U5u+zjAzITIEk0 HmCbuYbgCBwXuuR6o2isQGF/+dpgVTRHrr6itaXaJKUP0dRrnduckdVz3+lTioh2VJiz TaebJxldJLPRLazBnRQ7W2lO3LcS7wfc1Ua9yxOBFjhFDxNmodDU5Fyo7QKMCugdZgr4 s3bGt0pniawtknJYOpAPB466jwaxxrOQtIE/X9K4YYdxnWoPky4jGBoLusCeZ1bHgfC9 q4XT3IBlMJhJKnGfrNubPKwN8Ki6DBlvXKwVi7N0YgsJh4AZgU6hvt8GDabIEk3aURZl CvUA== 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:message-id:subject:cc :to:date:from:dkim-signature; bh=ZE/Q5wyFh/fk7FQaU+5dw//N1awzxGvvqRYpEuzZTWw=; b=rOoevdE223owPzfwp5+8NwbmKAg5LDqipPWs1MeTQ5FKHxp1rfqIHJE+7fV/P4CWkL soxrS+/fwvXLZoDyl5MsDRIeOdB4htHn9Q4wNvFTFBAUKFPbW/87yvaO0IaIM1JinW5J iDo1CeJesQazEfjJbm0lc7fTfffTlqrbF2y+/D5Etz8lds02FuVD5+6SqV1aMV/RO3nW KIxhPlGojyNdaeRfmu9HKtgqhjoYbbu7wcyiHpdeKf8UnBQLvMIR0uDX9zL9/BabQt6T DWrKbjqoglLd1+oRmSm/g+uggRO4iCb9ePbSW/pA4XLusR6yCFBtXvIX0LXJCpMViaa0 ADIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jkbesJ48; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co4si1637370edb.83.2020.04.23.11.30.13; Thu, 23 Apr 2020 11:30:37 -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=@gmail.com header.s=20161025 header.b=jkbesJ48; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbgDWS2D (ORCPT + 99 others); Thu, 23 Apr 2020 14:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730116AbgDWS2C (ORCPT ); Thu, 23 Apr 2020 14:28:02 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A0B5C09B042; Thu, 23 Apr 2020 11:28:02 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id u15so7284976ljd.3; Thu, 23 Apr 2020 11:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZE/Q5wyFh/fk7FQaU+5dw//N1awzxGvvqRYpEuzZTWw=; b=jkbesJ48ONQf7uxFHU+j1V4mbbyQ2ZTFodf96Wf4Q4aJi4KyNRXLMjJcX/+NtP8s2p r81tzrlz1HvyNLEYVGvLujlOHr37M5a92pXP7KeFMZoIHkicy4t5RSaZwFZwwC98YrU2 r1T7h7Gyy6FKHR1TF2k5+IYeOATnGzI7Lb31ZoSuxrmdB4q2bpyC+9EzvgDOx/AbCV0Q L3QicORR2y0VILFAnov6m+f4+vUI1utw76nRTzTFAJDyCiLTDIwwMzI+JeX3s2ji93aa vKmtSKfx1OZQhXK2n9mBr2l3qK4bdo6TEXhQrjggke4gJmlLNv10SQx3Bj28WdjQCXwB RrLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZE/Q5wyFh/fk7FQaU+5dw//N1awzxGvvqRYpEuzZTWw=; b=tiXqc3mHpADzmwnC/lKoXADd7AYqibXl1IS9A+YyWTXJNiNefXMhvt1ZBqrhYtZnx6 fQeqHXtVSWzWAV31r4OlxgT+/rF+xegOask0O6Ph+SvLy6nTsbE8vlwMfOKBskobZRt2 2hzsF/boSWybNB2BikHWAmtxLYqYYOwHWjpd1yYJqKcBeOBUV7chvmGBVkguURr3ltze i2kONexl1tk0ZPyN401tuL5Tii63pssDGrhcrR655oL7jN9enaEI3LdVC5hDHAElbTR+ +5IIwrfA4FywrMjPiOUZFy57Ogxf4oDvPTHZums7EtN+78wrZ15UH63E3uiyi8xcVjrj mQ8w== X-Gm-Message-State: AGi0PuYYdjgXUE5CjDyIbZxIMPIVZ3fSeyisQAniR45VYjBQH/ux2n8V T4U0gfPK1NcT5wIx9aiyLrQ= X-Received: by 2002:a2e:9a93:: with SMTP id p19mr2934194lji.77.1587666480470; Thu, 23 Apr 2020 11:28:00 -0700 (PDT) Received: from pc636 (h5ef52e31.seluork.dyn.perspektivbredband.net. [94.245.46.49]) by smtp.gmail.com with ESMTPSA id i124sm2398627lji.95.2020.04.23.11.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 11:27:59 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 23 Apr 2020 20:27:50 +0200 To: "Paul E. McKenney" , Johannes Weiner Cc: Johannes Weiner , Joel Fernandes , Uladzislau Rezki , linux-kernel@vger.kernel.org, Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , rcu@vger.kernel.org, Steven Rostedt Subject: Re: [PATCH RFC] rcu/tree: Refactor object allocation and try harder for array allocation Message-ID: <20200423182750.GA32451@pc636> References: <20200413211504.108086-1-joel@joelfernandes.org> <20200414194353.GQ17661@paulmck-ThinkPad-P72> <20200416103007.GA3925@pc636> <20200416131745.GA90777@google.com> <20200416180100.GT17661@paulmck-ThinkPad-P72> <20200422145752.GB362484@cmpxchg.org> <20200422153503.GQ17661@paulmck-ThinkPad-P72> <20200423174831.GB389168@cmpxchg.org> <20200423180249.GT17661@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200423180249.GT17661@paulmck-ThinkPad-P72> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 23, 2020 at 11:02:49AM -0700, Paul E. McKenney wrote: > On Thu, Apr 23, 2020 at 01:48:31PM -0400, Johannes Weiner wrote: > > On Wed, Apr 22, 2020 at 08:35:03AM -0700, Paul E. McKenney wrote: > > > On Wed, Apr 22, 2020 at 10:57:52AM -0400, Johannes Weiner wrote: > > > > On Thu, Apr 16, 2020 at 11:01:00AM -0700, Paul E. McKenney wrote: > > > > > On Thu, Apr 16, 2020 at 09:17:45AM -0400, Joel Fernandes wrote: > > > > > > On Thu, Apr 16, 2020 at 12:30:07PM +0200, Uladzislau Rezki wrote: > > > > > > > I have a question about dynamic attaching of the rcu_head. Do you think > > > > > > > that we should drop it? We have it because of it requires 8 + syzeof(struct rcu_head) > > > > > > > bytes and is used when we can not allocate 1 page what is much more for array purpose. > > > > > > > Therefore, dynamic attaching can succeed because of using SLAB and requesting much > > > > > > > less memory then one page. There will be higher chance of bypassing synchronize_rcu() > > > > > > > and inlining freeing on a stack. > > > > > > > > > > > > > > I agree that we should not use GFP_* flags instead we could go with GFP_NOWAIT | > > > > > > > __GFP_NOWARN when head attaching only. Also dropping GFP_ATOMIC to keep > > > > > > > atomic reserved memory for others. > > > > > > > > > > I must defer to people who understand the GFP flags better than I do. > > > > > The suggestion of __GFP_RETRY_MAYFAIL for no memory pressure (or maybe > > > > > when the CPU's reserve is not yet full) and __GFP_NORETRY otherwise came > > > > > from one of these people. ;-) > > > > > > > > The exact flags we want here depends somewhat on the rate and size of > > > > kfree_rcu() bursts we can expect. We may want to start with one set > > > > and instrument allocation success rates. > > > > > > > > Memory tends to be fully consumed by the filesystem cache, so some > > > > form of light reclaim is necessary for almost all allocations. > > > > > > > > GFP_NOWAIT won't do any reclaim by itself, but it'll wake kswapd. > > > > Kswapd maintains a small pool of free pages so that even allocations > > > > that are allowed to enter reclaim usually don't have to. It would be > > > > safe for RCU to dip into that. > > > > > > > > However, there are some cons to using it: > > > > > > > > - Depending on kfree_rcu() burst size, this pool could exhaust (it's > > > > usually about half a percent of memory, but is affected by sysctls), > > > > and then it would fail NOWAIT allocations until kswapd has caught up. > > > > > > > > - This pool is shared by all GFP_NOWAIT users, and many (most? all?) > > > > of them cannot actually sleep. Often they would have to drop locks, > > > > restart list iterations, or suffer some other form of deterioration to > > > > work around failing allocations. > > > > > > > > Since rcu wouldn't have anything better to do than sleep at this > > > > juncture, it may as well join the reclaim effort. > > > > > > > > Using __GFP_NORETRY or __GFP_RETRY_MAYFAIL would allow them that > > > > without exerting too much pressure on the VM. > > > > > > Thank you for looking this over and for the feedback! > > > > > > Good point on the sleeping. My assumption has been that sleeping waiting > > > for a grace period was highly likely to allow memory to eventually be > > > freed, and that there is a point of diminishing returns beyond which > > > adding additional tasks to the reclaim effort does not help much. > > > > There is when the VM is struggling, but not necessarily when there is > > simply a high, concurrent rate of short-lived file cache allocations. > > > > Kswapd can easily reclaim gigabytes of clean page cache each second, > > but there might be enough allocation concurrency from other threads to > > starve a kfree_rcu() that only makes a very cursory attempt at getting > > memory out of being able to snap up some of those returns. > > > > In that scenario it makes sense to be a bit more persistent, or even > > help scale out the concurrency of reclaim to that of allocations. > > > > > Here are some strategies right offhand when sleeping is required: > > > > > > 1. Always sleep in synchronize_rcu() in order to (with high > > > probability) free the memory. This might mean that the reclaim > > > effort goes slower than would be good. > > > > > > 2. Always sleep in the memory allocator in order to help reclaim > > > along. (This is a strawman version of what I expect your > > > proposal really is, but putting it here for completeness, please > > > see below.) > > > > > > 3. Always sleep in the memory allocator in order to help reclaim > > > along, but return failure at some point. Then the caller > > > invokes synchronize_rcu(). When to return failure? > > > > > > o After some substantial but limited amount of effort has > > > been spent on reclaim. > > > > > > o When it becomes likely that further reclaim effort > > > is not going to free up additional memory. > > > > > > I am guessing that you are thinking in terms of specifying GFP flags to > > > result in some variant of #3. > > > > Yes, although I would add > > > > o After making more than one attempt at the freelist to > > prevent merely losing races when the allocator/reclaim > > subsystem is mobbed by a high concurrency of requests. > > > > __GFP_NORETRY (despite its name) accomplishes this. > > > > __GFP_RETRY_MAYFAIL is yet more persistent, but may retry for quite a > > while if the allocation keeps losing the race for a page. This > > increases the chance of the allocation eventually suceeding, but also > > the risk of 1) trying to get memory for longer than a > > synchronize_rcu() might have taken and 2) exerting more temporary > > memory pressure on the workload* than might be productive. > > > > So I'm inclined to suggest __GFP_NORETRY as a starting point, and make > > further decisions based on instrumentation of the success rates of > > these opportunistic allocations. > > > > * Reclaim and OOM handling will be fine since no reserves are tapped > > Thank you for the explanation! Makes sense to me!!! > > Joel, Vlad, does this seem reasonable? > To me that makes sense. I think such strategy does fit to what we do, i mean we need to release memory asap. Doing it without initiating of long process of memory reclaim and do it only lightly(what __GFP_NORETRY does) is a good approach. We have an option to fallback to synchronize_rcu(). But that is for sleepable context. I have a question about non-sleeping context as well and how we allocate one page: bnode = (struct kvfree_rcu_bulk_data *) __get_free_page(GFP_NOWAIT | __GFP_NOWARN); Johannes, i saw you mentioned earlier that waking up a kswapd is not a good idea, what actually GFP_NOWAIT does. Do you recommend to exclude it? Also to replace by what? __GFP_HIGH|__GFP_ATOMIC? Thank you in advance! -- Vlad Rezki