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 36F6AC25B4E for ; Fri, 20 Jan 2023 18:42:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64E166B0071; Fri, 20 Jan 2023 13:42:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FE1D6B0073; Fri, 20 Jan 2023 13:42:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C52E6B0074; Fri, 20 Jan 2023 13:42:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3DDC46B0071 for ; Fri, 20 Jan 2023 13:42:33 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0BAD08075B for ; Fri, 20 Jan 2023 18:42:33 +0000 (UTC) X-FDA: 80376048186.18.9C100F6 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf07.hostedemail.com (Postfix) with ESMTP id 589DA40002 for ; Fri, 20 Jan 2023 18:42:31 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=OqxeLPVY; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of surenb@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674240151; 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=8yb9zlv0Fl/IYbvB0WWSWiKf6OADONZOE7K+mXp3Y6I=; b=VleLh0S1I2YEjvE3yA3nKCvHa5WG3x2vM8Fsr4Zzyl/thJffzHj54oxCj6asBdP6MX77XX NBQsiTNh2J9Eh1yLcWpsqs4MygbRVPCfzpFyd4mH69pjYEkSVy6nNeCZt1oiLZr0IVSmdN tPZwMx5KEcVX95lNDvA74AQM5q6FViU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=OqxeLPVY; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of surenb@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674240151; a=rsa-sha256; cv=none; b=e8KQZarLETFVgJQQzeG2oY6PgUMvgepDso5WPyYssKXjPa3tjoKusV70ApiSZwK9GEPVXv YDSEeBxi3S23TEDskl+ULtQf29N8hd8V2W2SxrXy3ltQQ+sDc3cnGnibxBg6UfZYhvUECW kWl0KtnLMhfPTD+GQoOlSHtCdSBGVxE= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-4fda31c3351so55942497b3.11 for ; Fri, 20 Jan 2023 10:42:30 -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=8yb9zlv0Fl/IYbvB0WWSWiKf6OADONZOE7K+mXp3Y6I=; b=OqxeLPVY+krRPbuAleh+D+kRq9eoi+WL0Zg5tLk44bbMXCJnLKnQkTPFE9zZ13gTLi mBKFHB2WR8VOw8TFwSbJU8qQHmF2D93Ce11KWQvbaS0HcMXyvbCe+on43LRjPMtc4xZ1 vCkWPK81+Uta9ojjKc3K9f5xlmFs7LyMOLiDJD8riY/ChroO5zXDIpIZDTGX0iq+wXjX rAciU0bPyVQXYsQ9xMvFLi5tpJhrpjfcZ2LiYJ1fFw4Nya5+RPjUeeJ9GS4rPkenYIZk EcZmC4ATyI97rxHsPOnbYUvVNqazmV8mcNLa8DK6m69+95LCWL1M2XqUvs430E3UA3Mu MKsg== 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=8yb9zlv0Fl/IYbvB0WWSWiKf6OADONZOE7K+mXp3Y6I=; b=FjgsovxPJNc0EJrPiDN1vJmayBYHByf4pzGFNMF+n5+O/o3ISuU6/qMAuip+W2gGrx J/83MKjEBvqiVOZnwWoEbgmbKM+j67o71LxekbvIH0m6w1e4h1kAWy6JZMDzfuwg52Go YE9YLCc6EHRt0B8VQ4DWF41bFzEJIvIUCemEI76+5cQnwvfO5bMJ9pO1QmLV6aSNohzL oa1SoXVQ563DeLlJEuqTZOULCaND3LS6rpJTaycFd3ga0JxP/VNoujV1ORMqO+n1SUvl y6c+yZYB+Yapot3u4Fru4jsGGhpJDnXmPmTuNDSZ8ypav89vaHbbw2Iq/tUa0f0dqAcF KSNA== X-Gm-Message-State: AFqh2kqAfxSe1fpbvfOwzl7QFGzbXfgtyA7EGNj7ri9hMoJwXslbzgFx ZaGWkDRhxrk3RM6JdDk7ikHj7M5Rgl+Ku9gmB7Dvhg== X-Google-Smtp-Source: AMrXdXvtn4UGZgzxG45YYNgiCF8TyR8V/vYHcCDAw2jaiyhLgI91qbTnWOU4ys0ojd68P8jMZVqiv5UrhWKEYqhpeOs= X-Received: by 2002:a0d:c0c7:0:b0:502:30d7:5fff with SMTP id b190-20020a0dc0c7000000b0050230d75fffmr159281ywd.347.1674240150044; Fri, 20 Jan 2023 10:42:30 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-40-surenb@google.com> <20230120172140.GL2948950@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20230120172140.GL2948950@paulmck-ThinkPad-P17-Gen-1> From: Suren Baghdasaryan Date: Fri, 20 Jan 2023 10:42:18 -0800 Message-ID: Subject: Re: [PATCH 39/41] kernel/fork: throttle call_rcu() calls in vm_area_free To: paulmck@kernel.org Cc: Matthew Wilcox , Michal Hocko , akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, 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-Rspamd-Queue-Id: 589DA40002 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 4swieri3ogbh1xbdd5k867ccpjjx1jy4 X-HE-Tag: 1674240151-225928 X-HE-Meta: U2FsdGVkX18hXVO/hoomHGfFmnYDUayhQFmLhyckE4wHoU0BNPKBWWT+YO+U5Lo50SKuxW+McglhSt91DI8OrR/hIriE4AlrF3iSykQk1mJxLwxbUNDw5SsuJfmyE/Vo9MXxVBvc5erTr1IVcliT6tI0A+bgv3P4oFpY2QqHvdRTzjJ8W3R6uYr1e0JCL8oFZLv6QfOKsBzwLq2DrseDA3Px9quWI+2bsDdUSFcUX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vw2VOsGPDPL5nzEPRCD6o4cNHKvkNH2aesX8k60smKkjaEfD4VyaK30+5COPTnvR2ZQiIxannsR9uQql0JUhj3YQlopXHMXhxftjD9a8oMDSQHEAEY0B74wb8CJkzxb3kMTWjQwYLeN/O1lkiISg8NvNsGZbusBjVCkI7glNov6Dj+qIE= 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 9:21 AM Paul E. McKenney wrote: > > On Fri, Jan 20, 2023 at 04:49:42PM +0000, Matthew Wilcox wrote: > > On Fri, Jan 20, 2023 at 08:45:21AM -0800, Suren Baghdasaryan wrote: > > > On Fri, Jan 20, 2023 at 8:20 AM Suren Baghdasaryan wrote: > > > > > > > > On Fri, Jan 20, 2023 at 12:52 AM Michal Hocko wrote: > > > > > > > > > > On Thu 19-01-23 10:52:03, Suren Baghdasaryan wrote: > > > > > > On Thu, Jan 19, 2023 at 4:59 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. To minimize that impact, place VMAs into > > > > > > > > a list and free them in groups using one call_rcu() call per group. > > > > > > > > > > > > > > After some more clarification I can understand how call_rcu might not be > > > > > > > super happy about thousands of callbacks to be invoked and I do agree > > > > > > > that this is not really optimal. > > > > > > > > > > > > > > On the other hand I do not like this solution much either. > > > > > > > VM_AREA_FREE_LIST_MAX is arbitrary and it won't really help all that > > > > > > > much with processes with a huge number of vmas either. It would still be > > > > > > > in housands of callbacks to be scheduled without a good reason. > > > > > > > > > > > > > > Instead, are there any other cases than remove_vma that need this > > > > > > > batching? We could easily just link all the vmas into linked list and > > > > > > > use a single call_rcu instead, no? This would both simplify the > > > > > > > implementation, remove the scaling issue as well and we do not have to > > > > > > > argue whether VM_AREA_FREE_LIST_MAX should be epsilon or epsilon + 1. > > > > > > > > > > > > Yes, I agree the solution is not stellar. I wanted something simple > > > > > > but this is probably too simple. OTOH keeping all dead vm_area_structs > > > > > > on the list without hooking up a shrinker (additional complexity) does > > > > > > not sound too appealing either. > > > > > > > > > > I suspect you have missed my idea. I do not really want to keep the list > > > > > around or any shrinker. It is dead simple. Collect all vmas in > > > > > remove_vma and then call_rcu the whole list at once after the whole list > > > > > (be it from exit_mmap or remove_mt). See? > > > > > > > > Yes, I understood your idea but keeping dead objects until the process > > > > exits even when the system is low on memory (no shrinkers attached) > > > > seems too wasteful. If we do this I would advocate for attaching a > > > > shrinker. > > > > > > Maybe even simpler, since we are hit with this VMA freeing flood > > > during exit_mmap (when all VMAs are destroyed), we pass a hint to > > > vm_area_free to batch the destruction and all other cases call > > > call_rcu()? I don't think there will be other cases of VMA destruction > > > floods. > > > > ... or have two different call_rcu functions; one for munmap() and > > one for exit. It'd be nice to use kmem_cache_free_bulk(). > > Good point, kfree_rcu(p, r) where "r" is the name of the rcu_head > structure's field, is much more cache-efficient. > > The penalty is that there is no callback function to do any cleanup. > There is just a kfree()/kvfree (bulk version where applicable), > nothing else. If Liam's suggestion works then we won't need anything additional. We will free the vm_area_structs directly on process exit and use call_rcu() in all other cases. Let's see if Michal knows of any case which still needs an RCU grace period during exit_mmap. > > Thanx, Paul > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >