Skip to contentSkip to conversation

Cleanups for zbud

PATCH In review Miaohe Lin 2 participants 7 messages Jun 8, 2021 – Jun 18, 2021

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

v2 cover Cleanups for zbud

Hi all,
This series contains just cleanups to save some possible memory in zbud_pool and avoid exporting any unneeded zbud API. More details can be found in the respective changelogs. Thanks!

v1->v2:
Use union and add comment per Andrew.

Miaohe Lin (2):
mm/zbud: reuse unbuddied[0] as buddied in zbud_pool mm/zbud: don't export any zbud API

 MAINTAINERS          |   1 -
 include/linux/zbud.h |  23 -----
 mm/zbud.c            | 229 +++++++++++++++++++++++--------------------
 3 files changed, 120 insertions(+), 133 deletions(-)
 delete mode 100644 include/linux/zbud.h
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH v2 1/2 mm/zbud: reuse unbuddied[0] as buddied in zbud_pool

Since commit 9d8c5b5284e4 ("mm: zbud: fix condition check on allocation size"), zbud_pool.unbuddied[0] is always unused. We can reuse it as buddied field to save some possible memory.

---
 mm/zbud.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
mm/zbud.c +8 -2
index a200121da400..78e80ca58869 100644
@@ -95,8 +95,14 @@
  */
 struct zbud_pool {
 	spinlock_t lock;
-	struct list_head unbuddied[NCHUNKS];
-	struct list_head buddied;
+	union {
+		/*
+		 * Reuse unbuddied[0] as buddied on the ground that
+		 * unbuddied[0] is unused.
+		 */
+		struct list_head buddied;
+		struct list_head unbuddied[NCHUNKS];
+	};
 	struct list_head lru;
 	u64 pages_nr;
 	const struct zbud_ops *ops;
Signature · 1 line
2.23.0
author
#2 lore raw

PATCH v2 2/2 mm/zbud: don't export any zbud API

In reply to Miaohe Lin

The zbud doesn't need to export any API and it is meant to be used via zpool API since the commit 12d79d64bfd3 ("mm/zpool: update zswap to use zpool"). So we can remove the unneeded zbud.h and move down zpool API to avoid any forward declaration.

---
 MAINTAINERS          |   1 -
 include/linux/zbud.h |  23 -----
 mm/zbud.c            | 219 ++++++++++++++++++++++---------------------
 3 files changed, 112 insertions(+), 131 deletions(-)
 delete mode 100644 include/linux/zbud.h
MAINTAINERS +0 -1
index d8648ee43199..625d66d7aacc 100644
@@ -20264,7 +20264,6 @@ M:	Seth Jennings <[email protected]>
 M:	Dan Streetman <[email protected]>
 L:	[email protected]
 S:	Maintained
-F:	include/linux/zbud.h
 F:	mm/zbud.c
 
 ZD1211RW WIRELESS DRIVER
include/linux/zbud.h deleted +0 -23
deleted file mode 100644
index b1eaf6e31735..000000000000
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ZBUD_H_
-#define _ZBUD_H_
-
-#include <linux/types.h>
-
-struct zbud_pool;
-
-struct zbud_ops {
-	int (*evict)(struct zbud_pool *pool, unsigned long handle);
-};
-
-struct zbud_pool *zbud_create_pool(gfp_t gfp, const struct zbud_ops *ops);
-void zbud_destroy_pool(struct zbud_pool *pool);
-int zbud_alloc(struct zbud_pool *pool, size_t size, gfp_t gfp,
-	unsigned long *handle);
-void zbud_free(struct zbud_pool *pool, unsigned long handle);
-int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries);
-void *zbud_map(struct zbud_pool *pool, unsigned long handle);
-void zbud_unmap(struct zbud_pool *pool, unsigned long handle);
-u64 zbud_get_pool_size(struct zbud_pool *pool);
-
-#endif /* _ZBUD_H_ */
mm/zbud.c +112 -107

289 lines not on this page · raw message

Signature · 1 line
2.23.0
#3 lore raw

Re: [PATCH v2 2/2] mm/zbud: don't export any zbud API

Quoted 6 lines · Miaohe Lin

The zbud doesn't need to export any API and it is meant to be used via zpool API since the commit 12d79d64bfd3 ("mm/zpool: update zswap to use zpool"). So we can remove the unneeded zbud.h and move down zpool API to avoid any forward declaration.

