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 35A0CC05027 for ; Mon, 23 Jan 2023 17:46:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1F986B007B; Mon, 23 Jan 2023 12:46:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA91E6B0080; Mon, 23 Jan 2023 12:46:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A225F6B0089; Mon, 23 Jan 2023 12:46:34 -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 922F36B007B for ; Mon, 23 Jan 2023 12:46:34 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 592B8123038 for ; Mon, 23 Jan 2023 17:46:34 +0000 (UTC) X-FDA: 80386793508.12.6640625 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf19.hostedemail.com (Postfix) with ESMTP id 67C191A001C for ; Mon, 23 Jan 2023 17:46:32 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="SdR/39hw"; spf=pass (imf19.hostedemail.com: domain of surenb@google.com designates 209.85.219.169 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=1674495992; 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=XGfK59iWA2VlvgRXkqRDqLtLKye7Z5SSTP2RGu4Ar9c=; b=Ws9Jqq6s3F/sZyDVO1QF7xuiC+FLdgs92sUa16/up1jBGvGW68pzUp1amubkS/k5Rz6MXp 2J6hS7uzDZxILh9bJlFWc0IhFpiGV75/sk+4AnTtTCTKl7R/JS3eblO3ObDqtmu+TcVTLX uA1k5gdjlw+NreWk4YlvIMJF6LmHEts= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="SdR/39hw"; spf=pass (imf19.hostedemail.com: domain of surenb@google.com designates 209.85.219.169 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=1674495992; a=rsa-sha256; cv=none; b=zKYexLUmkM+UNQsR9s9JETMFK92NTqV34pyBV8PZHO02V3T8eQxeH3T7mLlbf0mtl/TwZO MXQwTBMdUOsATK4WGOK02aek76Ytqh4Vg8rrdCNM0vhRW9QFRrysPWeJcTk3xaO6nm9T7W GGAgGYi8u5aM4TtqcVMgP+RiDzEIwSY= Received: by mail-yb1-f169.google.com with SMTP id 129so11829056ybb.0 for ; Mon, 23 Jan 2023 09:46:32 -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=XGfK59iWA2VlvgRXkqRDqLtLKye7Z5SSTP2RGu4Ar9c=; b=SdR/39hwgrAyKI4iGTaqEHY0PZx07Qq2iedH3AUTUZ1UbDUzkBukyUzn44oMlC56Q3 lkroO9Cs7sD/B778Bv2Qfm5VLknd6XgJWRlnBxIG40CWw30+itJvuAQtdRVW9AH1Xay1 KHj4xgWmJVEYuFp1ks8zPeSyal00rHWScfhwzQK3TM6RuZ9KJBIooS8YCnaAfUjDoSaR OKvFhrSSIlS7uiQQ/Jz51PzTN/X8l55QxRJYPJV2dK0vYMsU2JePdTp7/piHNQHUsCuO xKSnavE7rZxGa/wdyvkSpsuC03skPO5h7FOhPT10JRmp/3aHuwtuBNCTcnCuwJlm9dGH BTEw== 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=XGfK59iWA2VlvgRXkqRDqLtLKye7Z5SSTP2RGu4Ar9c=; b=IpGm+m7GhmGASxwy+p8XAD9envGlRNWQsE+dKaokTiwdlqSJaqleVAcu74857ivjTT BJwOUdnXQNkMX4QOzTq0TW02uQnnUDdgeeaKgJQbzPSbl3pzC1jlL0eV4wGNABogLouc B9dIr5DeDdIeJ4Q/c8/goNNF7uvtznGu354rYQI+QSsIeH90snALxMAzWWW56/X9ZuoG hvwZdcTj7o2k3JK/JM4dwE73Mmc++9CoZIOcJwV3g/VndkSsKcoHVowRtBaqpsuGWtGm 612zIa5knWBq0Ax9WR38eWxSIEWGRy3jPamexFdxPFf0j8sxf7rgVDlzFFtmyLZ9JgR+ YF3w== X-Gm-Message-State: AFqh2kq4TWHCaRW3w22DbqLF35s/B0u1J0RAXLVwDFibQ1XyE/coP4Hp yWM8ZEeXqbN6mYXQMHVa8oVVA9Cw+eX3JxRyUuJxcg== X-Google-Smtp-Source: AMrXdXteaJfzBdOfhYOTTo0923koQH1CezojDs1FTte0YsILtf2ySXsBRH58x0a8KuKynJ5TyY0FxTcWX+1TjHC2E1Q= X-Received: by 2002:a25:9801:0:b0:7d5:b884:3617 with SMTP id a1-20020a259801000000b007d5b8843617mr2229246ybo.380.1674495991353; Mon, 23 Jan 2023 09:46:31 -0800 (PST) MIME-Version: 1.0 References: <20230120170815.yuylbs27r6xcjpq5@revolver> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 23 Jan 2023 09:46:20 -0800 Message-ID: Subject: Re: [PATCH 39/41] kernel/fork: throttle call_rcu() calls in vm_area_free To: Michal Hocko Cc: Matthew Wilcox , "Liam R. Howlett" , akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, 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: 67C191A001C X-Stat-Signature: btxt97sbju7o3chrzdbe3xxdxxax733b X-HE-Tag: 1674495992-681204 X-HE-Meta: U2FsdGVkX1//idAi2wliAzLZxsoHVyCh4Ig3tK2uuUunfso87mi8St5d5C6uj6bncDX4VRuZS6xVAhYBPH2JJnHFhY4HCduPVei+/tzwdIzmN1YgUZog/28aDB1MYBwLGy8BC/Td0uuZpBlTrGkDU93BokUYxoJqLgJPCw7qHFjUZCD5Va7JE1VyL8Z/uNSma+KslJP4SQ7K3Xxm5r2Zy632CnA12evsrLIUFS/l5MztX/OHz/hbSJInB3VDPTJxxXjD8+KMOIzGSj/1iHoGMzX0GNbVy9+3/L6d0Wc/kSY/3Wh6DV5sMyBCBns2HTA2n96G02sWFP+pQTUZ7h6hZHniQ3m3/OO1Evd1l+ZKysHypOOpyGi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000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jan 23, 2023 at 9:16 AM Michal Hocko wrote: > > On Mon 23-01-23 09:07:34, Suren Baghdasaryan wrote: > > On Mon, Jan 23, 2023 at 8:55 AM Michal Hocko wrote: > > > > > > On Mon 23-01-23 08:22:53, Suren Baghdasaryan wrote: > > > > On Mon, Jan 23, 2023 at 1:56 AM Michal Hocko wrote: > > > > > > > > > > On Fri 20-01-23 09:50:01, Suren Baghdasaryan wrote: > > > > > > On Fri, Jan 20, 2023 at 9:32 AM Matthew Wilcox wrote: > > > > > [...] > > > > > > > The page fault handler (or whatever other reader -- ptrace, proc, etc) > > > > > > > should have a refcount on the mm_struct, so we can't be in this path > > > > > > > trying to free VMAs. Right? > > > > > > > > > > > > Hmm. That sounds right. I checked process_mrelease() as well, which > > > > > > operated on mm with only mmgrab()+mmap_read_lock() but it only unmaps > > > > > > VMAs without freeing them, so we are still good. Michal, do you agree > > > > > > this is ok? > > > > > > > > > > Don't we need RCU procetions for the vma life time assurance? Jann has > > > > > already shown how rwsem is not safe wrt to unlock and free without RCU. > > > > > > > > Jann's case requires a thread freeing the VMA to be blocked on vma > > > > write lock waiting for the vma real lock to be released by a page > > > > fault handler. However exit_mmap() means mm->mm_users==0, which in > > > > turn suggests that there are no racing page fault handlers and no new > > > > page fault handlers will appear. Is that a correct assumption? If so, > > > > then races with page fault handlers can't happen while in exit_mmap(). > > > > Any other path (other than page fault handlers), accesses vma->lock > > > > under protection of mmap_lock (for read or write, does not matter). > > > > One exception is when we operate on an isolated VMA, then we don't > > > > need mmap_lock protection, but exit_mmap() does not deal with isolated > > > > VMAs, so out of scope here. exit_mmap() frees vm_area_structs under > > > > protection of mmap_lock in write mode, so races with anything other > > > > than page fault handler should be safe as they are today. > > > > > > I do not see you talking about #PF (RCU + vma read lock protected) with > > > munmap. It is my understanding that the latter will synchronize over per > > > vma lock (along with mmap_lock exclusive locking). But then we are back > > > to the lifetime guarantees, or do I miss anything. > > > > munmap() or any VMA-freeing operation other than exit_mmap() will free > > using call_rcu(), as implemented today. The suggestion is to free VMAs > > directly, without RCU grace period only when done from exit_mmap(). > > OK, I have clearly missed that. This makes more sense but it also adds > some more complexity and assumptions - a harder to maintain code in the > end. Whoever wants to touch this scheme in future would have to > re-evaluate all of them. So, I would just avoid that special casing if > that is feasible. Ok, I understand your point. > > Dealing with the flood of call_rcu during exit_mmap is a trivial thing > to deal with as proposed elsewhere (just batch all of them in a single > run). This will surely add some more code but at least the locking would > consistent. Yes, batching the vmas into a list and draining it in remove_mt() and exit_mmap() as you suggested makes sense to me and is quite simple. Let's do that if nobody has objections. > -- > Michal Hocko > SUSE Labs