From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Oscar Salvador <osalvador@suse.de>
Subject: [PATCH 2/5] hugetlb: Add hugetlb_pfn_folio
Date: Fri, 1 Mar 2024 21:47:07 +0000 [thread overview]
Message-ID: <20240301214712.2853147-3-willy@infradead.org> (raw)
In-Reply-To: <20240301214712.2853147-1-willy@infradead.org>
Returns the hugetlb folio containing this PFN or NULL if the PFN
is not within a hugetlb folio.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/hugetlb.h | 1 +
mm/hugetlb.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 77b30a8c6076..c1d23ab53752 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -163,6 +163,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
long freed);
bool isolate_hugetlb(struct folio *folio, struct list_head *list);
+struct folio *hugetlb_pfn_folio(unsigned long pfn);
int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison);
int get_huge_page_for_hwpoison(unsigned long pfn, int flags,
bool *migratable_cleared);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 963c25963b5e..0895debc36f3 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -124,6 +124,33 @@ bool folio_test_hugetlb(const struct folio *folio)
}
EXPORT_SYMBOL_GPL(folio_test_hugetlb);
+/**
+ * hugetlb_pfn_folio - Convert a pfn to a hugetlb folio.
+ * @pfn: The Page Frame Number.
+ *
+ * If this function returns NULL, the pfn definitely wasn't part of
+ * a hugetlb folio. If a folio pointer is returned, this pfn was
+ * part of that hugetlb folio at some point. If the caller holds
+ * the @hugetlb_lock, hugetlb folios may not be returned to the page
+ * allocator, so the folio will still be valid (it may or may not
+ * be free).
+ *
+ * Return: NULL if the pfn is not part of a hugetlb folio.
+ */
+struct folio *hugetlb_pfn_folio(unsigned long pfn)
+{
+ struct page *page = pfn_to_page(pfn);
+ struct folio *folio;
+
+ if (!PageCompound(page))
+ return NULL;
+ folio = page_folio(page);
+ if (folio->large_id != &hugetlb_lock)
+ return NULL;
+
+ return folio;
+}
+
static inline bool subpool_is_free(struct hugepage_subpool *spool)
{
if (spool->count)
--
2.43.0
next prev parent reply other threads:[~2024-03-01 21:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 21:47 [PATCH 0/5] Remove some races around folio_test_hugetlb Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 1/5] hugetlb: Make folio_test_hugetlb safer to call Matthew Wilcox (Oracle)
2024-03-05 6:43 ` Oscar Salvador
2024-03-05 8:39 ` David Hildenbrand
2024-03-01 21:47 ` Matthew Wilcox (Oracle) [this message]
2024-03-05 6:58 ` [PATCH 2/5] hugetlb: Add hugetlb_pfn_folio Oscar Salvador
2024-03-01 21:47 ` [PATCH 3/5] memory-failure: Use hugetlb_pfn_folio Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 4/5] memory-failure: Reorganise get_huge_page_for_hwpoison() Matthew Wilcox (Oracle)
2024-03-01 21:47 ` [PATCH 5/5] compaction: Use hugetlb_pfn_folio in isolate_migratepages_block Matthew Wilcox (Oracle)
2024-03-04 9:09 ` [PATCH 0/5] Remove some races around folio_test_hugetlb Miaohe Lin
2024-03-04 17:08 ` Matthew Wilcox
2024-03-06 7:58 ` Miaohe Lin
2024-03-07 21:16 ` Matthew Wilcox
2024-03-05 9:10 ` David Hildenbrand
2024-03-05 20:35 ` Matthew Wilcox
2024-03-06 15:18 ` David Hildenbrand
2024-03-07 4:31 ` Matthew Wilcox
2024-03-07 9:20 ` David Hildenbrand
2024-03-07 21:14 ` Matthew Wilcox
2024-03-07 21:38 ` David Hildenbrand
2024-03-08 4:31 ` Matthew Wilcox
2024-03-08 8:46 ` David Hildenbrand
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=20240301214712.2853147-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
/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).