From: Lance Yang <ioworker0@gmail.com>
To: akpm@linux-foundation.org
Cc: 21cnbao@gmail.com, ryan.roberts@arm.com, dev.jain@arm.com,
david@redhat.com, shy828301@gmail.com, ziy@nvidia.com,
libang.li@antgroup.com, baolin.wang@linux.alibaba.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Lance Yang <ioworker0@gmail.com>,
Mingzhe Yang <mingzhe.yang@ly.com>
Subject: [RFC 1/2] mm/mthp: add pte_range_none_or_zeropfn() helper
Date: Mon, 20 Jan 2025 09:22:29 +0800 [thread overview]
Message-ID: <20250120012230.3343-2-ioworker0@gmail.com> (raw)
In-Reply-To: <20250120012230.3343-1-ioworker0@gmail.com>
In preparation for relaxing the mTHP PTE mapping restriction on the demand
zero page. We intend to provide more opportunities to take advantage of
mTHP.
Signed-off-by: Mingzhe Yang <mingzhe.yang@ly.com>
Signed-off-by: Lance Yang <ioworker0@gmail.com>
---
mm/memory.c | 43 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 2a20e3810534..4e148309b3e0 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4724,18 +4724,55 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
return ret;
}
-static bool pte_range_none(pte_t *pte, int nr_pages)
+/* Flags for __pte_range_check(). */
+typedef int __bitwise prc_t;
+
+/* Check if PTEs are not present. */
+#define PRC_CHECK_NONE ((__force prc_t)BIT(0))
+
+/* Check if PTEs are mapped to the zero page. */
+#define PRC_CHECK_ZEROPFN ((__force prc_t)BIT(1))
+
+static bool __pte_range_check(pte_t *pte, int nr_pages, prc_t flags,
+ bool *any_zeropfn)
{
int i;
+ pte_t ptent;
+
+ if (any_zeropfn)
+ *any_zeropfn = false;
for (i = 0; i < nr_pages; i++) {
- if (!pte_none(ptep_get_lockless(pte + i)))
- return false;
+ ptent = ptep_get_lockless(pte + i);
+
+ if ((flags & PRC_CHECK_NONE) && pte_none(ptent))
+ continue;
+
+ if ((flags & PRC_CHECK_ZEROPFN) &&
+ is_zero_pfn(pte_pfn(ptent))) {
+ if (any_zeropfn)
+ *any_zeropfn = true;
+ continue;
+ }
+
+ return false;
}
return true;
}
+static inline bool pte_range_none(pte_t *pte, int nr_pages)
+{
+ return __pte_range_check(pte, nr_pages, PRC_CHECK_NONE, NULL);
+}
+
+static inline bool pte_range_none_or_zeropfn(pte_t *pte, int nr_pages,
+ bool *any_zeropfn)
+{
+ return __pte_range_check(
+ pte, nr_pages, PRC_CHECK_NONE | PRC_CHECK_ZEROPFN, any_zeropfn);
+}
+
static struct folio *alloc_anon_folio(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
--
2.45.2
next prev parent reply other threads:[~2025-01-20 1:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-20 1:22 [RFC 0/2] relax anon mTHP PTE Mapping restrictions Lance Yang
2025-01-20 1:22 ` Lance Yang [this message]
2025-01-20 1:22 ` [RFC 2/2] mm/mthp: " Lance Yang
2025-01-20 2:15 ` Barry Song
2025-01-20 13:20 ` Lance Yang
2025-01-20 13:38 ` David Hildenbrand
2025-01-21 12:57 ` Lance Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250120012230.3343-2-ioworker0@gmail.com \
--to=ioworker0@gmail.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=libang.li@antgroup.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingzhe.yang@ly.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®