diff mbox series

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

Message ID 20231130101242.2590384-5-42.hyeyoo@gmail.com (mailing list archive)
State New
Headers show
Series mm/zsmalloc: Split zsdesc from struct page | expand

Commit Message

Hyeonggon Yoo Nov. 30, 2023, 10:12 a.m. UTC
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@gmail.com>
---
 mm/zsmalloc.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox Dec. 4, 2023, 3:45 a.m. UTC | #1
On Thu, Nov 30, 2023 at 07:12:25PM +0900, Hyeonggon Yoo wrote:
> +static __maybe_unused int is_first_zsdesc(struct zsdesc *zsdesc)
> +{
> +	return PagePrivate(zsdesc_page(zsdesc));
> +}

static inline bool is_first_zsdesc(struct zsdesc *zsdesc)
{
	return folio_test_private(zsdesc_folio(zsdesc));
}

> -static inline struct page *get_first_page(struct zspage *zspage)
> +static __maybe_unused inline struct page *get_first_page(struct zspage *zspage)

I don't think you need __maybe_unused with inline.

> +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));

Do we want a VM_BUG_ON_ZSDESC?
Hyeonggon Yoo Dec. 5, 2023, 12:35 a.m. UTC | #2
On Mon, Dec 4, 2023 at 12:45 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Thu, Nov 30, 2023 at 07:12:25PM +0900, Hyeonggon Yoo wrote:
> > +static __maybe_unused int is_first_zsdesc(struct zsdesc *zsdesc)
> > +{
> > +     return PagePrivate(zsdesc_page(zsdesc));
> > +}
>
> static inline bool is_first_zsdesc(struct zsdesc *zsdesc)
> {
>         return folio_test_private(zsdesc_folio(zsdesc));
> }

PagePrivate(zsdesc_page(zsdesc)) is fine as zsmalloc always allocates
a base page,
and then build a chain of base pages. That's not going to change anytime soon.
But will drop __maybe_unused and add inline.

> > -static inline struct page *get_first_page(struct zspage *zspage)
> > +static __maybe_unused inline struct page *get_first_page(struct zspage *zspage)
>
> I don't think you need __maybe_unused with inline.

Right, will adjust in v4.

> > +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));
>
> Do we want a VM_BUG_ON_ZSDESC?

If the kernel starts allocating zsdesc separately, we'll need that.
But at now, I don't think we need to implement that yet?

Thanks!
--
Hyeonggon
diff mbox series

Patch

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 4c9f9a2cb681..c511539bee8c 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -502,6 +502,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)
 {
@@ -514,7 +519,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);
 
@@ -522,6 +527,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;
@@ -810,7 +823,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);
 
@@ -820,6 +833,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