From patchwork Wed Apr 2 18:16:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036360 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 C8505C36018 for ; Wed, 2 Apr 2025 18:17:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA8D128000E; Wed, 2 Apr 2025 14:17:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2739280006; Wed, 2 Apr 2025 14:17:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91D5B28000E; Wed, 2 Apr 2025 14:17:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 75FFC280006 for ; Wed, 2 Apr 2025 14:17:38 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AC04B1605ED for ; Wed, 2 Apr 2025 18:17:38 +0000 (UTC) X-FDA: 83289911796.26.E6CE02F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 01F7620004 for ; Wed, 2 Apr 2025 18:17:36 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=YAXCy6X1; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743617857; 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=lziGZfROFPhpObpsaGUZ16kTN/pcfFau1WI7RqoG7Nk=; b=q4PfNztHjMGJg80T3nQmQYo006Yk6Zg53MNH2VR25+Yz1+awF79lCHzbyYlgci5T46pVcH clTdvg+1epVSzlqYAxMrroR5YukDOMDbfUyA5WD5SPqdopb+uemT46CL/Uk7QLtxd6riWc Tg1bBHupI1dii7AjiynVj5Az11czrp8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=YAXCy6X1; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743617857; a=rsa-sha256; cv=none; b=auzcRAos3mnr71FeBDHMbmzRB/DkPLIoplElN406Na3/3hSt2eKVN1/vNGO0p6zt2NmQBH fbOSlzMjDVvXUj7R4pnjInI+5hPjnAO/7pRC+JMWKV5H/sWC2CkBsHJKrML5FZCNYZeD29 h9NBRCRKp+w3ip1DwUhSzZM+Gr4guQE= 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=lziGZfROFPhpObpsaGUZ16kTN/pcfFau1WI7RqoG7Nk=; b=YAXCy6X1G2bFcoaDIZGZDJIjcY CayYgL2F+q7RCw52YgbfwYENQP7LaVJJH8DKSUhlxIuWCu7KFD4zqWq7/vuLsTcwYOtWxQKvjJ9t/ ctqq5kCqm7yurpAKtOyciNlMMgUMPoG1ke2hHdsXtnhTqZD8SExb5iQSk+AduITgbWGe05cFpwNsI 7SHht3zFfW5/iNKBZtTpMDXMuJD+lVq1hUpZC5OZ6+f1VFrzpVuDvsIKcuEk1APt8W86WqBCQBHVo m7PmJMhxuBt+ZF5c0CKHPun/BSBF6eSv1JvFELqmRtI9S7P/9ZiD6vZj3FUQIa/ZC25srHY0l+S6r rJ2sR16w==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1u02eF-0000000A0iU-0796; Wed, 02 Apr 2025 18:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-arch@vger.kernel.org, David Hildenbrand , Alexander Gordeev Subject: [PATCH v2 01/11] mm: Set the pte dirty if the folio is already dirty Date: Wed, 2 Apr 2025 19:16:55 +0100 Message-ID: <20250402181709.2386022-2-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402181709.2386022-1-willy@infradead.org> References: <20250402181709.2386022-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 01F7620004 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: tk5uiamjsj3dbsb5ihnsekqcnuioe6iy X-HE-Tag: 1743617856-724298 X-HE-Meta: U2FsdGVkX18Z9Yq4y1/t9MBLfpNRptvxNas3DXisShsV1NG6+0ES8dZpOlUccZh1eEoneZcAiI5FxkoevnhopWYg3Z5gDhU8Nb56AZcn2HnlYrf8eQz5HVIrdZmAwkoro+aA2DOk4JYjrAnJBBsmvf0lOBWawSnNuVRtbRDFqsQ3cMUrYUnInjfRlxSpC0Dq6akQuQGou0Ng5g+oqeFpX7zAwns/Jc/7+em/wGvw2TuUmuh8ebceU6sBFvpPl7/YT11atHLKTtd0GOd2/z6D4/eVJipYQUvXKD8p0DSMA/JSWd9bidscWFgxh5A/bYmT2bKfOx/8K0C40KjPBZQpfBRS9WoYnJk+mHwOpHQ2hlvMVumibYvzR4VY22SJTHc+2/OoR1H73Cu5JZ6/Orvqy2drOM0O3sAe47yY+zEulCNzi8zz4WEVtYO1F2Tq6GvTKf8dwICyO5qnXkRnUXop+nHAy7+ODii8ZFs3lUGmWWyR5XSPhnsviOQpnN3XgR8UQPWi16W9T4x4NbVayycXoUQ8D+LBx/RgiQaR4Tc4+IP/kViCfBScUWrlxY+Epw84NzeE9Ta1mP654Q9nFa0hKzPXlzXKhmpROaBlWG5n2dNvEK07pA61453ySmze7kN5rkw9Nuq9lLzobDqcaWN5Xe/B6kBmN78GByzmCu01bvd0o6aZRPW/OY1bdHR332Sfl4Wf4aZi9W8PbVAcr0C6kuRQIRvIbgtgp7wQJy4qS20MXgAJsGtcDDMGVrJBqrjseVQgs2o8OmHuWdLp8sDX2uTHql+PHrJa+k2O4Rbzx49tA9GuZ/oEb9tm5s+si1jyc6wpM7zfmXbnX6diKsvMyAWGc+nFClZ4JZevTI7z9oOwN5k7DVHAnA3HhLmY07hQxRZ0kyZ9G005zzq7N5PAOu0hFnQbzh21+/aosqJj9qXO+3qC81+NiojMLsSSu78FWKygZc4Hrmf9S5d/rLu K1WnYJgv ZygkToqJWwQEcuB69qSuWkTRi2Rt5+KKmjeHd90uRUOtZC2cP7iG6winLpTSFSLGNO99t69+mXyqGapWv5q7Kwktn0V+QGVFNwP73Ij1z9R+y4pye5+pNzbtl0kw/Bs5IF+1Rn25h+YCu5w8Ff22lS/uziH+4E015kRK9epPMoycG2lSgTl44AFVLzuSRF3N0UmkRsHJMBxLSdlGLJNRGYTdURJPrsILoWQU8zLJlE5jxRCxXkny4S9EnM/f7ZDc7RPKVtbI0zcGf94NYQjnSg23QvQ== 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: List-Subscribe: List-Unsubscribe: If the first access to a folio is a read that is then followed by a write, we can save a page fault. s390 implemented this in their mk_pte() in commit abf09bed3cce ("s390/mm: implement software dirty bits"), but other architectures can also benefit from this. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand Reviewed-by: Alexander Gordeev # for s390 --- arch/s390/include/asm/pgtable.h | 7 +------ mm/memory.c | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index f8a6b54986ec..49833002232b 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1450,12 +1450,7 @@ static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot) static inline pte_t mk_pte(struct page *page, pgprot_t pgprot) { - unsigned long physpage = page_to_phys(page); - pte_t __pte = mk_pte_phys(physpage, pgprot); - - if (pte_write(__pte) && PageDirty(page)) - __pte = pte_mkdirty(__pte); - return __pte; + return mk_pte_phys(page_to_phys(page), pgprot); } #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) diff --git a/mm/memory.c b/mm/memory.c index 2d8c265fc7d6..68bcf639a78c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5245,6 +5245,8 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, if (write) entry = maybe_mkwrite(pte_mkdirty(entry), vma); + else if (pte_write(entry) && folio_test_dirty(folio)) + entry = pte_mkdirty(entry); if (unlikely(vmf_orig_pte_uffd_wp(vmf))) entry = pte_mkuffd_wp(entry); /* copy-on-write page */