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 F3F5AC46467 for ; Thu, 19 Jan 2023 19:17:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B3C86B0072; Thu, 19 Jan 2023 14:17:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 563DB6B0073; Thu, 19 Jan 2023 14:17:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42B3D6B0082; Thu, 19 Jan 2023 14:17:11 -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 330006B0072 for ; Thu, 19 Jan 2023 14:17:11 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 06CC91A0E06 for ; Thu, 19 Jan 2023 19:17:11 +0000 (UTC) X-FDA: 80372506662.04.081461B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 2676718001B for ; Thu, 19 Jan 2023 19:17:08 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FCre4bIy; spf=pass (imf16.hostedemail.com: domain of "SRS0=Mfk3=5Q=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=Mfk3=5Q=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=1674155829; 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=jr0GNte2sAw0bsLsNA+eA3tJ2QaxJ+LTxMBaOOBROZw=; b=IwKMV37SdDXjh+bT0UpB0ZNv6KGDLHbICimZvxqefclvR17fbPewEo6n0kBewfa70vya5p UzbWjtS7akEAHytev2R3JkFKSOfi6YSnvRTz8ZTS1kbSP2WqhzolvGHrRzs+YOb9ex3vym BWyhWQVQ2EHyVMJd3IdOJlaB536OPTw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=FCre4bIy; spf=pass (imf16.hostedemail.com: domain of "SRS0=Mfk3=5Q=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=Mfk3=5Q=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=1674155829; a=rsa-sha256; cv=none; b=DE5nZKdBePkcsatcGQbeQYoQr0U5F5hBz9T3iS3nPMyuoLz5tzldO+09mQF/ZO74adncWW cqL7fKInjq7MwyI1m7ndJHLer8DFMTzXw7hrcKs4NY8MNTdsatHyf9EgnJa8IbusERrkUR lkOouMJSaZwQVj5E+E5Lcsvv6l4eZL4= 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 23BC461D52; Thu, 19 Jan 2023 19:17:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C3F5C433F0; Thu, 19 Jan 2023 19:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674155827; bh=eCVbGXT27QnDo1PpAtkdYdCPSqT1Q5ve44Q8Q75yHjw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=FCre4bIyUsGr3UbsqKMkAQvOnNpSp+ZWq+NbqqKwwWefnRM01gepbNKLipNzquSuy TS1GmlOYCg6zD4+UEVOtBJY+0ZPzqe/LmfVDG1bJ9ZhVV0p32LzzMAiWRBMPn1T1h4 lAj0M0gK0MPei3TtqZWQkMcaTNS1rzDw3cKDdRJFes7uSpMhuW4+YiOaItA+N+gKAc JMMK/ovArgjTbmyUfDHcWXuHF2hwBrtaAlfxcWTYx4Ccah0CVipkCZ8Vylnq9UGQx7 NSQGdLJX6rKSEaJIAZ+2hMcEPpSmmYmmGZ10dwS+6DGIGltSWvjltMSHYoKUe32kIM fDrsAF3VjIYdg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0FE685C1A49; Thu, 19 Jan 2023 11:17:07 -0800 (PST) Date: Thu, 19 Jan 2023 11:17:07 -0800 From: "Paul E. McKenney" To: Michal Hocko Cc: Suren Baghdasaryan , 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: <20230119191707.GW2948950@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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2676718001B X-Rspam-User: X-Stat-Signature: u4hddaa3n4mtwrcgb415ofzfdtjhzn4x X-HE-Tag: 1674155828-524477 X-HE-Meta: U2FsdGVkX19agmKgs1SYaXWu6iiR3w45Z1bAuevoKbRCxPQYgg8ZK7Fq+KC5yTKEW8srq6rv3tTNKuSCer0vo4kSvrHs8Osm3hVhvJlTnj+nqZvba14LHSCMie6v1QLS07lOc2h51Td2mKkX1PW0d0HxfcKJm8JAA/Py55YDHSwrwjkLkPJPdHweNPhqZXxcOOk7VJl7sVAzlR4subKMcoiYaVnc7GwGpV/354PHrOEyhP5hFrFVKHiL63jOQSh3G74UUSmlROH/9h5Bn3napfvPXj7W7YYF1ptDjJHPqy8u6k0fsZ8KSt6/w27VthpgL3is8PIS9WmhANJwG060pcflTRd+3w+3Xd+3PNEmpSQw8xT9RnhyLQl8gG+YXJYTBTZNW2LZoyB1deCBtKzHrdcTvjP2uBdSOebSwoselVs6N2eD91cF/zRDnGE7/aO9GBsHEAEzgZ+3gLshvnKfP8YorwvLqbs4s66JVP8AHVkc0hMz+tZI9bmHEE7UCy1+PpuWhOd/QKdU2cg0zJc45Nx8oHHyHAnY2YchtRT09rfQsjbi6+saCbwvyTfmfcwBvFt0Y5pksDMidXClnAxnh0oMFV0iL764NERqbCoFaO5yGVQxkKl7/RfEAizw8x+NyysNZrWvIzJCBiCwLgnBTodLc2VflGIYV8PmR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llTsL3D7kJSRqyiEbN7vZ8cjhE8gu/zVZl3s= 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 Thu, Jan 19, 2023 at 01:52:14PM +0100, Michal Hocko wrote: > On Wed 18-01-23 11:01:08, Suren Baghdasaryan wrote: > > On Wed, Jan 18, 2023 at 10:34 AM Paul E. McKenney wrote: > [...] > > > 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. > > Thanks for clarifications, Paul! > > Thanks for the explanation Paul. I have to say this has caught me as a > surprise. There are just not enough details about the benchmark to > understand what is going on but I find it rather surprising that > call_rcu can induce a higher overhead than the actual kmem_cache_free > which is the callback. My naive understanding has been that call_rcu is > really fast way to defer the execution to the RCU safe context to do the > final cleanup. If I am following along correctly (ha!), then your "induce a higher overhead" should be something like "induce a higher to-kfree() latency". Of course, there already is a higher latency-to-kfree via call_rcu() than via a direct call to kfree(), and callback-offload CPUs that are being flooded with callbacks raise that latency a jiffy or so more in order to avoid lock contention. If this becomes a problem, the callback-offloading code can be a bit smarter about avoiding lock contention, but need to see a real problem before I make that change. But if there is a real problem I will of course fix it. Or did I miss a turn in this discussion? Thanx, Paul