linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yafang Shao <laoar.shao@gmail.com>
To: akpm@linux-foundation.org
Cc: vbabka@suse.cz, 42.hyeyoo@gmail.com, willy@infradead.org,
	linux-mm@kvack.org, Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCH -mm 2/2] mm: page_idle: split 32bit page_idle's flag from the common flags
Date: Sat, 17 Dec 2022 10:58:33 +0000	[thread overview]
Message-ID: <20221217105833.24851-3-laoar.shao@gmail.com> (raw)
In-Reply-To: <20221217105833.24851-1-laoar.shao@gmail.com>

After we split page_owner's flag from the common page_ext flags, now
only 32bit page_idle is using the commt flags. Then we can define a flag
for 32bit page_idle only.
After this patch, the size of struct page_ext will be 0, so it won't
take extra memory overhead for the page_ext which don't use this flag.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 include/linux/page_ext.h  | 12 +-----------
 include/linux/page_idle.h | 39 +++++++++++++++++++++++++++++++++------
 mm/page_ext.c             | 10 ----------
 mm/page_idle.c            | 12 ++++++++++++
 4 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
index c8ca4954145c..6515d2a62f34 100644
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -15,14 +15,6 @@ struct page_ext_operations {
 };
 
 #ifdef CONFIG_PAGE_EXTENSION
-
-#if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT)
-enum page_ext_flags {
-	PAGE_EXT_YOUNG,
-	PAGE_EXT_IDLE,
-};
-#endif
-
 /*
  * Page Extension can be considered as an extended mem_map.
  * A page_ext page is associated with every page descriptor. The
@@ -30,9 +22,7 @@ enum page_ext_flags {
  * All page_ext are allocated at boot or memory hotplug event,
  * then the page_ext for pfn always exists.
  */
-struct page_ext {
-	unsigned long flags;
-};
+struct page_ext {};
 
 extern bool early_page_ext;
 extern unsigned long page_ext_size;
diff --git a/include/linux/page_idle.h b/include/linux/page_idle.h
index 5cb7bd2078ec..4d1311fdae1d 100644
--- a/include/linux/page_idle.h
+++ b/include/linux/page_idle.h
@@ -9,6 +9,21 @@
 #ifdef CONFIG_PAGE_IDLE_FLAG
 
 #ifndef CONFIG_64BIT
+enum page_idle_flags {
+	PAGE_EXT_YOUNG,
+	PAGE_EXT_IDLE,
+};
+
+struct page_idle {
+	unsigned long flags;
+};
+
+extern struct page_ext_operations page_idle_ops;
+static inline struct page_idle *get_page_idle(struct page_ext *page_ext)
+{
+	return (void *)page_ext + page_idle_ops.offset;
+}
+
 /*
  * If there is not enough space to store Idle and Young bits in page flags, use
  * page ext flags instead.
@@ -16,12 +31,14 @@
 static inline bool folio_test_young(struct folio *folio)
 {
 	struct page_ext *page_ext = page_ext_get(&folio->page);
+	struct page_idle *pi;
 	bool page_young;
 
 	if (unlikely(!page_ext))
 		return false;
 
-	page_young = test_bit(PAGE_EXT_YOUNG, &page_ext->flags);
+	pi = get_page_idle(page_ext);
+	page_young = test_bit(PAGE_EXT_YOUNG, &pi->flags);
 	page_ext_put(page_ext);
 
 	return page_young;
@@ -30,23 +47,27 @@ static inline bool folio_test_young(struct folio *folio)
 static inline void folio_set_young(struct folio *folio)
 {
 	struct page_ext *page_ext = page_ext_get(&folio->page);
+	struct page_idle *pi;
 
 	if (unlikely(!page_ext))
 		return;
 
-	set_bit(PAGE_EXT_YOUNG, &page_ext->flags);
+	pi = get_page_idle(page_ext);
+	set_bit(PAGE_EXT_YOUNG, &pi->flags);
 	page_ext_put(page_ext);
 }
 
 static inline bool folio_test_clear_young(struct folio *folio)
 {
 	struct page_ext *page_ext = page_ext_get(&folio->page);
+	struct page_idle *pi;
 	bool page_young;
 
 	if (unlikely(!page_ext))
 		return false;
 
-	page_young = test_and_clear_bit(PAGE_EXT_YOUNG, &page_ext->flags);
+	pi = get_page_idle(page_ext);
+	page_young = test_and_clear_bit(PAGE_EXT_YOUNG, &pi->flags);
 	page_ext_put(page_ext);
 
 	return page_young;
@@ -55,12 +76,14 @@ static inline bool folio_test_clear_young(struct folio *folio)
 static inline bool folio_test_idle(struct folio *folio)
 {
 	struct page_ext *page_ext = page_ext_get(&folio->page);
+	struct page_idle *pi;
 	bool page_idle;
 
 	if (unlikely(!page_ext))
 		return false;
 
-	page_idle =  test_bit(PAGE_EXT_IDLE, &page_ext->flags);
+	pi = get_page_idle(page_ext);
+	page_idle =  test_bit(PAGE_EXT_IDLE, &pi->flags);
 	page_ext_put(page_ext);
 
 	return page_idle;
@@ -69,22 +92,26 @@ static inline bool folio_test_idle(struct folio *folio)
 static inline void folio_set_idle(struct folio *folio)
 {
 	struct page_ext *page_ext = page_ext_get(&folio->page);
+	struct page_idle *pi;
 
 	if (unlikely(!page_ext))
 		return;
 
-	set_bit(PAGE_EXT_IDLE, &page_ext->flags);
+	pi = get_page_idle(page_ext);
+	set_bit(PAGE_EXT_IDLE, &pi->flags);
 	page_ext_put(page_ext);
 }
 
 static inline void folio_clear_idle(struct folio *folio)
 {
 	struct page_ext *page_ext = page_ext_get(&folio->page);
+	struct page_idle *pi;
 
 	if (unlikely(!page_ext))
 		return;
 
-	clear_bit(PAGE_EXT_IDLE, &page_ext->flags);
+	pi = get_page_idle(page_ext);
+	clear_bit(PAGE_EXT_IDLE, &pi->flags);
 	page_ext_put(page_ext);
 }
 #endif /* !CONFIG_64BIT */