This patch causes several new warnings when CONFIG_ZPOOL is disabled:

mm/zbud.c:222:26: warning: unused function 'zbud_create_pool' [-Wunused-function] mm/zbud.c:246:13: warning: unused function 'zbud_destroy_pool' [-Wunused-function] mm/zbud.c:270:12: warning: unused function 'zbud_alloc' [-Wunused-function] mm/zbud.c:345:13: warning: unused function 'zbud_free' [-Wunused-function] mm/zbud.c:417:12: warning: unused function 'zbud_reclaim_page' [-Wunused-function] mm/zbud.c:499:14: warning: unused function 'zbud_map' [-Wunused-function] mm/zbud.c:509:13: warning: unused function 'zbud_unmap' [-Wunused-function] mm/zbud.c:520:12: warning: unused function 'zbud_get_pool_size' [-Wunused-function]

It seems to me like all of these functions should be sunk into their callers and eliminated entirely as part of this refactoring. I took a whack at it but got lost with the kernel docs so someone who is familiar with this should probably do it.

Cheers,
Nathan

author
#4 lore raw

Re: [PATCH v2 2/2] mm/zbud: don't export any zbud API

Hi:

Quoted 8 lines · Nathan Chancellor
Quoted 6 lines · Miaohe Lin

The zbud doesn't need to export any API and it is meant to be used via zpool API since the commit 12d79d64bfd3 ("mm/zpool: update zswap to use zpool"). So we can remove the unneeded zbud.h and move down zpool API to avoid any forward declaration.

Thank you for help figure these warnings out. It seems zbud module won't do anything when CONFIG_ZPOOL is disabled. I think we should make zbud depends on ZPOOL and eliminate the CONFIG_ZPOOL macro in zbud.c like what z3fold does. Does this make sense for you?
Thanks again. :)

mm/Kconfig +1 -0
index 8f748010f7ea..5dc28e9205e0 100644
@@ -674,6 +674,7 @@ config ZPOOL
 
 config ZBUD
        tristate "Low (Up to 2x) density storage for compressed pages"
+       depends on ZPOOL
        help
          A special purpose allocator for storing compressed pages.
          It is designed to store up to two compressed pages per physical
mm/zbud.c +0 -10
index 3f61304405cb..6348932430b8 100644
@@ -111,10 +111,8 @@ struct zbud_pool {
        struct list_head lru;
        u64 pages_nr;
        const struct zbud_ops *ops;
-#ifdef CONFIG_ZPOOL
        struct zpool *zpool;
        const struct zpool_ops *zpool_ops;
-#endif
 };
 
 /*
@@ -526,8 +524,6 @@ static u64 zbud_get_pool_size(struct zbud_pool *pool)
  * zpool
  ****************/
 
-#ifdef CONFIG_ZPOOL
-
 static int zbud_zpool_evict(struct zbud_pool *pool, unsigned long handle)
 {
        if (pool->zpool && pool->zpool_ops && pool->zpool_ops->evict)
@@ -618,7 +614,6 @@ static struct zpool_driver zbud_zpool_driver = {
 };
 
 MODULE_ALIAS("zpool-zbud");
-#endif /* CONFIG_ZPOOL */
 
 static int __init init_zbud(void)
 {
@@ -626,19 +621,14 @@ static int __init init_zbud(void)
        BUILD_BUG_ON(sizeof(struct zbud_header) > ZHDR_SIZE_ALIGNED);
        pr_info("loaded\n");
 
-#ifdef CONFIG_ZPOOL
        zpool_register_driver(&zbud_zpool_driver);
-#endif
 
        return 0;
 }
 
 static void __exit exit_zbud(void)
 {
-#ifdef CONFIG_ZPOOL
        zpool_unregister_driver(&zbud_zpool_driver);
-#endif
-
        pr_info("unloaded\n");
 }
 
Quoted 20 lines

This patch causes several new warnings when CONFIG_ZPOOL is disabled:

mm/zbud.c:222:26: warning: unused function 'zbud_create_pool' [-Wunused-function] mm/zbud.c:246:13: warning: unused function 'zbud_destroy_pool' [-Wunused-function] mm/zbud.c:270:12: warning: unused function 'zbud_alloc' [-Wunused-function] mm/zbud.c:345:13: warning: unused function 'zbud_free' [-Wunused-function] mm/zbud.c:417:12: warning: unused function 'zbud_reclaim_page' [-Wunused-function] mm/zbud.c:499:14: warning: unused function 'zbud_map' [-Wunused-function] mm/zbud.c:509:13: warning: unused function 'zbud_unmap' [-Wunused-function] mm/zbud.c:520:12: warning: unused function 'zbud_get_pool_size' [-Wunused-function]

It seems to me like all of these functions should be sunk into their callers and eliminated entirely as part of this refactoring. I took a whack at it but got lost with the kernel docs so someone who is familiar with this should probably do it.

Cheers,
Nathan
.

#5 lore raw

Re: [PATCH v2 2/2] mm/zbud: don't export any zbud API

Quoted 8 lines · Miaohe Lin

Hi:

Quoted 6 lines · Nathan Chancellor
Quoted 5 lines · Miaohe Lin

The zbud doesn't need to export any API and it is meant to be used via zpool API since the commit 12d79d64bfd3 ("mm/zpool: update zswap to use zpool"). So we can remove the unneeded zbud.h and move down zpool API to avoid any forward declaration.

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Thank you for help figure these warnings out. It seems zbud module won't do anything when CONFIG_ZPOOL is disabled. I think we should make zbud depends on ZPOOL and eliminate the CONFIG_ZPOOL macro in zbud.c like what z3fold does. Does this make sense for you?
Thanks again. :)

