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 2F90AC4345F for ; Fri, 12 Apr 2024 13:07:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA1186B0083; Fri, 12 Apr 2024 09:07:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2AEB6B0087; Fri, 12 Apr 2024 09:07:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A4076B0088; Fri, 12 Apr 2024 09:07:07 -0400 (EDT) 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 6BED46B0083 for ; Fri, 12 Apr 2024 09:07:07 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BA4B91A0E73 for ; Fri, 12 Apr 2024 13:07:06 +0000 (UTC) X-FDA: 82000905252.24.95D76E5 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf30.hostedemail.com (Postfix) with ESMTP id 1778A80023 for ; Fri, 12 Apr 2024 13:07:03 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=0VzHulON; spf=pass (imf30.hostedemail.com: domain of surenb@google.com designates 209.85.219.175 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=1712927224; a=rsa-sha256; cv=none; b=AyFLexNsyMtdcbfqtMKuuTZdgcgOtMiC9RkPrqLc3/yYhMo/JJgyjImzaHF48TTeIHsG8r sXbWAVD/+OSac3PaD8GJej5u6GB9txKsD2xqKa0/UGnjy08pdu8FS+sat6r1ryyezevEBl qUDVTYfysIWhqe/41jnM0sCZxt5oI8Q= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=0VzHulON; spf=pass (imf30.hostedemail.com: domain of surenb@google.com designates 209.85.219.175 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=1712927224; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SB9S53FpUOU6K6sETjS3Mnaeo0b7/MTmwyW31fw1bBA=; b=Mi7uoHMnVzbCrDcrGBESvjf0l3n9+n1gnjjKFDJ2W8nTLoVgpsZIcIXqPZU1jLhCfSK3dL 39S9s12UCOR3hb6oCubmpEmUnpxpdSCZv93hCPlCcaIs1EHoe3JW0HQgna4y3/uT8ZVpKx XBcONgwAWHV2/o1GbWYR8sG0urb49l0= Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-dccb1421bdeso884734276.1 for ; Fri, 12 Apr 2024 06:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712927219; x=1713532019; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SB9S53FpUOU6K6sETjS3Mnaeo0b7/MTmwyW31fw1bBA=; b=0VzHulON7u/1fNQDPtkIAq79gv1dAAZGw6sH6llOLSBowLb/WVWhpNXDXzd0Z8/eQN QeJ88wXPbfz/mU7DlJyV9wR8bmucJoWxCLk5V4ZRUgMVzFB0Q8LzdG+GPZiiWbbELwJX Zax0J5V2hq5arpvFprAJ9GzsKKzY7DUigfkqjWj8odyRh2wV8ithP0Ewj072ENBUAR28 +pTUV/Ohy78Sofixv2gSq+pIMZuhtbPE1ykk7cJgGNNhARz49grCNArp4j+L7n9vURXr 8HFAh5ut8Pb3NbvLpUCWhDITNSJVOsfBWLjGOA1RH4RY2LdMuNEBxGEzn3hyjeNa5ClN BJig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712927219; x=1713532019; h=content-transfer-encoding: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=SB9S53FpUOU6K6sETjS3Mnaeo0b7/MTmwyW31fw1bBA=; b=juVeq4Uaws22pHiZUJVJob3asuj4Q7GiBNt4fhOEws5HMNBRiF/+mwcdURgVyuulSa MRzMFB+YRhAE8DP0OwqT/etvYMXqH+FaVwaAHYYVJk2iVM2Aa2XvGXJ2j1GbWtLrlQuT ZSGRYWopZBDfk9Kx5P5iUHIA6FdW3gpvIe0lsj8bd/5i/ZyxtzmslmWzrlxuU385V4PP 17NXjPO2Ks7GyDjZWiEETTrrIcNtrXs9xmg3gzJCNrZJ6WNFTLvAvk8HgkM804jysve2 SH5se66U/jisvWsScrl2ETZpQsI1+N4TTeIah0PIjlifeIK7liJWKVtD8OfbYehms91n 15ZQ== X-Forwarded-Encrypted: i=1; AJvYcCVHtk+uzkzdt5+24oFqwgo7uWjWSreFAT66eUl7kwrLPaxRl2QCGpm0s+NBTNHSZaMXrqq6sSxdKE8z+pksYiZCMIs= X-Gm-Message-State: AOJu0Ywek75D18OEBJ3DfpmWOgTnAtQSLgO+P7R0mOn4VsShNRvADgk1 4L/6udnnueqd+UZvV28S9pMBlBvOE7Pu/VaePyVTcdDklTFGdGnOdNy8+deThVpBB2dVMYC2zS1 HXmh80gNJGroeVIN9tpw0t1ETGd+tEsrQADmd X-Google-Smtp-Source: AGHT+IEkizqEncaI2tUBnj3BapsVHQZBG/G0ZuX28yKcPkP1UboPKfU2fh9EJAGBcxgdjfuxfzD4unqvpbTxfZAhAzQ= X-Received: by 2002:a05:6902:511:b0:dcd:1b8f:e6d3 with SMTP id x17-20020a056902051100b00dcd1b8fe6d3mr2319169ybs.48.1712927218816; Fri, 12 Apr 2024 06:06:58 -0700 (PDT) MIME-Version: 1.0 References: <20240410170621.2011171-1-peterx@redhat.com> <20240411171319.almhz23xulg4f7op@revolver> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 12 Apr 2024 06:06:46 -0700 Message-ID: Subject: Re: [PATCH] mm: Always sanity check anon_vma first for per-vma locks To: Peter Xu Cc: Matthew Wilcox , "Liam R. Howlett" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Lokesh Gidra , Alistair Popple Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1778A80023 X-Stat-Signature: r8bfjz1pr9ozdn3m7b7roow73fqquaaq X-Rspam-User: X-HE-Tag: 1712927223-158574 X-HE-Meta: U2FsdGVkX1+iHAIXH74jYcwO8ZepXtPPmAL9jNKko1sfwA1fsPz24Q9bOKkraVCbUfxkybA4xRnt+KNfz1WPM3Qw70ha8GtEITB9y7W7uKOpdhI61nnEPgo+XKAfE0KoWdK8nH5Vcs94DeTeaI0OzbQJOGyJGTBhZywaYsbZ8x3on/5YnoEiHm8ph/EUC5xfnzhriiPoNqruz1jOuAfF7oAlco57M70U/Riqo5FLk6t1zXSxKagCbpFKsOugPeMuxvgZRReElV4Sx0fJpDrscl/dDbr3AzR6JBqcdR6baMpecNE17rQmGcQKf1/0kL6XD83mcWVhSj4e537C8FCgeopICNyzEe3emmr1dqpn7tdhLXGT9kMROu2C/wvgrWf6uUTGBmtXJQwnerNcXw5eWFIGPZA6CoYrK2Q6HRBK9ptK/ej+26UsjjAg2rSnj7+/RHrPIpYuJGzlDetUOkseVdKpyVPn4DfYf6cYNPwW+G3LQ7P+8e7oZZllBvgFJuxvu34T6YNUG6mnYAn6gFTxERhcn7kvuMJgFhC4VQ/OorZWOGVK4xojMc/y/nkQywRzDEg6n1KEcY67NU+uPxHABfqL8u+NeSrJW7/nRhj2DeMzK9ZhOIsXsvH1uqBy7JegoBPrqs+aEOuxBmm9ym2K8bCxYbJrtwxzBk6J1UsqE/XSPbnLuAsoi1H65RUD4ubOpSl/h10STUPtDHYoVed37K1HE9E7+WYYPPm+ZVMVj+bsFXyDe1teFTYAwlGHEnr/2mIbVgLFEjJRTwQHxAGgIONkcAOSnRfcLGUxztKc+4zZaZQbuScLOUQIm/1iB9rp5sZfTqnlSV2n0xxJWZflNfzvOCGshIHzX6Q94frVdFT8iMf0xpHdatWAjfUdmaHqzY1gWj4XT9IdsBczdKtfV/hP1a2fQmczxINcua60HmieDLjPe6jwNgknl/9MJpSQkK5HxTwKjrCIjeRp8KC IajN3Npd lGi1bJ4E8uux9O6ZqKJuJfBgZ5+DQEKdOnXSQaezqwbeC8XU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Apr 12, 2024 at 5:39=E2=80=AFAM Peter Xu wrote: > > On Fri, Apr 12, 2024 at 04:14:16AM +0100, Matthew Wilcox wrote: > > On Thu, Apr 11, 2024 at 11:02:32PM +0100, Matthew Wilcox wrote: > > > > How many instructions it takes for a late RETRY for WRITEs to priva= te file > > > > mappings, fallback to mmap_sem? > > > > > > Doesn't matter. That happens _once_ per VMA, and it's dwarfed by the > > > cost of allocating and initialising the COWed page. You're adding > > > instructions to every single page fault. I'm not happy that we had t= o > > > add extra instructions to the fault path for single-threaded programs= , > > > but we at least had the justification that we were improving scalabil= ity > > > on large systems. Your excuse is "it makes the code cleaner". And > > > honestly, I don't think it even does that. > > > > Suren, what would you think to this? > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 6e2fe960473d..e495adcbe968 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -5821,15 +5821,6 @@ struct vm_area_struct *lock_vma_under_rcu(struct= mm_struct *mm, > > if (!vma_start_read(vma)) > > goto inval; > > > > - /* > > - * find_mergeable_anon_vma uses adjacent vmas which are not loc= ked. > > - * This check must happen after vma_start_read(); otherwise, a > > - * concurrent mremap() with MREMAP_DONTUNMAP could dissociate t= he VMA > > - * from its anon_vma. > > - */ > > - if (unlikely(vma_is_anonymous(vma) && !vma->anon_vma)) > > - goto inval_end_read; > > - > > /* Check since vm_start/vm_end might change before we lock the = VMA */ > > if (unlikely(address < vma->vm_start || address >=3D vma->vm_en= d)) > > goto inval_end_read; > > > > That takes a few insns out of the page fault path (good!) at the cost > > of one extra trip around the fault handler for the first fault on an > > anon vma. It makes the file & anon paths more similar to each other > > (good!) > > > > We'd need some data to be sure it's really a win, but less code is > > always good. > > You at least need two things: > > (1) don't throw away Jann's comment so easily I agree, if we make this change we should keep this comment and maybe move it into vmf_anon_prepare() > > (2) have a look on whether anon memory has the fallback yet, at all Yeah, I think do_anonymous_page() will have to change as I mentioned in the previous reply. > > Maybe someone can already comment in a harsh way on this one, but no, I'm > not going to be like that. > > I still don't understand why you don't like so much to not fallback at al= l > if we could, the flags I checked was all in hot cache I think anyway. > > And since I'm also enough on how you comment in your previous replies, I'= ll > leave the rest comments for others. FWIW I fully accept the blame for not seeing that private file mapping read case regression. In retrospect this should have been obvious... but the hindsight is always 20/20. > > -- > Peter Xu >