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 F1C70C32793 for ; Wed, 18 Jan 2023 19:01:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FF3E6B0071; Wed, 18 Jan 2023 14:01:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B0176B0073; Wed, 18 Jan 2023 14:01:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 376B46B0074; Wed, 18 Jan 2023 14:01:24 -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 273726B0071 for ; Wed, 18 Jan 2023 14:01:24 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D3CA1A0CE9 for ; Wed, 18 Jan 2023 19:01:23 +0000 (UTC) X-FDA: 80368838046.21.4469AFD Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) by imf19.hostedemail.com (Postfix) with ESMTP id 3BAF41A001F for ; Wed, 18 Jan 2023 19:01:22 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ejwY3+LK; spf=pass (imf19.hostedemail.com: domain of surenb@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674068482; h=from:from:sender: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=Z8DSKYHJgJYKJvmPul/jqy2wXXzLUlUgLi7Tkf9YlXU=; b=li59hGOoiLuuSDKaWgxPFa7mwisWIGxlhBy3ygkb87m2vwQ33aPNuHTr8TXLR9nxK9Pkmc +liEfHKbHvFMeiIwkvM+qXQqrlQ0NQs1AtM+DruM3oAwprsJx1Jy0V9Bup8n6hgrztnvKR mo2dJ7yMRbX7yIs0uh9hzUzwMNpio5c= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ejwY3+LK; spf=pass (imf19.hostedemail.com: domain of surenb@google.com designates 209.85.128.170 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674068482; a=rsa-sha256; cv=none; b=rnHMdIcp4t4TYBtdvvsKae3VDvbfSq0BePa037d8LaW7zigIKLqqgCYbBOqwL3AIbaqc55 AmSF8xa1mRbYcJ0ly+UzYmM8XqsEExWraHm3tle9b9QOhm0AOpglIZPSJbWuXfHEiVKLQE /G1QlJCJS8sZ5wRf9YbFiGTzn+qpamQ= Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-4c131bede4bso481705787b3.5 for ; Wed, 18 Jan 2023 11:01:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Z8DSKYHJgJYKJvmPul/jqy2wXXzLUlUgLi7Tkf9YlXU=; b=ejwY3+LKtxm5x3E+GJzfTUchB7m+L1YRon9Aa8Q50Ti4tQZzVZ6M7ddAXR8QuYX2/+ QbFt7G90bRjsGKuh+F1lDNIo0H7p5+Ztjzb+JsV1kzQB8MPN72CITN8khcfMdZzVCClr 0rfR86j8uR9XfP3lcG3CmwEZq8gGCNYy4GMw9BXNuo+B0XfUKFLgpaKByDGEKF5m5ob0 nAirCQpTYQiGnADXyL4rHN55X+6T7+KDx4Lknv/dk8Nf1obhK0VCQYfoZive5NaouN9J rWZ8CpiuCsm5NmaCNzdlzyweXpQ+VQ7Pr9lxoMOtqkqySGFLw02OuYspEMabUBJR88+S njvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z8DSKYHJgJYKJvmPul/jqy2wXXzLUlUgLi7Tkf9YlXU=; b=n8960RXaeGXNdsHvTwslOoYCP6y3DixSxyBP013USxAlJr0/eu93qootg8YO3UW2va D/ESZQ2RVH3uLCW6kZ+5eKuhte51c+p4T+jPd5SvCbqag+LN5xmp2Red6Cmi20PwXblY VTXXMAnSfc6EaOFDNKjzV2w7ReckRJgox28AHeI60ZsW2zdS+vi1RVm3IYelSwvIQ+Dw l5YaTHEkKHDimNwaAT84OLCkf4DiSQLh1LycEyJycz/sg0x4UrHtK0pm29rPJdZx+0UT pDR+Hy1MZpzrKJ2OzHzJl7ZXIovEPTyY0pkiKA3POo8MiyCqORScXF3MaEoA4ASHnOLe ok1A== X-Gm-Message-State: AFqh2ko52zqmQwRMm1CWzyPteH1ymT/WX23grIzhZeTe6gO5mr655Mjf FrRmqWaBhx34UHey269KDBATPJHaR0lL4yCpsOL7Wg== X-Google-Smtp-Source: AMrXdXubzcxtFjj0yWcsl/wowi8G0fcdGwos3LuYoWDDm/OjCNfgTh+Wjt7geFYZ2EGxVPVcRjYpoDeL03CkmRv1g5o= X-Received: by 2002:a81:6d8d:0:b0:490:89c3:21b0 with SMTP id i135-20020a816d8d000000b0049089c321b0mr1053073ywc.132.1674068480621; Wed, 18 Jan 2023 11:01:20 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-40-surenb@google.com> <20230118183447.GG2948950@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20230118183447.GG2948950@paulmck-ThinkPad-P17-Gen-1> From: Suren Baghdasaryan Date: Wed, 18 Jan 2023 11:01:08 -0800 Message-ID: Subject: Re: [PATCH 39/41] kernel/fork: throttle call_rcu() calls in vm_area_free To: paulmck@kernel.org 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 Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: kyb57pfw565xypymgbbj5emmhcwbu5i6 X-Rspam-User: X-Rspamd-Queue-Id: 3BAF41A001F X-Rspamd-Server: rspam06 X-HE-Tag: 1674068482-861675 X-HE-Meta: U2FsdGVkX1/pqBAZVC1T0G5qwoPLbCDWGiaW8CEiaF21eXxlmJ8sgTKv+NNCAklu9YWVdSE43jKTBl2mkW8gTD7ATz7AU+g3Qno43ONK/UJ70mdxYPJ+EjUpyV7WSO55xFVhEWmWHXtrZi0Q9oBYHirwxeHen9bWZnOO8CB06fqyTLU+wPAaaVy544COXLca/OvV2lg6Tn4c3HJididTlrRPQrOVn/cU5c5uUBg9mNYHVhfHADvYNuRFBRcKQhjOYNoP9AcYhhPuvPbgqk/5wKx7zoaBT7DMtxmvrjeGzzU9Yashuw1ia/DH35IV47FBWZii7U1scrXxEboI6UXfLDhDO4PFQBgOqcWilUWw2FIOrVFxwJGrFRHEKUm12Ap744iAxEyg+B7aLE08R5BuDJOZ4vL+BuCtrhwHCFUz65gWN3I74i7Wf3vKQfylnny7qr7bYmv2FEgY93dSI6dnFbcp9txFZfKIzoRwKs/eOHqSIMfXWX+wWlrsq0GSFYwb+CwQ9LRWYcpvK6urHVpZEXr4rjEwTfCQzs8m73eaIDQDtufOyvXe9+VdbQBAkvJo8sv9DPyvGayZPAMBDprJGUcJ7rEijxsGYLMvOoUhQjL3PrMKIBH2I0XLwiJqp8u+6wKcl7IHkpycUpKEddtaaAP63G8TKEsx6IC1UnayxCFNJ84UsaPI11fkDlPezMzUQKTR0+BScQybCoBZLaVLP3PCQq/W0Imd7NIO6362ZkEw4Xck06X5TH/H05IiJ/aVmlBHRiDiIIMeqoDrXVH/ybXaZK6lYmBYi016huvSaaaiBG2PYn8NqM0juNhypo/o6ML/XxKQRaNznly3rSRkoDWV33A0rq5US8cqRnd6pCfgLbXwp6XseiAley/7uNiVgsC680p4xBoBp71bKBZBa08ZnRxSx2qwPBoPEXaY1qR8loZZ3IiEkRkE9v2ZRFy8VWzqcplqx+LC6f0l8jB kDjNKtmu 7Oaqp1/TJ0FEKFFDincLrCtrSyS4a2rS0C5qTUngjEKffjQsNha43p1QATixa7qxeZ3gA 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: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. Thanks for clarifications, Paul! > > Or have I lost track of some other slow case? > > Thanx, Paul