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 64B4EC05027 for ; Fri, 20 Jan 2023 16:08:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A42656B0072; Fri, 20 Jan 2023 11:08:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F5536B0073; Fri, 20 Jan 2023 11:08:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B9ED6B0074; Fri, 20 Jan 2023 11:08:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7B6CE6B0072 for ; Fri, 20 Jan 2023 11:08:36 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2B87A40621 for ; Fri, 20 Jan 2023 16:08:36 +0000 (UTC) X-FDA: 80375660232.22.0DBAC4F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 1B9C540012 for ; Fri, 20 Jan 2023 16:08:33 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hjm+fR7l; spf=pass (imf27.hostedemail.com: domain of "SRS0=LVeK=5R=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=LVeK=5R=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=1674230914; 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=qp5usidh1kARl5posVSgu/7oo61qCeGCd+gnBQrILN8=; b=aE12tQcDgHpuPvL75jwngN5bTwnrrh/4kD2tDAh4Ab9d5hPGXAnnNXPldtt+T/Cqf4gJn3 6BK09VIhaogr0X6OYiUEUGhp6wO99VVXraZXmmaTW1ufrfVSWc4knVsi82URcux8cIynUh o4ctS8SpDCeZBn9YxOmlqltr6XaWA2o= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=hjm+fR7l; spf=pass (imf27.hostedemail.com: domain of "SRS0=LVeK=5R=paulmck-ThinkPad-P17-Gen-1.home=paulmck@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=LVeK=5R=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=1674230914; a=rsa-sha256; cv=none; b=Iya/1AIyGEYyuSITfTztTFnaIqRTPX9RnI7xj8Rpum1I/MM90hP9V/Uc2XTTNJ1BWrXfLI cfRVO3Rlz55PGVavipFeqvIYqfQWe0Pp9YU2jSmIyFylBIdsJnckRy+1TPJbeoi8y3iY9g A9HHnXudMwU4RbmuH+D4sYz61HeTMCk= 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 12B4161FE5; Fri, 20 Jan 2023 16:08:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D17CC433D2; Fri, 20 Jan 2023 16:08:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674230912; bh=l+Ax8n5nsemwAAmfAXhYYe/dbUQh2EPit95uZHw42Mg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=hjm+fR7lK+KW1tSyt9SI4OCbh/B22uL761f7Rdogw9S21bTCKacSNGlrC5t1rx3RP D8/Om6iWcNgRjJEMTRMM5ZpU/Td2mWlAy/UZdfn6/LuGuKqnAbkpLsSehhLW4yHvk3 h1BMr23yJiqKbI99fg6yZIhrbWL2xZKsoCk0gasd1J5urIsRsi6zgm+AA6t+FNr4E3 3spHrjCEmcPLRy6yCMUrdRhCiXicFDAoBo/qpKeiGmRh8/SDXkGSiIiBAUEeC1kwqN i2zkRryRjeLO5m2NP2YARZcZ0rHoJw1ZeEdEvcfyTDEz4i67fFWWtD5qC3xEhKeUGo VDR//jFwVWPJw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0599F5C0DFC; Fri, 20 Jan 2023 08:08:32 -0800 (PST) Date: Fri, 20 Jan 2023 08:08:31 -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: <20230120160831.GK2948950@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20230109205336.3665937-40-surenb@google.com> <20230118183447.GG2948950@paulmck-ThinkPad-P17-Gen-1> <20230119191707.GW2948950@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 1B9C540012 X-Stat-Signature: 6fhijxyy5bus45f3zgz64gcfx838o4nf X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674230913-297506 X-HE-Meta: U2FsdGVkX18f/voSeExtyWHOnw1fCketBibGO+dOGjb9rMJsPmWYWe+6rngNNv2670JIWiw3fpRCb1vU63a39vAJoXfXgt8P9Pn/8zASeZTr/botpqfIZG6q0r+o6T+lBeQH7BTTuwgWytW1efelsSeibcIG9jJW8Lj7jFZCQA1sJgchNjuyVpaSjHZHxgN5YrYOr9+JrpXzJyDpGzqV5ad4HxbBOoWSBy9W6bhUlnjFDAbs6QJPf54aNW6N2qQ+rnthKrVBdA4ZXxHJOG0B74fJqyF3JR/0x4je1ixF8fSpids1fw6k4lHkLYNMF4p5LJFlPbvhhQRbMum0TClM8TXkd9v5rBrhxz4AnVFibz8/aVOZ2JDayag8BTRo3KyEJnow6gtmp28+S477M3FZOX28hYz0qAd4j4E8Uw6aVkWSAY/UQ+ogwLRPhVXFPXDk73uyJMuaseMqYoXEiDecsHTzlQpyYcsz+6QjCUtFJR2xuFutD3dl2cgy3VvChJCSJJhxRdHkw6k2+yfTw9ARqTAwXraKz0bfUw3Bo6054BPfaDPShbF7iYdojj215SNjdxXKhOxQR2VSQFYunvl9oFO+rawL02BuiejXS0JdbPrO4W86LnE9wjEnwqQylEDwcFeN68MRSlsGfUOxaVQ/3lSyMRzch3aaf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id78jz8qbH1cImYtLEzNTSbqin4nCNPgLBtcm9D4= 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 Fri, Jan 20, 2023 at 09:57:05AM +0100, Michal Hocko wrote: > On Thu 19-01-23 11:17:07, Paul E. McKenney wrote: > > 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". > > Yes, this is expected. > > > 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. > > I believe that Suren claims that the call_rcu is really visible in the > exit_mmap case. Time-to-free actual vmas shouldn't really be material > for that path. If that happens much more later on there could be some > side effects by an increased memory consumption but that should be > marginal. How fast exit_mmap really is should only depend on direct > calls from that path. > > But I guess we need some specific numbers from Suren to be sure what is > going on here. Actually, Suren did discuss these (perhaps offlist) back in August. I was just being forgetful. :-/ Thanx, Paul