Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp131017lql; Fri, 12 Apr 2024 06:07:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9ev4yjIWEbyHAy/EhSv0TfCKAKcuWxONrt0tjLW37wsXuOXkqgtkFMJ1VqMquqImsuht219HnyWKJjuplXRchJCBvWnL67/QOZIxLhw== X-Google-Smtp-Source: AGHT+IE2HyPX1TYYT8R6pqcbIiPNRPQ49xC9GK3dyiiAGn79uO9D6tb3JT90+F0tt53Hle2xft/M X-Received: by 2002:a05:6a21:9201:b0:1a9:b7d0:b6ff with SMTP id tl1-20020a056a21920100b001a9b7d0b6ffmr851597pzb.32.1712927228525; Fri, 12 Apr 2024 06:07:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712927228; cv=pass; d=google.com; s=arc-20160816; b=WeByaqFXqWJGqCbkhVtdrsMuox0bwYdA5N/YBIVMhN4q2af4FhMpfxEqVvfcuIfDHB xwoHmRKlQzOwIcS5esxIhg+1JEwbONzXwA5bFfag4gMKeKZjDh8o2ATnkzo5aO1x1FB0 nLNsUMtbSOkJj8d+E+zoh671o29NkOMZgJN3MUkzgxNXbHJ4QB29nlMrShiN9kRcC63c pqsguVRiL682XdC36eRgAxJlVd1G611iV40lutThIi3lYMH9WopWclwEjg0zU4N0bW07 1rwc5z4zLgp5liuF+gAX47GOOzYiJvBefnZVSjN7vvD0AqOWxb0pyyxEmJtJt4D8PTN5 nXXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=SB9S53FpUOU6K6sETjS3Mnaeo0b7/MTmwyW31fw1bBA=; fh=BBtHmjsNNPfKOT2LYFMCBGZjJa6AdddrP+g8ag4gdBY=; b=KaP5GxHQjTNr92mvJctnI7ihEx9YR1IKOAjgSithFS/581lVslnYOtVheISv9Be/vp caFJIV8gLz0xHK5jUCJRBrCB6o3NDfLSUP6DcSie+pxNbhtogCaK5HSN209R6xg6vAAC 2zSW1KjqFqJ9M0qM/POYITWKHT36Kv7ArqsoXLF1sabPfzZdR8biTX1MYu4Y5dWAlzik sU0BtQI7Xodd6xQI2O+X+uomxOXJejulXL+91dkvezYDjb9H0sgEW2ZC9/WSBAudEg76 5aoouDTfmxmVB33/e5xgDGxVs7xScLHofcBWwEfJ7DjNiOxpl6BQ5amn4Q9abrns1WHT LElw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OHPVUInz; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-142687-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142687-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y13-20020a65528d000000b005dc8a33fcc3si3258879pgp.653.2024.04.12.06.07.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 06:07:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142687-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OHPVUInz; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-142687-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142687-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 31D8D281CAB for ; Fri, 12 Apr 2024 13:07:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99A3D5EE67; Fri, 12 Apr 2024 13:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OHPVUInz" Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 395755C61C for ; Fri, 12 Apr 2024 13:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712927221; cv=none; b=E49cBj6kT9Cv5ZVgkY/bVZdRkTSir9QFw6l3ES0GMxSNEZsuPjZuPVPBR5K5dbzDlfkTYjiukAwH6HHUwndKMot3aMApU3yvCIUB5WQBOOOv4ECgO3ywEQvSkYD18Q6JJr2wYXitt1zPVmdYMSTgNi9vjiS1wbPZVIVSkyn012M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712927221; c=relaxed/simple; bh=WWML42pU0gyPEAbHQUi6Fs7oG2/hltpIrDkhv5AR/ok=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=btz8ljlv8UK4wHx0hunSsR6U0u2+qVlychumKy0qcCKX5tUe4hefWHVgSySsCEc7INh8ZJ6EqCZyF0boYP/F3fgo4rQSLlRAx4x1+3HPpVUKkOfQThwDfUHf1si6kN87S2nkcyrGWGlN8aN60oW9+KOXJ/Nsa8fXrWET1aWkkyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OHPVUInz; arc=none smtp.client-ip=209.85.219.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-dc6d9a8815fso870535276.3 for ; Fri, 12 Apr 2024 06:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712927219; x=1713532019; darn=vger.kernel.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=OHPVUInzLDWo+uF7UqVd4FMp8UHYpDMBrNVX7PhrPnBZ9BN6EOvdfK5eCgsrOuN5aN XcqNLVLGnlaD0xadhAlOdDo865pJ19LOPrYVl+Sn+MI8quOvamPp9igk3kdFQIbdTyAk WwzD6Pgb32pkNhvQ+PrP01ScsbDKKlYFXp5mI32T9wevAaIaolvDk44GnZubarMVBuDx cqtbZwd6FSBEIMILG9okJs8DUSF7Bm8SOX4wCvqTlTcRDNkWuxEpw2p6LbVDIepgVSjM COla/i+QoDdh5Xr2FNR6BCX+eFmaoXBOif4mFnsR3BI98HVLYT+Vh4ZFVT5xu7sNTowF NJSw== 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=JnIin87hxgZzcQP1FK/kpsIoqhIqQlBsaSY1udIjWX0IAfrc0kSQY6pfypZ2RC8zse WQJXDDhsTLCsIwr/zYoM9pizLobC9txX0MJdVuA9xiLVU7EkF2/00+A+sL6MJ5koY4Gl HxaNixsb/s+ZIiDhK8clqNYVtn56AzEAWHuqbhPERE5xssy/SkcOdhlbY/eZIgGGfeVK IMwQhK0ZraidDhazeEZbmHAtnZ7XL+3gJ4GH70vFtG2ioVDHfdDtyRMXUEmhdL1k9YSc /Mw4CKL2pcx3vWAyVDrvKi3WyYQ+8Zx6d5RtjB7gFF7SGG5MZmt88H6QGgk2uROZRWGZ A++w== X-Forwarded-Encrypted: i=1; AJvYcCWf0WpYA5rXs3MpyXiAHr7sMuZOoqe0/uNjXNRWJJc3Yu5oUoIXwQ+HKGoIbM2kFZM8v/ikRfDHDCdD516F9RbqJXFB4GD5yGfWkoeL X-Gm-Message-State: AOJu0Yw/J4slK2xHJiiAuyER0wNn+xqIjMkUPH7ctKLAdV0zkUhKRhIJ yKhF3zHQp37PCUZdfC1gMjY6e5NYwyZJOQVCIwpXPMYIfRtPyqyfc995HtHc+XS20gl0t1UCqkX 9AcNrC+A1r6gT3w6pArW9QwtAaksoTreX6tbP 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 >