[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230106174028.151384-2-sj@kernel.org>
Date: Fri, 6 Jan 2023 17:40:26 +0000
From: SeongJae Park <sj@...nel.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: SeongJae Park <sj@...nel.org>, willy@...radead.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: [PATCH 1/3] include/linux/page-flags: add folio_headpage()
The standard idiom for getting head page of a given folio is
'&folio->page'. It is efficient and safe even if the folio is NULL,
because the offset of page field in folio is zero. However, it makes
the code not that easy to understand at the first glance, especially the
NULL safety. Also, sometimes people forget the idiom and use
'folio_page(folio, 0)' instead. To make it easier to read and remember,
add a new macro function called 'folio_headpage()' with the NULL case
explanation.
Signed-off-by: SeongJae Park <sj@...nel.org>
---
include/linux/page-flags.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 69e93a0c1277..5a22bd823a5d 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -285,6 +285,14 @@ static inline unsigned long _compound_head(const struct page *page)
*/
#define folio_page(folio, n) nth_page(&(folio)->page, n)
+/**
+ * folio_headpage - Return the head page from a folio.
+ * @folio: The pointer to the folio.
+ *
+ * Return: The head page of the folio, or NULL if the folio is NULL.
+ */
+#define folio_headpage(folio) (&(folio)->page)
+
static __always_inline int PageTail(struct page *page)
{
return READ_ONCE(page->compound_head) & 1 || page_is_fake_head(page);
--
2.25.1
Powered by blists - more mailing lists