diff mbox series

[v8,16/21] mm/zsmalloc: convert SetZsPageMovable and remove unused funcs

Message ID 20241205175000.3187069-17-willy@infradead.org (mailing list archive)
State New
Headers show
Series Add zpdesc memory descriptor for zswap.zpool | expand

Commit Message

Matthew Wilcox (Oracle) Dec. 5, 2024, 5:49 p.m. UTC
From: Alex Shi <alexs@kernel.org>

Convert SetZsPageMovable() to use zpdesc, and then remove unused
funcs: get_next_page()/get_first_page()/is_first_page().

Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Signed-off-by: Alex Shi <alexs@kernel.org>
---
 mm/zsmalloc.c | 33 +++++----------------------------
 1 file changed, 5 insertions(+), 28 deletions(-)

Comments

Hyeonggon Yoo Dec. 10, 2024, 2:04 p.m. UTC | #1
On Thu, Dec 05, 2024 at 05:49:53PM +0000, Matthew Wilcox (Oracle) wrote:
> From: Alex Shi <alexs@kernel.org>
> 
> Convert SetZsPageMovable() to use zpdesc, and then remove unused
> funcs: get_next_page()/get_first_page()/is_first_page().
> 
> Originally-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> Signed-off-by: Alex Shi <alexs@kernel.org>
> ---

Looks good to me,
Hyeonggon Yoo <42.hyeyoo@gmail.com>

>  mm/zsmalloc.c | 33 +++++----------------------------
>  1 file changed, 5 insertions(+), 28 deletions(-)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index bf1db07c58cf..16e3d6705563 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -470,11 +470,6 @@ static DEFINE_PER_CPU(struct mapping_area, zs_map_area) = {
>  	.lock	= INIT_LOCAL_LOCK(lock),
>  };
>  
> -static __maybe_unused int is_first_page(struct page *page)
> -{
> -	return PagePrivate(page);
> -}
> -
>  static inline bool is_first_zpdesc(struct zpdesc *zpdesc)
>  {
>  	return PagePrivate(zpdesc_page(zpdesc));
> @@ -491,14 +486,6 @@ static inline void mod_zspage_inuse(struct zspage *zspage, int val)
>  	zspage->inuse += val;
>  }
>  
> -static inline struct page *get_first_page(struct zspage *zspage)
> -{
> -	struct page *first_page = zpdesc_page(zspage->first_zpdesc);
> -
> -	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
> -	return first_page;
> -}
> -
>  static struct zpdesc *get_first_zpdesc(struct zspage *zspage)
>  {
>  	struct zpdesc *first_zpdesc = zspage->first_zpdesc;
> @@ -783,16 +770,6 @@ static struct zspage *get_zspage(struct zpdesc *zpdesc)
>  	return zspage;
>  }
>  
> -static struct page *get_next_page(struct page *page)
> -{
> -	struct zspage *zspage = get_zspage(page_zpdesc(page));
> -
> -	if (unlikely(ZsHugePage(zspage)))
> -		return NULL;
> -
> -	return (struct page *)page->index;
> -}
> -
>  static struct zpdesc *get_next_zpdesc(struct zpdesc *zpdesc)
>  {
>  	struct zspage *zspage = get_zspage(zpdesc);
> @@ -1955,13 +1932,13 @@ static void init_deferred_free(struct zs_pool *pool)
>  
>  static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
>  {
> -	struct page *page = get_first_page(zspage);
> +	struct zpdesc *zpdesc = get_first_zpdesc(zspage);
>  
>  	do {
> -		WARN_ON(!trylock_page(page));
> -		__SetPageMovable(page, &zsmalloc_mops);
> -		unlock_page(page);
> -	} while ((page = get_next_page(page)) != NULL);
> +		WARN_ON(!zpdesc_trylock(zpdesc));
> +		__zpdesc_set_movable(zpdesc, &zsmalloc_mops);
> +		zpdesc_unlock(zpdesc);
> +	} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
>  }
>  #else
>  static inline void zs_flush_migration(struct zs_pool *pool) { }
> -- 
> 2.45.2
> 
>
diff mbox series

Patch

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index bf1db07c58cf..16e3d6705563 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -470,11 +470,6 @@  static DEFINE_PER_CPU(struct mapping_area, zs_map_area) = {
 	.lock	= INIT_LOCAL_LOCK(lock),
 };
 
-static __maybe_unused int is_first_page(struct page *page)
-{
-	return PagePrivate(page);
-}
-
 static inline bool is_first_zpdesc(struct zpdesc *zpdesc)
 {
 	return PagePrivate(zpdesc_page(zpdesc));
@@ -491,14 +486,6 @@  static inline void mod_zspage_inuse(struct zspage *zspage, int val)
 	zspage->inuse += val;
 }
 
-static inline struct page *get_first_page(struct zspage *zspage)
-{
-	struct page *first_page = zpdesc_page(zspage->first_zpdesc);
-
-	VM_BUG_ON_PAGE(!is_first_page(first_page), first_page);
-	return first_page;
-}
-
 static struct zpdesc *get_first_zpdesc(struct zspage *zspage)
 {
 	struct zpdesc *first_zpdesc = zspage->first_zpdesc;
@@ -783,16 +770,6 @@  static struct zspage *get_zspage(struct zpdesc *zpdesc)
 	return zspage;
 }
 
-static struct page *get_next_page(struct page *page)
-{
-	struct zspage *zspage = get_zspage(page_zpdesc(page));
-
-	if (unlikely(ZsHugePage(zspage)))
-		return NULL;
-
-	return (struct page *)page->index;
-}
-
 static struct zpdesc *get_next_zpdesc(struct zpdesc *zpdesc)
 {
 	struct zspage *zspage = get_zspage(zpdesc);
@@ -1955,13 +1932,13 @@  static void init_deferred_free(struct zs_pool *pool)
 
 static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
 {
-	struct page *page = get_first_page(zspage);
+	struct zpdesc *zpdesc = get_first_zpdesc(zspage);
 
 	do {
-		WARN_ON(!trylock_page(page));
-		__SetPageMovable(page, &zsmalloc_mops);
-		unlock_page(page);
-	} while ((page = get_next_page(page)) != NULL);
+		WARN_ON(!zpdesc_trylock(zpdesc));
+		__zpdesc_set_movable(zpdesc, &zsmalloc_mops);
+		zpdesc_unlock(zpdesc);
+	} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
 }
 #else
 static inline void zs_flush_migration(struct zs_pool *pool) { }