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 77E15C05027 for ; Fri, 17 Feb 2023 16:13:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 079B66B007E; Fri, 17 Feb 2023 11:13:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 002F06B0081; Fri, 17 Feb 2023 11:13:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC0066B0082; Fri, 17 Feb 2023 11:13:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C4B1A6B007E for ; Fri, 17 Feb 2023 11:13:16 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 95793A921A for ; Fri, 17 Feb 2023 16:13:16 +0000 (UTC) X-FDA: 80477278392.07.5EB6B4D Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf12.hostedemail.com (Postfix) with ESMTP id E32094002B for ; Fri, 17 Feb 2023 16:13:13 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Ps/3Ura3"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.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=1676650393; 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=J4EHWLfMVpn05LE1kL8V3EaRVJa2Vq/hdu+Zr2nir+A=; b=gzK/uvtdinwfa+YoQ5b10d49HSV2EJTMNc6YdwsJAmi8I6GRNgZNDsXSpZCFKemcPUwTj3 vL7tKMZ+fNB72H8QqFYuSTJhC4OcJ+E9U+Oxe3eQ/z5KE4BBa54E9BzgpKeK+1P41u1ABI 3ptuvlSfpjtv9Yhokqz+htTEii8bHyY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Ps/3Ura3"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.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=1676650393; a=rsa-sha256; cv=none; b=MFIsfLQf/KTpBQ8Al9pi8+hI7xPLVwyhwu1raNCQqFg13jPRFtNM9u+bHD+wjyDbmlC+Vb aVPO5l4YKtZ+AQxkCYI3HpUO4eJUl2makSoBTCoYsmxqRpDi7Z2z0rPdr4vPgXE4qN4Dge DmHHLxMYiDX4CneQd9Ait5E64MgiRME= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-5365893236aso13311307b3.5 for ; Fri, 17 Feb 2023 08:13:13 -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=J4EHWLfMVpn05LE1kL8V3EaRVJa2Vq/hdu+Zr2nir+A=; b=Ps/3Ura3iI/sgUgvz42dqxzsriO4I9cszr72+ddh2HMcmKhNMfYrqt5HL1Y86sjtN6 yu2myzRPHLctGeK0vbEnLBiPb+LDtXDpu1H/ngw8hd42q77djSNfEDuq2smOvHfVmvG5 jndrjIPwxv0mEFmpwF7d6AzaGw0QKW07BGmDwE/OV8XDtfAqz9YPEGlGej0Z1YGRB8M7 vS9f4qzXP+t1M77sBl6rLadj8ku4sO6zQg0RbTtATOc0mlsP4oO2LhtJiLBVsIdKQ9or eJRYL0nXT4a4l6+W9WgYSxzVHw1LfCBVuoX5M/HBbFMa1KMU+rAuVYnT32UPuo2CitFI Bknw== 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=J4EHWLfMVpn05LE1kL8V3EaRVJa2Vq/hdu+Zr2nir+A=; b=3CF0pU5nqd9TEuuXmrzBVFdmgIPQ5NlcI+huaYdBcWoe5MV0ji+9FwNwO5S+fP2jTU arWwLIE2mEaK4NFO17UdKKmHaUrQhttNb8hO8hmWqAtpcE7PIye9rksgGh/cTXOvhrqF Y99+6zZpg262m1Wz2tknBflOyQFtyOQxxKcBEJnEXT8U38VacYm+RciNw2XPw5cMI+VK mHTUkGMNg/lyG1N/fSB3GvrgiilIDwXOEp0pQ9gyPgHowz3KxMZ1r9c9MVYBcbErva3B ileZ9l9JoKs8OfBeth3KxRzeJ2FvUTKkPt8B5lTQoSZEkfCbc2sN5rIi5SvvN5yru6UO kmWg== X-Gm-Message-State: AO0yUKUoffgP4O+6FQv2DctTY3mC4GVwiPfEaLxR7t93kBpjDkS5yoG+ oUPPWM8vib59ymK3IJfDW6CVt5vEW1kvEW7Kp5iMHA== X-Google-Smtp-Source: AK7set8CiXM0E8YPU1/djoX0qPy+RyHJBDO7kI4idZxu74F7kxn5or+wulxu9xRZnwkebwpvo4C/y03As5+77Z+srdY= X-Received: by 2002:a0d:d54b:0:b0:534:c230:ff14 with SMTP id x72-20020a0dd54b000000b00534c230ff14mr317502ywd.7.1676650392893; Fri, 17 Feb 2023 08:13:12 -0800 (PST) MIME-Version: 1.0 References: <20230216051750.3125598-1-surenb@google.com> <20230216051750.3125598-27-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 17 Feb 2023 08:13:01 -0800 Message-ID: Subject: Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set To: Hyeonggon Yoo <42.hyeyoo@gmail.com> 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 Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: E32094002B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: eisnbp1izo6oxjy1w5az1bheucg63kif X-HE-Tag: 1676650393-922308 X-HE-Meta: U2FsdGVkX1+w0pbTXmbmnWVq+dxAiXulmveRnTNSBVZx0Z8axjQKteEKfdkljCQMqseTcu6Hv9oTDryjiP3G4ceEie+ZufI0hvD7I45sn7JQjEndMJumyEFM3kWeEZ5+zIjdJgE8aOf3I0RMqK6zWoGc2fzuY3K+FRsknfNIkwx5vjJlQOwokSq2jlxbKbOOlVwHoBLoc3QbBSVzoGwRk5AIKcRXQsHex7diYJgt1vrjE6sRwKYtUVfwm0WdsMrkCo8elHt8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QSk1ANE+4nGEJT2WUThLeQEutCgaF2FQFXwt87e2e2Vqv32z6ec8vEPXxOOuBESEyRhThzQMMoQw2PpuFPfmkUDKtAkOBvAdnnorpO/Qvh23aspHHXA3xsiYlz6FPR4X1op7677r8bbdNuWAD8QQ6YzbmKkGshENz8o95Ym0WNSbaXgs4M= 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 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? > > > > 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. >