From patchwork Mon Jul 24 18:54:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13325259 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 CFCE4C04A6A for ; Mon, 24 Jul 2023 18:54:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 005196B0075; Mon, 24 Jul 2023 14:54:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7576B0078; Mon, 24 Jul 2023 14:54:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFAEF8E0001; Mon, 24 Jul 2023 14:54:21 -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 B94BB6B0075 for ; Mon, 24 Jul 2023 14:54:21 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8C95716017E for ; Mon, 24 Jul 2023 18:54:21 +0000 (UTC) X-FDA: 81047405922.26.815B95D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id C1DF040013 for ; Mon, 24 Jul 2023 18:54:19 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IfZBEC2b; dmarc=none; spf=none (imf07.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=1690224859; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Q+DaNTNbIUG3q6eDPG2po4w54RCX1zIfiIR5STu1uiQ=; b=2rZJsO2AtNOaE0A0qBSgZGLjW8Hp3QcpqMyzBE75LJfjCdpsF5Xei4GQeb70oZ5XSu+lts hOz/CeToewiii2oZkU5guUG3vA23jnB3QcKGJtSUAXQC98nbIlZtAq0KcFhttf9arARahM Yd6wH6UUYDDfJ2i9wRYsDDSqTG02RVU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IfZBEC2b; dmarc=none; spf=none (imf07.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=1690224859; a=rsa-sha256; cv=none; b=DVVY/RepXUP+0dsag3YQMVUiFkbVvz2l59wX+HxkydTizd2KdyyUDrPTdVLncDJeNGqtoV MBdWF+zvvnKCilYEouY32ALHGeK/A4j4B88Ql41Ri6zA9FqPNi1z/upz2lyk55XGuyPd+L 3UC7s6IIg1b6wzhAL6HGNrgaY2BmxxQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Q+DaNTNbIUG3q6eDPG2po4w54RCX1zIfiIR5STu1uiQ=; b=IfZBEC2bafAFTQbS89y7UijEBE RWmQ1Ds4r4Jychulds5YnYRb3I0od+yIzxGEjRBg/sMoaW8Sgo39q598ZbCrb8yFJjLhEXLbKGw2u m6ON7coI8Vkyui8eqwVD3MAAI4b1SEwfQnyn3FGv9SQx1ziGML5H3GK5zcH+sBTO4lmFkaq0PKQyx xzo+xp/C7beutQOsWwV77qUovD+qADlO+56E/Dwyj29cWGg4lg7hX6Mo01FXPuux0JJUirC3kWWWp PlgvLemMPnSu3miVyRvcWhE2qw/Nw7f8SnbiBBb69OcutacNlt/2UeeoQC1+cppK2G6+2AMHfS7AU qU4S7HIA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qO0hA-004iRJ-S7; Mon, 24 Jul 2023 18:54:12 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Punit Agrawal Subject: [PATCH v3 10/10] mm: Handle faults that merely update the accessed bit under the VMA lock Date: Mon, 24 Jul 2023 19:54:10 +0100 Message-Id: <20230724185410.1124082-11-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230724185410.1124082-1-willy@infradead.org> References: <20230724185410.1124082-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: o5ya8gj1ijwd5jwodwj5rh6iopesjzee X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C1DF040013 X-HE-Tag: 1690224859-643432 X-HE-Meta: U2FsdGVkX18hyzHDhzOmPOeLDEvzHPG0WqTps+ldvZkUesMJyTAdBFdKo12AyAgRXZFDVJ+JJQ190ya4mRI9DUZkMMX/cHfEON7oKHrAvGaC7I0A949miPwZcQfv5TDcm8rnumbdOXdxD4gl7Rse7BFSsyE/ha10Rc51/axfIdvluzQ1sfHjNbhfeZ06PgoCrYAbD0EfMoMaGcXc/XCVisxtDGf6S3N524MpC0f+dd6LOcJ3FXMYsDz2vG0kbpb325IqzkZpGGsGeDo906Dechr6W4Egp+kzjqx0e+aVP+td+wsoDw8qX3AODMjN8lqa63VRwLdv8raDmpQ6nyOLEtUCyPzxpJfmO1N+mfmomp488QFRb/tHo+VDDBdRkxwpoqdoNpCOBdb9m+9PFcgRieWdXIo4Q2RX1plHRFznq4m3+oSoAj+S9F0VQ1iVqp65YQTsbHeqtDo+uc6tGAi1ZQOcUy75TC3GNPuN0wKIG/Ia5owGx7QXXzerb+5FzcDnTdWmTtUmi9CPTmWnKBARCDB0jM4MHVqDdWj5GZABgmz76r2u1hu5ib7AfOB3n0KLn/9sqPvsrtpszL7ll9VTS2JLrCXHFzveSbrW6TyacFD29HJUrx7m3zdYFYdL5pYkNqtZ+lSRo5v/KRQG2tNzUXmltYEyzodoO/iWWO+dufqUufDGv5yVbMxl6wzBsi511TAAp2t4Lz2FiTM7J32Ezulm3bPHxXUwa5Vq3tsylf3IsWfi5b2Hbnegr9X4VmM+QLZVU3aG/xu9/ma3pNtVGgj2+CQ4neqzzJvsF6RKwxUBxCHBAqo+LJ+9sfGTmKkPaZfV5QK4IYanC9v+6JCjuoLvaMMsEvBT++mSqRdn1BwhDc2KLi6WkOFGCxGYqrY+e/UsgyrvpmKAfcToBAPt9ZYLPWQ/syj8yPfrwIu5rlz39gLoujZuY+phqCnMI8WK1O8O2gMhWADq9PgJTlI o7lL+6bm Tr8r4p64jCl2RYeelSfPeTVvwO/w5sspcPewyC+dLtnd9QTvoBgmvUkh3p7l0AmqgzoYmobF/p4N684PTDHqR962ZakJArsO38uQtpM/OFsG42xSvOuyhgMbVtw/rvODmbg2VDtPuo37aD/Z2QaKG3tVNK+uZxlih2DrRdP/SDweh5QdmHUYGf251qw== 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: Move FAULT_FLAG_VMA_LOCK check out of handle_pte_fault(). This should have a significant performance improvement for mmaped files. Write faults (on read-only shared pages) still take the mmap lock as we do not want to audit all the implementations of ->pfn_mkwrite() and ->page_mkwrite(). However write-faults on private mappings are handled under the VMA lock. Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index ad77ac7f8c9b..20a2e9ed4aeb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3393,6 +3393,11 @@ static vm_fault_t wp_pfn_shared(struct vm_fault *vmf) vm_fault_t ret; pte_unmap_unlock(vmf->pte, vmf->ptl); + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + vma_end_read(vmf->vma); + return VM_FAULT_RETRY; + } + vmf->flags |= FAULT_FLAG_MKWRITE; ret = vma->vm_ops->pfn_mkwrite(vmf); if (ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)) @@ -3415,6 +3420,12 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf, struct folio *folio) vm_fault_t tmp; pte_unmap_unlock(vmf->pte, vmf->ptl); + if (vmf->flags & FAULT_FLAG_VMA_LOCK) { + folio_put(folio); + vma_end_read(vmf->vma); + return VM_FAULT_RETRY; + } + tmp = do_page_mkwrite(vmf, folio); if (unlikely(!tmp || (tmp & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) { @@ -5113,12 +5124,6 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) if (pte_protnone(vmf->orig_pte) && vma_is_accessible(vmf->vma)) return do_numa_page(vmf); - if ((vmf->flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vmf->vma)) { - pte_unmap(vmf->pte); - vma_end_read(vmf->vma); - return VM_FAULT_RETRY; - } - spin_lock(vmf->ptl); entry = vmf->orig_pte; if (unlikely(!pte_same(ptep_get(vmf->pte), entry))) {