That seems logical to me. It probably makes sense to send that as a fix patch for this one so Andrew can squash it in.

Cheers,
Nathan

Quoted 85 lines
mm/Kconfig +1 -0
index 8f748010f7ea..5dc28e9205e0 100644
@@ -674,6 +674,7 @@ config ZPOOL
 
  config ZBUD
         tristate "Low (Up to 2x) density storage for compressed pages"
+       depends on ZPOOL
         help
           A special purpose allocator for storing compressed pages.
           It is designed to store up to two compressed pages per physical
mm/zbud.c +0 -10
index 3f61304405cb..6348932430b8 100644
@@ -111,10 +111,8 @@ struct zbud_pool {
         struct list_head lru;
         u64 pages_nr;
         const struct zbud_ops *ops;
-#ifdef CONFIG_ZPOOL
         struct zpool *zpool;
         const struct zpool_ops *zpool_ops;
-#endif
  };
 
  /*
@@ -526,8 +524,6 @@ static u64 zbud_get_pool_size(struct zbud_pool *pool)
   * zpool
   ****************/
 
-#ifdef CONFIG_ZPOOL
-
  static int zbud_zpool_evict(struct zbud_pool *pool, unsigned long handle)
  {
         if (pool->zpool && pool->zpool_ops && pool->zpool_ops->evict)
@@ -618,7 +614,6 @@ static struct zpool_driver zbud_zpool_driver = {
  };
 
  MODULE_ALIAS("zpool-zbud");
-#endif /* CONFIG_ZPOOL */
 
  static int __init init_zbud(void)
  {
@@ -626,19 +621,14 @@ static int __init init_zbud(void)
         BUILD_BUG_ON(sizeof(struct zbud_header) > ZHDR_SIZE_ALIGNED);
         pr_info("loaded\n");
 
-#ifdef CONFIG_ZPOOL
         zpool_register_driver(&zbud_zpool_driver);
-#endif
 
         return 0;
  }
 
  static void __exit exit_zbud(void)
  {
-#ifdef CONFIG_ZPOOL
         zpool_unregister_driver(&zbud_zpool_driver);
-#endif
-
         pr_info("unloaded\n");
  }
 
Quoted 20 lines

This patch causes several new warnings when CONFIG_ZPOOL is disabled:

mm/zbud.c:222:26: warning: unused function 'zbud_create_pool' [-Wunused-function] mm/zbud.c:246:13: warning: unused function 'zbud_destroy_pool' [-Wunused-function] mm/zbud.c:270:12: warning: unused function 'zbud_alloc' [-Wunused-function] mm/zbud.c:345:13: warning: unused function 'zbud_free' [-Wunused-function] mm/zbud.c:417:12: warning: unused function 'zbud_reclaim_page' [-Wunused-function] mm/zbud.c:499:14: warning: unused function 'zbud_map' [-Wunused-function] mm/zbud.c:509:13: warning: unused function 'zbud_unmap' [-Wunused-function] mm/zbud.c:520:12: warning: unused function 'zbud_get_pool_size' [-Wunused-function]

It seems to me like all of these functions should be sunk into their callers and eliminated entirely as part of this refactoring. I took a whack at it but got lost with the kernel docs so someone who is familiar with this should probably do it.

Cheers,
Nathan
.

author
#6 lore raw

Re: [PATCH v2 2/2] mm/zbud: don't export any zbud API

Quoted 12 lines · Nathan Chancellor
Quoted 11 lines · Miaohe Lin

Hi:

Quoted 8 lines · Nathan Chancellor
Quoted 6 lines · Miaohe Lin

The zbud doesn't need to export any API and it is meant to be used via zpool API since the commit 12d79d64bfd3 ("mm/zpool: update zswap to use zpool"). So we can remove the unneeded zbud.h and move down zpool API to avoid any forward declaration.

Quoted 7 lines
Quoted 5 lines

Thank you for help figure these warnings out. It seems zbud module won't do anything when CONFIG_ZPOOL is disabled. I think we should make zbud depends on ZPOOL and eliminate the CONFIG_ZPOOL macro in zbud.c like what z3fold does. Does this make sense for you?
Thanks again. :)

