From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AFD9C32793 for ; Wed, 18 Jan 2023 20:20:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2DDC6B0071; Wed, 18 Jan 2023 15:20:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CDD7B6B0073; Wed, 18 Jan 2023 15:20:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7DF56B0074; Wed, 18 Jan 2023 15:20:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A982F6B0071 for ; Wed, 18 Jan 2023 15:20:24 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 645291C5FD2 for ; Wed, 18 Jan 2023 20:20:24 +0000 (UTC) X-FDA: 80369037168.12.094B4A0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id AE8A218001F for ; Wed, 18 Jan 2023 20:20:22 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="NSz4Cw/o"; spf=pass (imf06.hostedemail.com: domain of "SRS0=DEr1=5P=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=DEr1=5P=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674073222; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VjB4K/F8GbM3IYLgrylIoPlmmCHNBetktnlDcrTTfgQ=; b=R+sj5yxbFbxvCMNDk41IAA0K95qB27L3MsX7h+p+Nm2TUFYgdaqXIYBPyKRmLP2jtcFcHY vnj3l2o6TAHqIHMDfVpkY/xnOO3VNvQ3TBlWDZ/mdmLnpgrGl36orz4UpeOE3A6Svkidq7 lnXz7jb1peroCyGWpnUGTD4ap7ycY74= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="NSz4Cw/o"; spf=pass (imf06.hostedemail.com: domain of "SRS0=DEr1=5P=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=DEr1=5P=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org"; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674073222; a=rsa-sha256; cv=none; b=1S5xoksxPnAGAtY8JYMgczhGCBLKq7AQE362MZu6Cxti0YexroVd0JkkyhXvcUdgNDbnAW PLxwosCfRudPNVGA36AX1RovAXbyXKY6LpVriEDortkFco7xzz54iLiMdxZ2oFXS0b5Nqv jtg508RjNyEuywViD507gnXaSxM9B6E= 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 8FEA361A1E; Wed, 18 Jan 2023 20:20:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E25FEC433D2; Wed, 18 Jan 2023 20:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674073221; bh=LkDAI9qvKi0MAfsYbidawt8PxsElByOP+Pkz5GpU4hs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=NSz4Cw/oXByK796oD3DytxHbEDXkhaciBuZCZt45dNnN2s0gmq78/PdAZYCRdE4OX gz3dDxoeuz+mKBLy2IgkAJzI+1iylam0JeecbKRS240Cf0ullxO+c5nmor/Gr5F/2J AwkG7qLuD7L71ncK3oGIUzOw2zE0s8dM/AYkWz+TxySO8nRHHCn4ks4FvNEXWGz3Ke CgbmmOlqZ+36yexqUqvhLyyj8u4HB/KHsj1pK62QWITX6NQM0KOXlOvkBMJjzlZhyh GfW49aeeMbUgY7ivyRdrvk4iT+2EsREynM2gVCKjqYcjsU3lveJY5nkdSQlBpQRhny p/yJPNrHzo9tg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 8482B5C0920; Wed, 18 Jan 2023 12:20:20 -0800 (PST) Date: Wed, 18 Jan 2023 12:20:20 -0800 From: "Paul E. McKenney" To: Suren Baghdasaryan Cc: Michal Hocko , akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 39/41] kernel/fork: throttle call_rcu() calls in vm_area_free Message-ID: <20230118202020.GJ2948950@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-40-surenb@google.com> <20230118183447.GG2948950@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: 4sug4pf5pkdgsnaxkwgd7irsajfbejdp X-Rspam-User: X-Rspamd-Queue-Id: AE8A218001F X-Rspamd-Server: rspam06 X-HE-Tag: 1674073222-757535 X-HE-Meta: U2FsdGVkX18lCT+0C2rg/bFe1jtLstGwEgDqx0F1MOoM0l3cvSEoIRVRsCgvJ8Pit6TsSfFrTI+YY0k6sbWHeeb8+qlo7bHzlth7Zq2S2TkWmiyVmzYFl9fq1mjKUG/E3Tph7A/hgTAlibshJNhZJjxPojySURPgnheb0P8wTn7OKrbF7/hRyg1TiwNN91fXW7qVtXnqdZm9/lQ+7KPIxYV6H3dJ8h63nFM9tgZLzj53fHQb4CYFSNqkEEFtUgUedZlBLtp+ZgthAseYfL5GkedUZePrhT1jnRxF9akNuXCQB0JeOSMDsKWrdR4H9jIcAU0iRUyWPFZzG0bm7cZmYFkXiAB4IhDOiZe8Oa8RG+pKCJZQVgOTvnQVQ2lSk0uCthy2hW6ifs/963Zt+VMvrQQS6N8zZE8pHQoOAUA7m1PUUWwv3u/oo63tWAjoSwEe6e9cfGMVRrIAMGlO1CTr+vVRX/Lbtg7XgXR1KEeLV1nDwNxuSOq7g4B4/mT/J0nnXNT7w/3siHUrtj6o+Wt9zubRLnx1ovkeJeOzTOyiENuHGS45MhRBpBDIditxomDXBbXB7jd++HHeCt9Ox9RJ2J9ncpY1VwK/TNypAf77bdkPGodJIaQe4nHLNPuT4v/O3AzBrxgbmxfbQ/pEkDYql9OZBUjndtVSRqM/bG11pgoORPfIfYphouJtx/U28vMuy0VqKYBFh0/oy04uQzs0xIdgrAImgcVYiHxYWr7D5lFLR5OJcvKxseUoCfAQ3obAsNoXYlFBRdTsCizqAXNkmm6xVBLtl7GJN3dpl2+dizDTWWSqrYwjGcJf50HAknHtCQhXztw+YZiUT9KWSBSOrBJis05k/NSUezbEwUdXOGXBAkYQOoOdfYJ+/ppRjP8pp+G+dolP6Zz2ggr0u3qQuL9V6dMLG9jn/RFcJSnnCyNN9B6V/BP+QXuy+XL5LkhF+oV0qXk2pRjxnJ8WpOA U/Artr0S lirQnxl1Tsh/yy7pFy2coXeHrc+pw3y5JSsU6Pa+iKA2UhUfDOsqq6vmjFYSSY+wstnUzurTbRMl66SuysOoRbpzwSgQ51J7lAJIOd5aZmHhxczDbmSQzeNrlS+1oLFhTjoEyZ+XsXfijzhS7NumYNOl+5lV0Gm9WQs2qWnNZSwQNoZJsPWyWcXdz6//M9dsFPIZsntDISxCFpbSK7VDW8kNMHmcb/8BJFuE4aesX69nTg40LS4ulLBt3mlXkrLmh1DgjVMjZcLZDih0YIXazFnEcN60/zldmJVZ3TRYVV7vXJWJeqjMAawtrX+g6PLIPXC9xzJZQH/IXCUs+EwSIAyLuvdKQwoRxSKFnxzw7MO6TEL9PAbzOeearoyBhqExqBuQC33wzzXHeQmeO3UjW7GYgXnq6mqx2HL12NtqPQZ7EXq5XV6/Gnur67JxjI90RbhVMoDG3S+aBEPVjUgyMQgy0Vmjwt7yiGQ+4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jan 18, 2023 at 11:01:08AM -0800, Suren Baghdasaryan wrote: > On Wed, Jan 18, 2023 at 10:34 AM Paul E. McKenney wrote: > > > > On Wed, Jan 18, 2023 at 10:04:39AM -0800, Suren Baghdasaryan wrote: > > > On Wed, Jan 18, 2023 at 1:49 AM Michal Hocko wrote: > > > > > > > > On Tue 17-01-23 17:19:46, Suren Baghdasaryan wrote: > > > > > On Tue, Jan 17, 2023 at 7:57 AM Michal Hocko wrote: > > > > > > > > > > > > On Mon 09-01-23 12:53:34, Suren Baghdasaryan wrote: > > > > > > > call_rcu() can take a long time when callback offloading is enabled. > > > > > > > Its use in the vm_area_free can cause regressions in the exit path when > > > > > > > multiple VMAs are being freed. > > > > > > > > > > > > What kind of regressions. > > > > > > > > > > > > > To minimize that impact, place VMAs into > > > > > > > a list and free them in groups using one call_rcu() call per group. > > > > > > > > > > > > Please add some data to justify this additional complexity. > > > > > > > > > > Sorry, should have done that in the first place. A 4.3% regression was > > > > > noticed when running execl test from unixbench suite. spawn test also > > > > > showed 1.6% regression. Profiling revealed that vma freeing was taking > > > > > longer due to call_rcu() which is slow when RCU callback offloading is > > > > > enabled. > > > > > > > > Could you be more specific? vma freeing is async with the RCU so how > > > > come this has resulted in a regression? Is there any heavy > > > > rcu_synchronize in the exec path? That would be an interesting > > > > information. > > > > > > No, there is no heavy rcu_synchronize() or any other additional > > > synchronous load in the exit path. It's the call_rcu() which can block > > > the caller if CONFIG_RCU_NOCB_CPU is enabled and there are lots of > > > other call_rcu()'s going on in parallel. Note that call_rcu() calls > > > rcu_nocb_try_bypass() if CONFIG_RCU_NOCB_CPU is enabled and profiling > > > revealed that this function was taking multiple ms (don't recall the > > > actual number, sorry). Paul's explanation implied that this happens > > > due to contention on the locks taken in this function. For more > > > in-depth details I'll have to ask Paul for help :) This code is quite > > > complex and I don't know all the details of RCU implementation. > > > > There are a couple of possibilities here. > > > > First, if I am remembering correctly, the time between the call_rcu() > > and invocation of the corresponding callback was taking multiple seconds, > > but that was because the kernel was built with CONFIG_LAZY_RCU=y in > > order to save power by batching RCU work over multiple call_rcu() > > invocations. If this is causing a problem for a given call site, the > > shiny new call_rcu_hurry() can be used instead. Doing this gets back > > to the old-school non-laziness, but can of course consume more power. > > That would not be the case because CONFIG_LAZY_RCU was not an option > at the time I was profiling this issue. > Laxy RCU would be a great option to replace this patch but > unfortunately it's not the default behavior, so I would still have to > implement this batching in case lazy RCU is not enabled. > > > Second, there is a much shorter one-jiffy delay between the call_rcu() > > and the invocation of the corresponding callback in kernels built with > > either CONFIG_NO_HZ_FULL=y (but only on CPUs mentioned in the nohz_full > > or rcu_nocbs kernel boot parameters) or CONFIG_RCU_NOCB_CPU=y (but only > > on CPUs mentioned in the rcu_nocbs kernel boot parameters). The purpose > > of this delay is to avoid lock contention, and so this delay is incurred > > only on CPUs that are queuing callbacks at a rate exceeding 16K/second. > > This is reduced to a per-jiffy limit, so on a HZ=1000 system, a CPU > > invoking call_rcu() at least 16 times within a given jiffy will incur > > the added delay. The reason for this delay is the use of a separate > > ->nocb_bypass list. As Suren says, this bypass list is used to reduce > > lock contention on the main ->cblist. This is not needed in old-school > > kernels built without either CONFIG_NO_HZ_FULL=y or CONFIG_RCU_NOCB_CPU=y > > (including most datacenter kernels) because in that case the callbacks > > enqueued by call_rcu() are touched only by the corresponding CPU, so > > that there is no need for locks. > > I believe this is the reason in my profiled case. > > > > > Third, if you are instead seeing multiple milliseconds of CPU consumed by > > call_rcu() in the common case (for example, without the aid of interrupts, > > NMIs, or SMIs), please do let me know. That sounds to me like a bug. > > I don't think I've seen such a case. Whew!!! ;-) > Thanks for clarifications, Paul! No problem! Thanx, Paul