From patchwork Mon Apr 15 15:24:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13630221 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 45AC6C4345F for ; Mon, 15 Apr 2024 15:25:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDEBA6B00A4; Mon, 15 Apr 2024 11:25:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8EE76B00A5; Mon, 15 Apr 2024 11:25:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7CAB6B00A6; Mon, 15 Apr 2024 11:25:01 -0400 (EDT) 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 9BB126B00A4 for ; Mon, 15 Apr 2024 11:25:01 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5241F120289 for ; Mon, 15 Apr 2024 15:25:01 +0000 (UTC) X-FDA: 82012139202.10.28708A1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 426B11C0021 for ; Mon, 15 Apr 2024 15:24:58 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Rxvmu9m7; dmarc=none; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713194699; 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: references:dkim-signature; bh=01ImQsXXWvSp5SJtwfJ2JkvkKrzd9N9Z7V2ZHRtY+2c=; b=yzvdGu0z5Fsqz0kB4KaktIZ0Ih3pBXMqmFUOuaKoyZOzyLhm9XBu+I6szuJSYpQWm1zSxO bAa3VoBCJkUKl1640PUA2UM7f8NGvoNBaRgVOlOaFi3iHW2gW3h0xGCRi0oRfop/nYU1MD wV72S52eUNdbJzfoSztR+GmiLBG0EE0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Rxvmu9m7; dmarc=none; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713194699; a=rsa-sha256; cv=none; b=kgRVu7+W90Fx//RFuhCryrOwo34A8TrPxXH5EJjO6CfukPRouNGmxvmYRHlh+LvgIzc7hJ IADYq6if8pD/BHtFNs8jn95qZDJmfZQUodX3uC9tzlcnQE2D5ednJzZ0E9eVYRnRqvehFg o/JS7yADDcig97ZPSNJQOyVpyFWsRUU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=01ImQsXXWvSp5SJtwfJ2JkvkKrzd9N9Z7V2ZHRtY+2c=; b=Rxvmu9m7nG4V4zMCk0O6w+WCFn aJHSocH/+6N1n6lw7dEXVstItL3+K5NM1+Xa071x7yBb/tI0sbhJrMEvK41mOQMbXUxD6h3Ex03Po FC5qmbLWI9MN9T/G/oEzTM7UsWUBAoCJ62Tn4dCbpWJyi93zHO8UV65HgyNhxKU2qkgVm44Voaob+ iKV0TywM+oDudCuEulxVXAJ+RXG4T7yFVlsyy+u9D94JPtyI6EL9oeUErGt7quqLAKXgl7MykEpBk jYSEDxm5tuqfzOt401FsYMevO9tr7YPjyawF0NoHhnyoyQAfTKvzWZJhQsGDUjMG0F9XNap8QEKtA 9c6vJkfA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwOCW-0000000FxtA-0elU; Mon, 15 Apr 2024 15:24:56 +0000 Date: Mon, 15 Apr 2024 16:24:56 +0100 From: Matthew Wilcox To: linux-mm@kvack.org Cc: Suren Baghdasaryan Subject: [RFC] Trylock the mmap_lock in vmf_anon_prepare() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 426B11C0021 X-Stat-Signature: mn8dbxs1fa1odofr4hue3ai4muw6tspd X-HE-Tag: 1713194698-812709 X-HE-Meta: U2FsdGVkX1+0TljPz+IQGcf0sN91LuEXjmxVybMAcBWjXiuM0vp0AaWELitkTecyRc21DkiRU8YMmugFUbrmMoSBQPGOxtMfM862rfL9NT62qlul1KYkkLfrB1yLc1gZ544TkCwddc2zya4M2BVYmSvTg/yDMoHCdIo14AdK9XOLIqL8r58BmD/1ioTQT3MCdN8syvnuvZCilkUs13WDQiEI0bsEj+Og+Ts/VPExz2Qwt2Jb+bmNt4aPECyN2hamA3/UZiu/U98CfX55LUtQM4I1ZDdnNm2W1qUCzhMl/q/L5wdnKoWeSREOFNIcb44tsmCyqOl5HDJ80cFmQjVgLVWcvTgO8BaE7FOdmj2vElWfROe1j2qTCJYLYO6XDTDHHvdgX8IugOX8IoXLnTSnABdUwTEW4oBuXs8ClnE+s2TyBjr1qW6cUAgfadZsfpyW3iGZ7R/HyBzkdz83I9WnYa0xv9k4rLHqB2Hg9R6PdJ//eFQhCTzC4Ayw9yibPLZoUb/x7W+P64aA6QT5eF5nUxFO+ZuQ1z6zWpas9Y/+tkOgV4PUiIRMuqeHnYXMxka5dnqMm/zswRxs+1wzqQ7wK9cSS9+V0bJqY7c6j3z9vWYHQM2OiqeNCYVP5G86D5yk9dIuP9h9vkCIjBRV6mqWcsvqUK/8+MJGPbHxKhwxqhB2iLhURs/6Z/RZrlcV7jbajzBqFhrqN2ijLjLO9hlmyinzZNPtKLcegAVs8TtMgmFo2tzO5jKNT9Kswz0BHOPWbOus5i2J7coKY8qkCBcfL+hQt+bkwef2Tpamc3pVbzkuOnjcfDqzPUrheWzBnv3SR6ydnKaRibN1eEBk3lpKyzL/Y29EHsgWmq5QfguOJgY35kFbCTRhhs3APoStH6d9tF0/0hhA7jvI7M7TSMaIz1ighKjr+qz4dLj6pJbcF4qvf2d6lGGowys/fKoscrIRy3lBylVWa9dlvZqu+Ih vrl9Ujf9 3aOmjBCIzkQWCE2EdBmLcCMEDLwC7EDtmp4INBPM8BzJ4oiiHJGF82bvsh8m4/u0ABNOQSSHVboK26E4HqZMfSQ9MojQlBsOOOS1bobyZpGb9SElFBgNRAkZH+ZYY9lcqE/u1ae6FZ5prPx/T1GsNWKWA95W8538fiOg2awTE6IwzrdlYZoStLmNc3DnQJHAYc7Jjyzfw6ESFmO6mrn+XoCurq4OIptlZs3NbQGTgKZtNSn8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000074, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: It seems a shame to fallback if the mmap_lock is readily available. It doesn't blow up immediately in my testing ... thoughts? From 70833af858ce41a80b5f0669648ee9f59b149a03 Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Mon, 15 Apr 2024 11:13:41 -0400 Subject: [PATCH] mm: Optimise vmf_anon_prepare() for VMAs without an anon_vma If the mmap_lock can be taken for read, there's no reason not to take it so that we can call __anon_vma_prepare(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Jann Horn Reviewed-by: Suren Baghdasaryan --- mm/memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b9c23393fa9b..7075fb7f74da 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3219,11 +3219,15 @@ vm_fault_t vmf_anon_prepare(struct vm_fault *vmf) if (likely(vma->anon_vma)) return 0; if (vmf->flags & FAULT_FLAG_VMA_LOCK) { - vma_end_read(vma); - return VM_FAULT_RETRY; + if (!mmap_read_trylock(vma->vm_mm)) { + vma_end_read(vma); + return VM_FAULT_RETRY; + } } if (__anon_vma_prepare(vma)) return VM_FAULT_OOM; + if (vmf->flags & FAULT_FLAG_VMA_LOCK) + mmap_read_unlock(vma->vm_mm); return 0; }