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 CA594C32793 for ; Wed, 18 Jan 2023 18:34:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 379066B0072; Wed, 18 Jan 2023 13:34:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 329946B0073; Wed, 18 Jan 2023 13:34:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA756B0075; Wed, 18 Jan 2023 13:34:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0E2536B0072 for ; Wed, 18 Jan 2023 13:34:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 95342120984 for ; Wed, 18 Jan 2023 18:34:52 +0000 (UTC) X-FDA: 80368771224.06.9764FBC Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf27.hostedemail.com (Postfix) with ESMTP id A14064001F for ; Wed, 18 Jan 2023 18:34:50 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=l7I9EeWk; spf=pass (imf27.hostedemail.com: domain of "SRS0=DEr1=5P=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.68.75 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=1674066890; 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=YAmXFW+OVusLsACKj6TYt94oGDD5pU11j0LYIPowwNc=; b=nvX9Y9bYRK0P7ckC//b873nJfXOKbgiFRod8j0OCWwII1FSY9s5CS+PLPfXrADoAH/ksy/ 61v6oBVbzl/DBxh+HivFRQdWiKPaYakzdPnPu2PdOk9xM0Y3/+Et0B5LWwI182aWTgRhTi hWE7Lfd/xd2T+3GO6jlnmXDD0HiPFlw= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=l7I9EeWk; spf=pass (imf27.hostedemail.com: domain of "SRS0=DEr1=5P=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 145.40.68.75 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=1674066890; a=rsa-sha256; cv=none; b=h7nO18EvFRb6+LSNbWkSEvdEDwyP9H3nrvNv+qqIWf/y5GEu/19F3z/eyG1D6P5nmL/zFm TgsZ+AkcxvlG3vsVmfpz5WIrWZG8abhmPdHDQtbEXf8oqIAAguVDL7vJzEg/y9Y4Y3efoM rWFmppP2CPfAoJ4UVnM0McOCQ/0uQGA= 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 ams.source.kernel.org (Postfix) with ESMTPS id 02105B81E13; Wed, 18 Jan 2023 18:34:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 991C3C433EF; Wed, 18 Jan 2023 18:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674066887; bh=WQ17/uS48eZ8vtlubVHsA2/zGXMyPtsK+cdglVuC3Rk=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=l7I9EeWkRjSLj1wGudDzwXdc0sESiedA3fjzJiVx+p/XRVSGBaesgKTbYGvFV/H+8 KP8ri+KTfIfSH8KTYyWNP8/ZtnZyQunMJHF7SvF8GN1aAk/DWoxRCFlAcWvfxYu0RC u87DKHHyUfCqMosqAlvct/bnRBhum4/aftEN0bB6UPhSQDj1ya/NAqC3qYBtVkZEkH HxW0N5S1ZUwrHHpY+f1tNg0x59vWWpgMQI49JqhKMmZ4pYL2yadwCBF0jyu3XWinLI 4B2q/swf54li/JxKiY7pxyv0AThLCSGhQi0IKcrPIzdXFPB3XcbujUUqAY25jTqCkX /heXQ/ilfGUlw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 3CC605C0920; Wed, 18 Jan 2023 10:34:47 -0800 (PST) Date: Wed, 18 Jan 2023 10:34:47 -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: <20230118183447.GG2948950@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-40-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A14064001F X-Stat-Signature: m5o5czryyrfcrs1d18whdkdxoy8cfnxd X-HE-Tag: 1674066890-987948 X-HE-Meta: U2FsdGVkX1+8u3clTiGxqfyhKlmq2iLD/pc2VCrJJT+/Bbk0gjSoDrsBMuUB/ArMAVz/s3B8zSQQSfaXEje6Ijjv6ZvDIaTCWfRmk/afskmsj9uFNi8JMoEhK6EEcWe+iK0IlAjL+aCI/qUuNGrdlH/xt0HC31zQFHD5eDMaI+p7tIMOXnzPPo/n55zGDVNR1IttHslOxSoiHKALYfVoth57EEUR2POBeT87ii2pcRg/5idkAbDvb2x4FnxtkJOwy9TcocVnGuDLMPfmiHOlWwRYTjUuDsk/U7mbrmMIUVVF3YHUlEkpKnCV4T1JzFOqiSLYxyXSEhvD6JY+/m54CFlmR/J/voYm9Bfkl843m6G8j1Pi8fDlsTOdur9ShuqfHIpuo91rU/HLsAABOVCx6xeTpmBZrEpb6cczOKa0Hj+XerxAkhhWESDHilsAXMMldHFT/MHJVrB6xtNx3DPCt3gI6fw7zlQAA8QYmEFKs12+IL+6uXRJRjTm6uJUz11vlsXlKTTauaE8HWf37+YDWVsRxBTKFy2zi55L6AjrFAlEd43J551PkjHeQ+ICgFpKvt/antdeSZr/RgTzqf/o6b+24khnPq6B8UP0tvwFWFBRRnCgQATLLzxA3GKym9fMxAuKQfdnMckSya4oAK55tju7omawJFkIGe66ct27SVXG9uyNePvf+EOC//7mPerwXPKA43GpLrHTctKoN0DHz2KTJS4R9gN5hKzHmsrtQED5KchkO9MRhVlUtNwu+mjB8ewGQ7wvjpN1rTVYO4bt6VPGjrCRnFqzPXezya4Zk1vKuB8nG5Easopy+XETkz8EPK8X34ECsjZSqAXR6Su/B2Zpls9Lsnm/LnW89OI2DtjWDvtx0YgOwOguyXSE8fixjZNoh16qi99cSra/sOUzuEpUuH7pCoRkXvmmwTnNQNDnGJp25nszPkHbsEKePJr94mQufyeJ6sda3j9X970 /sIyoz1f 4gtQjk7Dj9/KOLa0nNym54mU4YoCne5x6wdxKybRRNIuxPwyELn+zvA8BTMIZbGPe8XaCNtcu3MkRPEvslkRSIKq6gyQ0vgKjc8oaGewT3Glx0ozQezl4vDt6lSVIeSElEE1V1aHcf/SqUD80srxgnCl/KkiWw2M76h1uT8lr4xTvwZFeRNdpEVlT4vfbdwbcQWcDIAda15rh1DEvugwjSIBLQzu6DuGoapV/LJFAtf0qBESb/OrI3cG4Af1GThjmuMuUI8xQ70W+M+Fb+OonUBiQMqQuPwgeJWPeAlU9CPMrkFHBOiox1fFHL/R4X4iSZX1JFw4iiGLDc3L0UO2sEIo5ZpQJaedt3dLMNnjtCcpurLSpRSQMRs0OEVQgmRON00YtnnD1F+UiqLpKbG+WMYN4gEIS8WzBCVQOrnJfYSGNynak4vVLHRcoJH2wDp3v2l147UzMnfQw6yAtub5vri7DRr7VMfeCsBKq 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 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. 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. 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. Or have I lost track of some other slow case? Thanx, Paul