That seems logical to me. It probably makes sense to send that as a fix patch for this one so Andrew can squash it in.

Sure. This is also what I meant to do. Will do it later. Many thanks!

Quoted 91 lines

Cheers,
Nathan

Quoted 80 lines
mm/Kconfig +0 -0
index 8f748010f7ea..5dc28e9205e0 100644
@@ -674,6 +674,7 @@ config ZPOOL
 

  config ZBUD
         tristate "Low (Up to 2x) density storage for compressed pages" +       depends on ZPOOL
         help
           A special purpose allocator for storing compressed pages. It is designed to store up to two compressed pages per physical

mm/zbud.c +0 -10
index 3f61304405cb..6348932430b8 100644
@@ -111,10 +111,8 @@ struct zbud_pool {
          struct list_head lru;
          u64 pages_nr;
          const struct zbud_ops *ops;
-#ifdef CONFIG_ZPOOL
          struct zpool *zpool;
          const struct zpool_ops *zpool_ops;
-#endif
   };
 
   /*
@@ -526,8 +524,6 @@ static u64 zbud_get_pool_size(struct zbud_pool *pool)
    * zpool
    ****************/
 
-#ifdef CONFIG_ZPOOL
-
   static int zbud_zpool_evict(struct zbud_pool *pool, unsigned long handle)
   {
          if (pool->zpool && pool->zpool_ops && pool->zpool_ops->evict)
@@ -618,7 +614,6 @@ static struct zpool_driver zbud_zpool_driver = {
   };
 
   MODULE_ALIAS("zpool-zbud");
-#endif /* CONFIG_ZPOOL */
 
   static int __init init_zbud(void)
   {
@@ -626,19 +621,14 @@ static int __init init_zbud(void)
          BUILD_BUG_ON(sizeof(struct zbud_header) > ZHDR_SIZE_ALIGNED);
          pr_info("loaded\n");
 
-#ifdef CONFIG_ZPOOL
          zpool_register_driver(&zbud_zpool_driver);
-#endif
 
          return 0;
   }
 
   static void __exit exit_zbud(void)
   {
-#ifdef CONFIG_ZPOOL
          zpool_unregister_driver(&zbud_zpool_driver);
-#endif
-
          pr_info("unloaded\n");
   }
 
Quoted 16 lines

This patch causes several new warnings when CONFIG_ZPOOL is disabled:

mm/zbud.c:222:26: warning: unused function 'zbud_create_pool' [-Wunused-function] mm/zbud.c:246:13: warning: unused function 'zbud_destroy_pool' [-Wunused-function] mm/zbud.c:270:12: warning: unused function 'zbud_alloc' [-Wunused-function] mm/zbud.c:345:13: warning: unused function 'zbud_free' [-Wunused-function] mm/zbud.c:417:12: warning: unused function 'zbud_reclaim_page' [-Wunused-function] mm/zbud.c:499:14: warning: unused function 'zbud_map' [-Wunused-function] mm/zbud.c:509:13: warning: unused function 'zbud_unmap' [-Wunused-function] mm/zbud.c:520:12: warning: unused function 'zbud_get_pool_size' [-Wunused-function]

It seems to me like all of these functions should be sunk into their callers and eliminated entirely as part of this refactoring. I took a whack at it but got lost with the kernel docs so someone who is familiar with this should probably do it.

Quoted 5 lines
Quoted 4 lines

Cheers,
Nathan
.

.