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 D84CDC61DA4 for ; Thu, 16 Feb 2023 19:43:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 105B76B0071; Thu, 16 Feb 2023 14:43:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B5A16B0072; Thu, 16 Feb 2023 14:43:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC0206B0073; Thu, 16 Feb 2023 14:43:32 -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 D93F66B0071 for ; Thu, 16 Feb 2023 14:43:32 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id AB84FA092B for ; Thu, 16 Feb 2023 19:43:32 +0000 (UTC) X-FDA: 80474179464.03.A5236D8 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf09.hostedemail.com (Postfix) with ESMTP id DD13B140005 for ; Thu, 16 Feb 2023 19:43:30 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nQjhqTpW; spf=pass (imf09.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=1676576610; 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=ecCMrPuH47M6x+7l+8oSjk53rrpfDEPsyzkbMwvMYGE=; b=WWt8DtEgHQ4AIgV11k0+rduaW6rOiTM9xAyrVeC4oFkYv7QvOAOT0ymLs2KmRt1VTbxWvt NmYU1XYTzvpH0kh4hX7h9jIZtcbkm3FndeaufWbOoSMk16JJjO3VhYck+GenUz+lTSiM7Z HRczPXPyPC3CtPIi83nNvhv+/cmgHkg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nQjhqTpW; spf=pass (imf09.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=1676576610; a=rsa-sha256; cv=none; b=T6cAwDRNJVb0sQ/2ClsHC7tqKn2qYjfBcpI8Y2vBp/FSbVvBfgrBqyfqpUfHddJV+Wv759 94wsv4FfQVG/M4AA+nvw5t9c4JtZV/1u8Bu5HYsJzUEGxb0Xn/T4yyx+VkFAtqoKGhi8tR tFE7HUusjVf05A3ab36xoDq5szsNOX8= Received: by mail-yb1-f169.google.com with SMTP id v14so2465619ybm.7 for ; Thu, 16 Feb 2023 11:43: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=ecCMrPuH47M6x+7l+8oSjk53rrpfDEPsyzkbMwvMYGE=; b=nQjhqTpWmrsidiAuvoCcaH+1Nn+MdzCD0u1wOKp3+6nMie0EEOCShOkZxWAStmC0Z7 0DAiGxaTX/84wos6YcnH4ZcBy4oFJENSMkSF4PKWKvGrLfFlv9miv6D1euEV3WJw2Bja U/Tc4VyRAp8gojN5lr+rESfLvTfTK5vezctBWGmB51gEhz9cXu1jwSFmGRSfVyIe7KJW 9985FtKADC1PSU2QKatY5svbWvXHeK/lG4CpKBFBZzA8TlGvpIV5VpHjgkpocjYvo2Sn 2t+SpqQDf8D5EE+w43rAN8WY2iOuZ6m2DhxKzx3UvSVmlCnkWCxNbjgkfk9I9fPsoDou rcSQ== 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=ecCMrPuH47M6x+7l+8oSjk53rrpfDEPsyzkbMwvMYGE=; b=LwjMqz8vuQaKtrWZ29YO7Wmgc5F4EJeN0W0Gmdeqc67awssNfGH//3u5C5jYAWaGk0 RzF8+er9tvgyd1BxCVz0BZUmGVC9h2tceTOn3oydaXRbVuN6Sev2IUxpxjR+XXnSNVaF cub6H3/cOF9PAVTV67SJUcJchbU4Uo7WS3vs0DWKjzq3/SmxMSpQVrA6RbeG7OKAf/7X FIMSgqdJobh8TFvV2pHftS57ug7JplWGyrc56BwhUCgTCK5nrpCuYvsRSFlJmot+cM98 Dht7dlxvP/6s+v5fMsvWlVOrTnL6ooZ/qib4vYdV1ruu819qhHcijxbreGyry43rDr6e t2rg== X-Gm-Message-State: AO0yUKXzn5pxcwLahhMY46ZT+0Cyps12HwwX/bRJYhEwsmZ2N5DqYLRu /K9ruMicO5rnhaVpqQgb5+tx8LAaWca7itxgbZYSDw== X-Google-Smtp-Source: AK7set+GOKNhzuykRCoIMckW7I82pXv7V9YjFwgSjZ09J90OxeIVOanNo7rnoi+gq6vhCwETbxbWJ7fJFGy2XpbKeOY= X-Received: by 2002:a25:9941:0:b0:90c:de27:7f15 with SMTP id n1-20020a259941000000b0090cde277f15mr876421ybo.428.1676576609777; Thu, 16 Feb 2023 11:43:29 -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: Thu, 16 Feb 2023 11:43:18 -0800 Message-ID: Subject: Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set To: Matthew Wilcox Cc: 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-Stat-Signature: hrqabpsok94payf7rj9zrni1wdh6ir46 X-Rspam-User: X-Rspamd-Queue-Id: DD13B140005 X-Rspamd-Server: rspam06 X-HE-Tag: 1676576610-215973 X-HE-Meta: U2FsdGVkX18co0QKwaW2vs/mGj+PQPU5i/6jXsQAkesWSskyvND2ddL3THkiBA4bZUiXA/9hDA1KiiD4l+jzW6ngr4QfkZ1tQKrBzkQnc7J/g7EJk6XakKBdCMlSXCmA0k05UP0fTZWm/ddEGanEBJ530FwwMafA7I2MCmiu7Wi91+C0K+TyEzW2U6bICpXoTEo9X0xuf4nFaBz26E6pyHyfzj3PXL/SGA2xISVl/JJ0jkzulDGfQeqjysDGw3AstRFkoGQy5UD0PyxsC5NmpTYhftS3wIryYVeXY49MTp4MFQcupx87ednLOy6gexIasl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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. 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.