From patchwork Fri Jun 7 21:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13690660 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 ADEFEC27C53 for ; Fri, 7 Jun 2024 21:14:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E8AB6B0098; Fri, 7 Jun 2024 17:14:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 397BA6B009D; Fri, 7 Jun 2024 17:14:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 239726B00A5; Fri, 7 Jun 2024 17:14:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 039F56B0098 for ; Fri, 7 Jun 2024 17:14:31 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B514A1C1C5A for ; Fri, 7 Jun 2024 21:14:31 +0000 (UTC) X-FDA: 82205346342.23.9AAD49E Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf03.hostedemail.com (Postfix) with ESMTP id CED9B2000B for ; Fri, 7 Jun 2024 21:14:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gIxRc1As; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717794869; 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=VWi1D+MWFV3PdLNdsuc+9ZlTB2gIrgKafnL+RRtVsTs=; b=GfS8+Ir6WG6b+XnioIwA2q/K1tAo3wfdwKwwbhKytAlrDmgm1jU5TCNj/0QqtC8JIFQ9VS D9vJPRF442j7zcljvK95y1DfplKCRsO20JHm3pjP1owFEnuJjkoAJoGORRAoFNrTslc1fL 12OeVRes8KpedoLXwu9Vk6ghcaO7cAY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=gIxRc1As; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717794869; a=rsa-sha256; cv=none; b=kmfadRVPq8R5cFvKoKrjCJ6We3V0Fckt0VmxtLoOSI6XONShi5t15QS8FMIBhaX/BIgvJj C4Y5le8r1Dj5dZdeHXbj+FPxr4lTwsSzFQPfOD/S1o1/sVpJHsYWj7gmO4hZeO+cD4O/lX k8esq76t54d2g/lc/TCmjuwbPJkUeOU= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f62fae8c1aso20522085ad.3 for ; Fri, 07 Jun 2024 14:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717794869; x=1718399669; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VWi1D+MWFV3PdLNdsuc+9ZlTB2gIrgKafnL+RRtVsTs=; b=gIxRc1As/OPOlBt3hz2ishG0Q1upKbL2IVu32A/hbIwl+3ZDFihxzaerKnyWm6uxhC 1DPC/osscD/LGX1l1T+hmC7Yirdfh3kVZJhOOVVeqy8N2B9l9+S7CQRanPTZ2+JNWbBq 1augxj60ppAmlnDduOltsjjHL0Mj52ZNLGNIeO6KOvWRhWNNmxt6yNGEXkwY6hPMy9qe ZvLZJxVPUPnh1v5hksgf/m+T3yI/4UorOfvIpTezZTOeTyYZpda8PNk8+itySECWJdg2 W/NOH2V+nHvbnd0ZAULAGxkpodCSsWcXFAtyHqLSTjzcylq6c2ImrTIAuzK5b19+y7+I 0Y5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717794869; x=1718399669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VWi1D+MWFV3PdLNdsuc+9ZlTB2gIrgKafnL+RRtVsTs=; b=t06GLWW5xJqj1E9lLIbNOFRxUYohP3C2Fmah69GAPAlvFWmbM9nvSqVDcFuxz5Xggn 187kvxU8M6G9ux7mgzjMPYcGQeYxBidR0oTAcrRgMIqHm4/kheJS0k5uHNffx5hXKBY6 hXsSZB/s+7MTuVAEzTJmo350PYaOb6Z2RjxEC7acGUmCLDnhLRSop1U23w+K2AcqC82S h1y4PPTdfsHTq+OFHzO90fNh7nNBQbsiTL0lNJJgWpBgXPrQikgRaZ06Kz+3dZVkPUJ3 tt+bS9laDtdB9yC/TXvzvq67vI/JtZa3EqEug00Xao4cYDDRr5A17GAlEQGZsedSSwGG mnFg== X-Forwarded-Encrypted: i=1; AJvYcCXGdPPUrQZPrK9/9XsFNCL0jbB+s4tq9En2yAj6+aMipK/5RHIp8JnTuORdZmVvelkUVOsy8n0mFSmeQyWEFDhgrvg= X-Gm-Message-State: AOJu0YyVEc7JJBFTgc02xvru+iirHBkCfpBBEIl92CmafCEpjFoYa86s mOD4ZW+00S1zJTjTs2MgDiC8V/y0PlR4wKcOWftAel+d6im0nsDl X-Google-Smtp-Source: AGHT+IG6pwtK/hl5JOm7TirT0nRdsgcUjVPOoWYAZpxsEa+99qZaWFnUTQy5hXv8A03dkjib73+KUQ== X-Received: by 2002:a17:903:234b:b0:1e0:bae4:48f9 with SMTP id d9443c01a7336-1f6d02f3c76mr39672315ad.32.1717794868604; Fri, 07 Jun 2024 14:14:28 -0700 (PDT) Received: from barry-desktop.hub ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6d859ea3csm17912255ad.178.2024.06.07.14.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 14:14:28 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: chrisl@kernel.org, kasong@tencent.com, linux-kernel@vger.kernel.org, minchan@kernel.org, ryan.roberts@arm.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org Subject: [PATCH v2 2/2] mm: set pte writable while pte_soft_dirty() is true in do_swap_page() Date: Sat, 8 Jun 2024 09:13:58 +1200 Message-Id: <20240607211358.4660-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607211358.4660-1-21cnbao@gmail.com> References: <20240607211358.4660-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CED9B2000B X-Stat-Signature: dbtx4byfdpt79wzai4nq559aqwghxu7r X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1717794869-426178 X-HE-Meta: U2FsdGVkX18ZX+wQgw4JRyZyBlluQiNry2DrzffKDtx9s4jYfA5RSqLpTi2d6ru28qJASU7KHuqhcAI0gOz9C/dstzCbkicUNCCmVtH9d+wHdjjrowqVmNiw8bwv6Xf7rJjzzx0px0Uta0MACU9VG7y2RCvr2FpsbCYQKHwmA6fAPosjjogOmqblFzIvTmPTfLjroF1AicnubV4x1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LiI3v1Dj1OeHuAK/4gydZiy7EZ+udS765mj0UYKmNI1wQKS2NPTQPaPQjRU61vEhTU6D2TScgAxk+Ls4tV/pTh8SSMGKuC/Xr+RConePLdrTXKRX2qx7l4sETCejQwqvQO43+fx5iXp9lRQCHM9x/1tIM8BP/AtgieAVuHLZKFHg4fDzNariAQAYi2TgWx7ePQ2voFhY3F1Zm+D1x+ADOtAg0tM2f2cDIUma97J+SZdNqa06vuzJCY64bJ8qpFnX7Nvl0dRZFuYXaRfKdsdZ3Kv+QbpZuHV/1VI5xNmXZFut5+AqAHgNbqLY6Fsau0IJE+Fx7Vt3dEV2JQ== 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: From: Barry Song This patch leverages the new pte_needs_soft_dirty_wp() helper to optimize a scenario where softdirty is enabled, but the softdirty flag has already been set in do_swap_page(). In this situation, we can use pte_mkwrite instead of applying write-protection since we don't depend on write faults. Suggested-by: David Hildenbrand Signed-off-by: Barry Song Acked-by: David Hildenbrand --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index db9130488231..a063e489446d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4322,7 +4322,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (!folio_test_ksm(folio) && (exclusive || folio_ref_count(folio) == 1)) { if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma, pte) && - !vma_soft_dirty_enabled(vma)) { + !pte_needs_soft_dirty_wp(vma, pte)) { pte = pte_mkwrite(pte, vma); if (vmf->flags & FAULT_FLAG_WRITE) { pte = pte_mkdirty(pte);