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 B4AF5C004D4 for ; Thu, 19 Jan 2023 19:47:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 046116B0072; Thu, 19 Jan 2023 14:47:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F10A66B0073; Thu, 19 Jan 2023 14:47:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB2736B0074; Thu, 19 Jan 2023 14:47:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C9E5A6B0072 for ; Thu, 19 Jan 2023 14:47:50 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9DEE8160D7B for ; Thu, 19 Jan 2023 19:47:50 +0000 (UTC) X-FDA: 80372583900.05.B37F0CC Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf15.hostedemail.com (Postfix) with ESMTP id D53E2A001C for ; Thu, 19 Jan 2023 19:47:48 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tRwk9+zu; spf=pass (imf15.hostedemail.com: domain of surenb@google.com designates 209.85.219.177 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=1674157668; 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=P2j6lHak2WNm7vGtRzqgYAFuvxH6JX58ZqrhL7ZQFfg=; b=aR5WpG8zmJlFwrniBJH4h7/d0FKbOxPuKxsMEJ0ttKqfX2SgM3RdNFUio7VXtixuMef48u E61G3I//fbo0bT67U+UqW+S7tI1t+yERnP3HWGmpkB4snSirs820mZTUUU66L1mTzO4cOa JbamE1O1jZBq+3LUvP8AoTwPl32EFZY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tRwk9+zu; spf=pass (imf15.hostedemail.com: domain of surenb@google.com designates 209.85.219.177 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=1674157668; a=rsa-sha256; cv=none; b=Yv9O7rSYg4NsQaq28cS6PdFekQwqKMfCXnO7raJ/cUXyjOzHOXNVj72HQuQ8IYTXmyq4eN t6vhZODW9LA766v5YePj6WSlrfJJd1I3GyImF5vxoRCpACicT9bN42w6zJvnBRLlqUmyk9 VM9t5rI52szCRy8/BNEYRkwuEz6iFeA= Received: by mail-yb1-f177.google.com with SMTP id p141so1228929ybg.12 for ; Thu, 19 Jan 2023 11:47:48 -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=P2j6lHak2WNm7vGtRzqgYAFuvxH6JX58ZqrhL7ZQFfg=; b=tRwk9+zuhnApnMpCZGGlzVwa+yZTlhQpdZ6D/DvhQoFQpUTQCeM6lA4awAgkKlc6pA 569vcWotwshb2MJ3asbawGKsmiAf/09j93YtvGPhv8aIXeEodHvuQSIQ5ljSUAkeCXzO IqeRDxz6EbgbHh8k87h+XcI+Gi5IBdHJFL4tHPiahQxfVXpu36hpl3PHH/mKcKNvwhOv UCU76RUWF05xBZwsRriVr7hQXTTtQJ2FG3IoMxW3Mwj2/MvvT/4EBXFgCKYYlhd3hGTR 1qkSNLLzjXoHMCy86p9goHtqYEOQIkIXGOFAkld/l51jc9hZeYZmW078//u/yo9FNWkJ t4Jw== 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=P2j6lHak2WNm7vGtRzqgYAFuvxH6JX58ZqrhL7ZQFfg=; b=FQy12vlypAZGw5bi6ll3vLw+kq8RfctKQcP7fRFkiDJ2Vj6DFWWwZ9l98pLwnGYCTf kgeuf8ovNGd/ZUZy37xrCH/Dd1qqBdK6b+INeuIbyhNL+7WsGKeymXXh7Ud+rJb4lgx6 6zbUMqkrnZ7lX9dvupA3EGDfRIh4G8PeUW0Aj0Khimj+NGzLKg64UPD2+MsR8baIzq70 D2+T3i287y36CPY3OKk9p47hgyXYoWv7gMh6UFkzxevzKt2uaZcLnyKixtC1670nFOYo /Jw9vBo+PfiLDt+d6PA7GtCL50F543sfmmSptU8J/MH3ksp+YajwADvZIG6rReGbp693 4NKw== X-Gm-Message-State: AFqh2koIOBOjMBMLVoNqV88lzpQnAVT01DRhCHFPdKW4Cn9Df/XPEP8S 4mnjvyvZmSJ55o9RPN2Rm5AqUiVcyYP2HwhvF0nYcw== X-Google-Smtp-Source: AMrXdXtVjG1suljuq7kTbxad3urbLbwnBS0I2yo5AivnT5FA4XZ5/ePVWQvbEfh73NgWws2sOxQOIRQCI7QYYkEgZCg= X-Received: by 2002:a25:ceca:0:b0:7e4:115c:9cf6 with SMTP id x193-20020a25ceca000000b007e4115c9cf6mr1417330ybe.316.1674157667650; Thu, 19 Jan 2023 11:47:47 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-40-surenb@google.com> <20230119192002.GX2948950@paulmck-ThinkPad-P17-Gen-1> In-Reply-To: <20230119192002.GX2948950@paulmck-ThinkPad-P17-Gen-1> From: Suren Baghdasaryan Date: Thu, 19 Jan 2023 11:47:36 -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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D53E2A001C X-Stat-Signature: exz7txnouwtqjiqf67yhmnmwnsptmgb1 X-HE-Tag: 1674157668-728483 X-HE-Meta: U2FsdGVkX18qkrfTpUhH6N/t2izN1MGIzAEW1BE6PU4q/1g6g6UsnZvd6NnPJ2A3vLJ5rYLg0HaUKRfqYUGKng0IQU3OVEoMjFEiQbnDdmwS4uIKDlvQkHwRm1Jz7m0fuuCNSBgHHQdHaNq697YxBn6OCaS3O/EPxvwW8L5lTftxKnCrr0Z87fyM7yzOfVoGiyplVyYtCELqdCOnUzQBXNFbwgEHIteFL2IHf0K13M3yMRWK9kOkz1TiC/VfujrZOoCz/2l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zmPWT3xqg9yOwZr9ERCXuetN7e4JKrvwyhYGh 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 11:20 AM Paul E. McKenney wrote: > > On Thu, Jan 19, 2023 at 10:52:03AM -0800, 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. WDYT about time domain throttling to > > limit draining the list to say once per second like this: > > > > void vm_area_free(struct vm_area_struct *vma) > > { > > struct mm_struct *mm = vma->vm_mm; > > bool drain; > > > > free_anon_vma_name(vma); > > > > spin_lock(&mm->vma_free_list.lock); > > list_add(&vma->vm_free_list, &mm->vma_free_list.head); > > mm->vma_free_list.size++; > > - drain = mm->vma_free_list.size > VM_AREA_FREE_LIST_MAX; > > + drain = jiffies > mm->last_drain_tm + HZ; > > > > spin_unlock(&mm->vma_free_list.lock); > > > > - if (drain) > > + if (drain) { > > drain_free_vmas(mm); > > + mm->last_drain_tm = jiffies; > > + } > > } > > > > Ultimately we want to prevent very frequent call_rcu() calls, so > > throttling in the time domain seems appropriate. That's the simplest > > way I can think of to address your concern about a quick spike in VMA > > freeing. It does not place any restriction on the list size and we > > might have excessive dead vm_area_structs if after a large spike there > > are no vm_area_free() calls but I don't know if that's a real problem, > > so not sure we should be addressing it at this time. WDYT? > > Just to double-check, we really did try the very frequent call_rcu() > invocations and we really did see a problem, correct? Correct. More specifically with CONFIG_RCU_NOCB_CPU=y we saw regressions when a process exits and all its VMAs get destroyed, causing a flood of call_rcu()'s. > > Although it is not perfect, call_rcu() is designed to take a fair amount > of abuse. So if we didn't see a real problem, the frequent call_rcu() > invocations might be a bit simpler. > > Thanx, Paul