linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <luizcap@redhat.com>
To: david@redhat.com, willy@infradead.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	shivankg@amd.com, sj@kernel.org, harry.yoo@oracle.com
Subject: [PATCH v3 1/4] mm/memory: introduce is_huge_zero_pfn() and use it in vm_normal_page_pmd()
Date: Mon, 14 Jul 2025 09:16:51 -0400	[thread overview]
Message-ID: <4940826e99f0c709a7cf7beb94f53288320aea5a.1752499009.git.luizcap@redhat.com> (raw)
In-Reply-To: <cover.1752499009.git.luizcap@redhat.com>

From: David Hildenbrand <david@redhat.com>

Let's avoid working with the PMD when not required. If
vm_normal_page_pmd() would be called on something that is not a present
pmd, it would already be a bug (pfn possibly garbage).

While at it, let's support passing in any pfn covered by the huge zero
folio by masking off PFN bits -- which should be rather cheap.

Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Luiz Capitulino <luizcap@redhat.com>
---
 include/linux/huge_mm.h | 12 +++++++++++-
 mm/memory.c             |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 2f190c90192d..59e93fba15f4 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -486,9 +486,14 @@ static inline bool is_huge_zero_folio(const struct folio *folio)
 	return READ_ONCE(huge_zero_folio) == folio;
 }
 
+static inline bool is_huge_zero_pfn(unsigned long pfn)
+{
+	return READ_ONCE(huge_zero_pfn) == (pfn & ~(HPAGE_PMD_NR - 1));
+}
+
 static inline bool is_huge_zero_pmd(pmd_t pmd)
 {
-	return pmd_present(pmd) && READ_ONCE(huge_zero_pfn) == pmd_pfn(pmd);
+	return pmd_present(pmd) && is_huge_zero_pfn(pmd_pfn(pmd));
 }
 
 struct folio *mm_get_huge_zero_folio(struct mm_struct *mm);
@@ -636,6 +641,11 @@ static inline bool is_huge_zero_folio(const struct folio *folio)
 	return false;
 }
 
+static inline bool is_huge_zero_pfn(unsigned long pfn)
+{
+	return false;
+}
+
 static inline bool is_huge_zero_pmd(pmd_t pmd)
 {
 	return false;
diff --git a/mm/memory.c b/mm/memory.c
index b0cda5aab398..3a765553bacb 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -687,7 +687,7 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 	if (pmd_devmap(pmd))
 		return NULL;
-	if (is_huge_zero_pmd(pmd))
+	if (is_huge_zero_pfn(pfn))
 		return NULL;
 	if (unlikely(pfn > highest_memmap_pfn))
 		return NULL;
-- 
2.50.0



  reply	other threads:[~2025-07-14 13:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-14 13:16 [PATCH v3 0/4] mm: introduce snapshot_page() Luiz Capitulino
2025-07-14 13:16 ` Luiz Capitulino [this message]
2025-07-14 14:26   ` [PATCH v3 1/4] mm/memory: introduce is_huge_zero_pfn() and use it in vm_normal_page_pmd() David Hildenbrand
2025-07-14 13:16 ` [PATCH v3 2/4] mm/util: introduce snapshot_page() Luiz Capitulino
2025-07-16 10:16   ` David Hildenbrand
2025-07-16 17:36     ` Luiz Capitulino
2025-07-16 18:18       ` David Hildenbrand
2025-07-16 22:19         ` Andrew Morton
2025-07-17  1:52           ` Luiz Capitulino
2025-07-17 15:54             ` Luiz Capitulino
2025-07-14 13:16 ` [PATCH v3 3/4] proc: kpagecount: use snapshot_page() Luiz Capitulino
2025-07-16 10:17   ` David Hildenbrand
2025-07-16 17:41     ` Luiz Capitulino
2025-07-16 18:18       ` David Hildenbrand
2025-07-14 13:16 ` [PATCH v3 4/4] fs: stable_page_flags(): " Luiz Capitulino
2025-07-16 10:19   ` David Hildenbrand
2025-07-14 13:55 ` [PATCH v3 0/4] mm: introduce snapshot_page() Shivank Garg
2025-07-15 22:53 ` Harry Yoo

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=4940826e99f0c709a7cf7beb94f53288320aea5a.1752499009.git.luizcap@redhat.com \
    --to=luizcap@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shivankg@amd.com \
    --cc=sj@kernel.org \
    --cc=willy@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).