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 2F09FC636D6 for ; Fri, 17 Feb 2023 18:50:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B5786B0073; Fri, 17 Feb 2023 13:50:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83E766B0074; Fri, 17 Feb 2023 13:50:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 690DD6B0075; Fri, 17 Feb 2023 13:50:14 -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 53ACF6B0073 for ; Fri, 17 Feb 2023 13:50:14 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 10B834051F for ; Fri, 17 Feb 2023 18:50:14 +0000 (UTC) X-FDA: 80477673948.22.C02394C Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf13.hostedemail.com (Postfix) with ESMTP id 44EA420009 for ; Fri, 17 Feb 2023 18:50:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DoyZ0Iuv; spf=pass (imf13.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676659811; 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=txCbIcxMcKNWF/8/Xv4WaLkszxM0EFbIb80kOwi9Rfc=; b=zzlL9kYzuB4zSgBq61sokNbaxl7sOCoOxwudiWTBTIkIwkVLdD+/PurTVyyRG7wlfHoOD4 r/UM1IOu8Zxg/A+OI4vseHTJqzmw/LaH2ByJua7GSGNKe+timeO//wqetkiyopDDZxFgWU QVWTyakSXMTEZI8pEr3zNZlOTga/Un8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DoyZ0Iuv; spf=pass (imf13.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676659811; a=rsa-sha256; cv=none; b=it72GwO5WA4mys1Ek6HAMWz5XGGI01X/Kihi5PxgpjH6/Bj7bRXU6/y2HQRxeqUV2N6LBF twco/QTjO+BE8vdq+DR1P99BFao8B40/KlZDgrPGcneRo7vNKxpQ/UCbzYGXsQv8N9HatB StL4vKalcUPqd32t8DqA+/qkmFWNZy8= Received: by mail-pf1-f179.google.com with SMTP id o5so1240530pfw.10 for ; Fri, 17 Feb 2023 10:50:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=txCbIcxMcKNWF/8/Xv4WaLkszxM0EFbIb80kOwi9Rfc=; b=DoyZ0IuvT9n0MkYehst+WgppOwJf4TBkUptMWVrr+72g5BBNmp9R+Jd5HsD22vWeow +ry/TEXLMU/Ft/r1cC7WjqyybGO9b9I9SRDu2Eq7ratNg6JQgVlYkMw6wJWEO9M4yxGC FlzWFl6/rPQGxhqhVz0td9KNMibW9jb1iUL1loJleWrTIIi+sLaondd3j77EpBuY3HTt rNPjllusoF93h15OUC9ZM9HYWozAcsDcVY1LFhQMJYIlN+FIB9F6p+fT47ZdADXSKrAM AljoCIDQwQSc2Kh+R9yG0ImV7hvIvtbUWa8dB7ey2t4jTnSqPy6BE+l4VD980Ae/4VO1 /hng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=txCbIcxMcKNWF/8/Xv4WaLkszxM0EFbIb80kOwi9Rfc=; b=YffKO92+Fy30YVwhTnjqyx6vZ54mu4zymKxtJtWbnso97XKC9ydRL8hMgVGB2RYs2n HNyuNiLxSjOyyHbNDT8ZEyQAUlY5YZBec1AnmttNmofhI++nclExc0IrecHHl+yfhCH3 hq5ozpAywaPd/t9lN2aQx0D24eo4H0t4Q052CFAx5y9ysUGH59Kz3E8sN0xplxXnNF4K iePd8OzXTehmuZsfd123UQBtJfXbLDgDxaDVA5A8kRt2s5fYWeY0I+fI1EYzmlp3v1dL s2zHJfNc8W4YVnMfo0Iy9DpLO4IE94b4OzJKF/dNODLAFe33sheK1TcP/2/h4o2HGVnJ unTw== X-Gm-Message-State: AO0yUKXNaPQN8yNbS1ZcXBGPuqjacS93z+a6dmujsLwYBRDhC+q863g9 slnBJw5PSFt70tzwMcCADsU= X-Google-Smtp-Source: AK7set9KYoFRQrG2DJscVGs0pH8tAGSBxCGsCiCA+9GB+lMylmI+TFq2V2i+aqg9/Vw1XgM3dp91jQ== X-Received: by 2002:aa7:9608:0:b0:5a8:cbcc:4b58 with SMTP id q8-20020aa79608000000b005a8cbcc4b58mr1454308pfg.12.1676659810012; Fri, 17 Feb 2023 10:50:10 -0800 (PST) Received: from localhost ([2400:8902::f03c:93ff:fe27:642a]) by smtp.gmail.com with ESMTPSA id u21-20020a62ed15000000b00581ad007a9fsm3385410pfh.153.2023.02.17.10.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 10:50:08 -0800 (PST) Date: Fri, 17 Feb 2023 18:49:53 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Suren Baghdasaryan Cc: Matthew Wilcox , akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@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, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.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, aarcange@redhat.com Subject: Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set Message-ID: References: <20230216051750.3125598-1-surenb@google.com> <20230216051750.3125598-27-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 44EA420009 X-Rspam-User: X-Stat-Signature: 1xfbcjf7gfmd7frcz7xnr4yjnbaorse3 X-HE-Tag: 1676659811-573540 X-HE-Meta: U2FsdGVkX1/VfxgOyBDrFCHPlKVZmdJrv5n+NZRZystRlwGd5JjeO82icTdDzQeeL3JJHzf7uGz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PDnDx9col8xgDKchzUvKkiCzfkYDaObj5FdZNwvr7pDthSpAZ50jbVu+1jBYBvrzRJdwL9QBUCOewSlPCqX9UCX4w8ZF8x2YJlv27Nq1DY2B6vmvQrma+7ySqg7JIaRI9Kgi0jo8NV54I4ifkvrGBpElRQX3WAS9BZMjOTgO+KQFvMF9fWSMsKAGgklhK/FKewuWU9FX709EUNqX4nklgOcQELv7JYIKA6CEbjFv+xDIk9EQka7pFnUCyCp1WpmtRdQS54dInHfywUROK0FZT32UU/CS9pMjZf+ZHOX2+A5MNjlDTV0SRln8A3rD7cPdqmooAFvwhIPHdWB0ZSRI+nK5LcQvxIkz43yzIViiqA3zfu0OsXsaUFKHcRjokak7UNjiAD1lFHRLK/tyjMQFjfMzxxKZI6jtblUlCe3J3ZppY4/GP8pAZJ/W0Jm64S2dvFKCFdboMH+hezMvKUhhnNzo5MebRFjwnl4BR8J1FK/o0nK5N5gB83L0lga1X1+nUncROhfG23iY3+t3dOClJSiu/ljk2pi80CGZIknVA4cKruGKpifdSaT6m+q/ZAYHSI6gdSrlOmIIoTMOU9SqIm0hBn4t8uIp/bdYdoKywVucC8dIgDnkxtRBv38VRpXlm18oZmQFd1HqyMXbcgmNnA== 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, Feb 17, 2023 at 08:13:01AM -0800, Suren Baghdasaryan wrote: > On Fri, Feb 17, 2023 at 2:21 AM Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote: > > > > On Fri, Feb 17, 2023 at 11:15 AM Suren Baghdasaryan wrote: > > > > > > On Thu, Feb 16, 2023 at 11:43 AM Suren Baghdasaryan wrote: > > > > > > > > On Thu, Feb 16, 2023 at 7:44 AM Matthew Wilcox wrote: > > > > > > > > > > On Wed, Feb 15, 2023 at 09:17:41PM -0800, Suren Baghdasaryan wrote: > > > > > > When vma->anon_vma is not set, page fault handler will set it by either > > > > > > reusing anon_vma of an adjacent VMA if VMAs are compatible or by > > > > > > allocating a new one. find_mergeable_anon_vma() walks VMA tree to find > > > > > > a compatible adjacent VMA and that requires not only the faulting VMA > > > > > > to be stable but also the tree structure and other VMAs inside that tree. > > > > > > Therefore locking just the faulting VMA is not enough for this search. > > > > > > Fall back to taking mmap_lock when vma->anon_vma is not set. This > > > > > > situation happens only on the first page fault and should not affect > > > > > > overall performance. > > > > > > > > > > I think I asked this before, but don't remember getting an aswer. > > > > > Why do we defer setting anon_vma to the first fault? Why don't we > > > > > set it up at mmap time? > > > > > > > > Yeah, I remember that conversation Matthew and I could not find the > > > > definitive answer at the time. I'll look into that again or maybe > > > > someone can answer it here. > > > > > > After looking into it again I'm still under the impression that > > > vma->anon_vma is populated lazily (during the first page fault rather > > > than at mmap time) to avoid doing extra work for areas which are never > > > faulted. Though I might be missing some important detail here. > > > > I think this is because the kernel cannot merge VMAs that have > > different anon_vmas? > > > > Enabling lazy population of anon_vma could potentially increase the > > chances of merging VMAs. > > Hmm. Do you have a clear explanation why merging chances increase this > way? A couple of possibilities I can think of would be: > 1. If after mmap'ing a VMA and before faulting the first page into it > we often change something that affects anon_vma_compatible() decision, > like vm_policy; > 2. When mmap'ing VMAs we do not map them consecutively but the final > arrangement is actually contiguous. > > Don't think either of those cases would be very representative of a > usual case but maybe I'm wrong or there is another reason? Ok. I agree it does not represent common cases. Hmm then I wonder how it went from the initial approach of "allocate anon_vma objects only via fork()" [1] to "populate anon_vma at page faults". [2] [3] Maybe Hugh, Andrea or Andrew have opinions? [1] anon_vma RFC2, lore.kernel.org https://lore.kernel.org/lkml/20040311065254.GT30940@dualathlon.random [2] The status of object-based reverse mapping, LWN.net https://lwn.net/Articles/85908 [3] rmap 39 add anon_vma rmap https://gitlab.com/hyeyoo/linux-historical/-/commit/8aa3448cabdfca146aa3fd36e852d0209fb2276a > > > > > > > In the end rather than changing that logic I decided to skip > > > > vma->anon_vma==NULL cases because I measured them being less than > > > > 0.01% of all page faults, so ROI from changing that would be quite > > > > low. But I agree that the logic is weird and maybe we can improve > > > > that. I will have to review that again when I'm working on eliminating > > > > all these special cases we skip, like swap/userfaults/etc. > > > > -- > > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. > >