[RFC PATCH v2 04/21] mm/zsmalloc: add alternatives of frequently used helper functions

From: Hyeonggon Yoo
Date: Thu Jul 13 2023 - 00:21:29 EST


get_first_page(), get_next_page(), is_first_page() are frequently used
throughout zsmalloc code. As replacing them all at once would be hard to
review, add alternative helpers and gradually replace its users to
use new functions.

Signed-off-by: Hyeonggon Yoo <42.hyeyoo@xxxxxxxxx>
---
mm/zsmalloc.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 8f7d9b79d849..f44a2d8a36b5 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -498,6 +498,11 @@ static __maybe_unused int is_first_page(struct page *page)
return PagePrivate(page);
}

+static __maybe_unused int is_first_zsdesc(struct zsdesc *zsdesc)
+{
+ return PagePrivate(zsdesc_page(zsdesc));
+}
+
/* Protected by pool->lock */
static inline int get_zspage_inuse(struct zspage *zspage)
{
@@ -510,7 +515,7 @@ static inline void mod_zspage_inuse(struct zspage *zspage, int val)
zspage->inuse += val;
}

-static inline struct page *get_first_page(struct zspage *zspage)
+static __maybe_unused inline struct page *get_first_page(struct zspage *zspage)
{
struct page *first_page = zsdesc_page(zspage->first_zsdesc);

@@ -518,6 +523,14 @@ static inline struct page *get_first_page(struct zspage *zspage)
return first_page;
}

+static __maybe_unused struct zsdesc *get_first_zsdesc(struct zspage *zspage)
+{
+ struct zsdesc *first_zsdesc = zspage->first_zsdesc;
+
+ VM_BUG_ON_PAGE(!is_first_zsdesc(first_zsdesc), zsdesc_page(first_zsdesc));
+ return first_zsdesc;
+}
+
static inline unsigned int get_first_obj_offset(struct page *page)
{
return page->page_type;
@@ -806,7 +819,7 @@ static struct zspage *get_zspage(struct page *page)
return zspage;
}

-static struct page *get_next_page(struct page *page)
+static __maybe_unused struct page *get_next_page(struct page *page)
{
struct zspage *zspage = get_zspage(page);

@@ -816,6 +829,16 @@ static struct page *get_next_page(struct page *page)
return (struct page *)page->index;
}

+static __maybe_unused struct zsdesc *get_next_zsdesc(struct zsdesc *zsdesc)
+{
+ struct zspage *zspage = get_zspage(zsdesc_page(zsdesc));
+
+ if (unlikely(ZsHugePage(zspage)))
+ return NULL;
+
+ return zsdesc->next;
+}
+
/**
* obj_to_location - get (<page>, <obj_idx>) from encoded object value
* @obj: the encoded object value
--
2.41.0