diff --git a/mm/page_ext.c b/mm/page_ext.c
index 4ee522fd381c..b3459bf08b78 100644
--- a/mm/page_ext.c
+++ b/mm/page_ext.c
@@ -64,16 +64,6 @@
 #define PAGE_EXT_INVALID       (0x1)
 #endif
 
-#if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT)
-static bool need_page_idle(void)
-{
-	return true;
-}
-static struct page_ext_operations page_idle_ops __initdata = {
-	.need = need_page_idle,
-};
-#endif
-
 static struct page_ext_operations *page_ext_ops[] __initdata = {
 #ifdef CONFIG_PAGE_OWNER
 	&page_owner_ops,
diff --git a/mm/page_idle.c b/mm/page_idle.c
index bc08332a609c..ea1b08a541b3 100644
--- a/mm/page_idle.c
+++ b/mm/page_idle.c
@@ -18,6 +18,18 @@
 #define BITMAP_CHUNK_SIZE	sizeof(u64)
 #define BITMAP_CHUNK_BITS	(BITMAP_CHUNK_SIZE * BITS_PER_BYTE)
 
+#ifndef CONFIG_64BIT
+static bool need_page_idle(void)
+{
+	return true;
+}
+
+struct page_ext_operations page_idle_ops __initdata = {
+	.size = sizeof(struct page_idle),
+	.need = need_page_idle,
+};
+#endif
+
 /*
  * Idle page tracking only considers user memory pages, for other types of
  * pages the idle flag is always unset and an attempt to set it is silently
-- 
2.30.1 (Apple Git-130)



  parent reply	other threads:[~2022-12-17 10:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-17 10:58 [PATCH -mm 0/2] mm: page_ext: split page_ext flags Yafang Shao
2022-12-17 10:58 ` [PATCH -mm 1/2] mm: page_owner: split page_owner's flag from the comm flags Yafang Shao
2022-12-17 10:58 ` Yafang Shao [this message]
2022-12-17 12:45   ` [PATCH -mm 2/2] mm: page_idle: split 32bit page_idle's flag from the common flags kernel test robot
2022-12-17 13:59     ` Yafang Shao
2022-12-17 12:45   ` kernel test robot
2022-12-18  8:08 ` [PATCH -mm 0/2] mm: page_ext: split page_ext flags Hyeonggon Yoo
2022-12-18 10:01   ` Yafang Shao
2022-12-18 11:22     ` Hyeonggon Yoo
2023-01-16 10:58 ` Vlastimil Babka
2023-01-18  3:15   ` Yafang Shao

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=20221217105833.24851-3-laoar.shao@gmail.com \
    --to=laoar.shao@gmail.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    --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).