diff mbox series

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

Message ID 20210608114515.206992-3-linmiaohe@huawei.com (mailing list archive)
State New, archived
Headers show
Series Cleanups for zbud | expand

Commit Message

Miaohe Lin June 8, 2021, 11:45 a.m. UTC
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.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 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

Comments

Nathan Chancellor June 18, 2021, 12:44 a.m. UTC | #1
On Tue, Jun 08, 2021 at 07:45:15PM +0800, Miaohe Lin wrote:
> 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.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

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
Miaohe Lin June 18, 2021, 2:28 a.m. UTC | #2
Hi:
On 2021/6/18 8:44, Nathan Chancellor wrote:
> On Tue, Jun 08, 2021 at 07:45:15PM +0800, Miaohe Lin wrote:
>> 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.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> 

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. :)

diff --git a/mm/Kconfig b/mm/Kconfig
index 8f748010f7ea..5dc28e9205e0 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -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
diff --git a/mm/zbud.c b/mm/zbud.c
index 3f61304405cb..6348932430b8 100644
--- a/mm/zbud.c
+++ b/mm/zbud.c
@@ -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");
 }

> 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
> .
>
Nathan Chancellor June 18, 2021, 2:42 a.m. UTC | #3
On 6/17/2021 7:28 PM, Miaohe Lin wrote:
> Hi:
> On 2021/6/18 8:44, Nathan Chancellor wrote:
>> On Tue, Jun 08, 2021 at 07:45:15PM +0800, Miaohe Lin wrote:
>>> 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.
>>>
>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>
> 
> 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

> diff --git a/mm/Kconfig b/mm/Kconfig
> index 8f748010f7ea..5dc28e9205e0 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -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
> diff --git a/mm/zbud.c b/mm/zbud.c
> index 3f61304405cb..6348932430b8 100644
> --- a/mm/zbud.c
> +++ b/mm/zbud.c
> @@ -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");
>   }
> 
>> 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
>> .
>>
>
Miaohe Lin June 18, 2021, 2:52 a.m. UTC | #4
On 2021/6/18 10:42, Nathan Chancellor wrote:
> On 6/17/2021 7:28 PM, Miaohe Lin wrote:
>> Hi:
>> On 2021/6/18 8:44, Nathan Chancellor wrote:
>>> On Tue, Jun 08, 2021 at 07:45:15PM +0800, Miaohe Lin wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>>
>>
>> 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!

> 
> Cheers,
> Nathan
> 
>> diff --git a/mm/Kconfig b/mm/Kconfig
>> index 8f748010f7ea..5dc28e9205e0 100644
>> --- a/mm/Kconfig
>> +++ b/mm/Kconfig
>> @@ -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
>> diff --git a/mm/zbud.c b/mm/zbud.c
>> index 3f61304405cb..6348932430b8 100644
>> --- a/mm/zbud.c
>> +++ b/mm/zbud.c
>> @@ -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");
>>   }
>>
>>> 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
>>> .
>>>
>>
> 
> .
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index d8648ee43199..625d66d7aacc 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -20264,7 +20264,6 @@  M:	Seth Jennings <sjenning@redhat.com>
 M:	Dan Streetman <ddstreet@ieee.org>
 L:	linux-mm@kvack.org
 S:	Maintained
-F:	include/linux/zbud.h
 F:	mm/zbud.c
 
 ZD1211RW WIRELESS DRIVER
diff --git a/include/linux/zbud.h b/include/linux/zbud.h
deleted file mode 100644
index b1eaf6e31735..000000000000
--- a/include/linux/zbud.h
+++ /dev/null
@@ -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_ */
diff --git a/mm/zbud.c b/mm/zbud.c
index 78e80ca58869..3f61304405cb 100644
--- a/mm/zbud.c
+++ b/mm/zbud.c
@@ -51,7 +51,6 @@ 
 #include <linux/preempt.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <linux/zbud.h>
 #include <linux/zpool.h>
 
 /*****************
@@ -73,6 +72,12 @@ 
 #define ZHDR_SIZE_ALIGNED CHUNK_SIZE
 #define NCHUNKS		((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT)
 
+struct zbud_pool;
+
+struct zbud_ops {
+	int (*evict)(struct zbud_pool *pool, unsigned long handle);
+};
+
 /**
  * struct zbud_pool - stores metadata for each zbud pool
  * @lock:	protects all pool fields and first|last_chunk fields of any
@@ -128,104 +133,6 @@  struct zbud_header {
 	bool under_reclaim;
 };
 
-/*****************
- * 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)
-		return pool->zpool_ops->evict(pool->zpool, handle);
-	else
-		return -ENOENT;
-}
-
-static const struct zbud_ops zbud_zpool_ops = {
-	.evict =	zbud_zpool_evict
-};
-
-static void *zbud_zpool_create(const char *name, gfp_t gfp,
-			       const struct zpool_ops *zpool_ops,
-			       struct zpool *zpool)
-{
-	struct zbud_pool *pool;
-
-	pool = zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL);
-	if (pool) {
-		pool->zpool = zpool;
-		pool->zpool_ops = zpool_ops;
-	}
-	return pool;
-}
-
-static void zbud_zpool_destroy(void *pool)
-{
-	zbud_destroy_pool(pool);
-}
-
-static int zbud_zpool_malloc(void *pool, size_t size, gfp_t gfp,
-			unsigned long *handle)
-{
-	return zbud_alloc(pool, size, gfp, handle);
-}
-static void zbud_zpool_free(void *pool, unsigned long handle)
-{
-	zbud_free(pool, handle);
-}
-
-static int zbud_zpool_shrink(void *pool, unsigned int pages,
-			unsigned int *reclaimed)
-{
-	unsigned int total = 0;
-	int ret = -EINVAL;
-
-	while (total < pages) {
-		ret = zbud_reclaim_page(pool, 8);
-		if (ret < 0)
-			break;
-		total++;
-	}
-
-	if (reclaimed)
-		*reclaimed = total;
-
-	return ret;
-}
-
-static void *zbud_zpool_map(void *pool, unsigned long handle,
-			enum zpool_mapmode mm)
-{
-	return zbud_map(pool, handle);
-}
-static void zbud_zpool_unmap(void *pool, unsigned long handle)
-{
-	zbud_unmap(pool, handle);
-}
-
-static u64 zbud_zpool_total_size(void *pool)
-{
-	return zbud_get_pool_size(pool) * PAGE_SIZE;
-}
-
-static struct zpool_driver zbud_zpool_driver = {
-	.type =		"zbud",
-	.sleep_mapped = true,
-	.owner =	THIS_MODULE,
-	.create =	zbud_zpool_create,
-	.destroy =	zbud_zpool_destroy,
-	.malloc =	zbud_zpool_malloc,
-	.free =		zbud_zpool_free,
-	.shrink =	zbud_zpool_shrink,
-	.map =		zbud_zpool_map,
-	.unmap =	zbud_zpool_unmap,
-	.total_size =	zbud_zpool_total_size,
-};
-
-MODULE_ALIAS("zpool-zbud");
-#endif /* CONFIG_ZPOOL */
-
 /*****************
  * Helpers
 *****************/
@@ -312,7 +219,7 @@  static int num_free_chunks(struct zbud_header *zhdr)
  * Return: pointer to the new zbud pool or NULL if the metadata allocation
  * failed.
  */
-struct zbud_pool *zbud_create_pool(gfp_t gfp, const struct zbud_ops *ops)
+static struct zbud_pool *zbud_create_pool(gfp_t gfp, const struct zbud_ops *ops)
 {
 	struct zbud_pool *pool;
 	int i;
@@ -336,7 +243,7 @@  struct zbud_pool *zbud_create_pool(gfp_t gfp, const struct zbud_ops *ops)
  *
  * The pool should be emptied before this function is called.
  */
-void zbud_destroy_pool(struct zbud_pool *pool)
+static void zbud_destroy_pool(struct zbud_pool *pool)
 {
 	kfree(pool);
 }
@@ -360,7 +267,7 @@  void zbud_destroy_pool(struct zbud_pool *pool)
  * gfp arguments are invalid or -ENOMEM if the pool was unable to allocate
  * a new page.
  */
-int zbud_alloc(struct zbud_pool *pool, size_t size, gfp_t gfp,
+static int zbud_alloc(struct zbud_pool *pool, size_t size, gfp_t gfp,
 			unsigned long *handle)
 {
 	int chunks, i, freechunks;
@@ -435,7 +342,7 @@  int zbud_alloc(struct zbud_pool *pool, size_t size, gfp_t gfp,
  * only sets the first|last_chunks to 0.  The page is actually freed
  * once both buddies are evicted (see zbud_reclaim_page() below).
  */
-void zbud_free(struct zbud_pool *pool, unsigned long handle)
+static void zbud_free(struct zbud_pool *pool, unsigned long handle)
 {
 	struct zbud_header *zhdr;
 	int freechunks;
@@ -507,7 +414,7 @@  void zbud_free(struct zbud_pool *pool, unsigned long handle)
  * no pages to evict or an eviction handler is not registered, -EAGAIN if
  * the retry limit was hit.
  */
-int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries)
+static int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries)
 {
 	int i, ret, freechunks;
 	struct zbud_header *zhdr;
@@ -589,7 +496,7 @@  int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries)
  *
  * Returns: a pointer to the mapped allocation
  */
-void *zbud_map(struct zbud_pool *pool, unsigned long handle)
+static void *zbud_map(struct zbud_pool *pool, unsigned long handle)
 {
 	return (void *)(handle);
 }
@@ -599,7 +506,7 @@  void *zbud_map(struct zbud_pool *pool, unsigned long handle)
  * @pool:	pool in which the allocation resides
  * @handle:	handle associated with the allocation to be unmapped
  */
-void zbud_unmap(struct zbud_pool *pool, unsigned long handle)
+static void zbud_unmap(struct zbud_pool *pool, unsigned long handle)
 {
 }
 
@@ -610,11 +517,109 @@  void zbud_unmap(struct zbud_pool *pool, unsigned long handle)
  * Returns: size in pages of the given pool.  The pool lock need not be
  * taken to access pages_nr.
  */
-u64 zbud_get_pool_size(struct zbud_pool *pool)
+static u64 zbud_get_pool_size(struct zbud_pool *pool)
 {
 	return pool->pages_nr;
 }
 
+/*****************
+ * 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)
+		return pool->zpool_ops->evict(pool->zpool, handle);
+	else
+		return -ENOENT;
+}
+
+static const struct zbud_ops zbud_zpool_ops = {
+	.evict =	zbud_zpool_evict
+};
+
+static void *zbud_zpool_create(const char *name, gfp_t gfp,
+			       const struct zpool_ops *zpool_ops,
+			       struct zpool *zpool)
+{
+	struct zbud_pool *pool;
+
+	pool = zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL);
+	if (pool) {
+		pool->zpool = zpool;
+		pool->zpool_ops = zpool_ops;
+	}
+	return pool;
+}
+
+static void zbud_zpool_destroy(void *pool)
+{
+	zbud_destroy_pool(pool);
+}
+
+static int zbud_zpool_malloc(void *pool, size_t size, gfp_t gfp,
+			unsigned long *handle)
+{
+	return zbud_alloc(pool, size, gfp, handle);
+}
+static void zbud_zpool_free(void *pool, unsigned long handle)
+{
+	zbud_free(pool, handle);
+}
+
+static int zbud_zpool_shrink(void *pool, unsigned int pages,
+			unsigned int *reclaimed)
+{
+	unsigned int total = 0;
+	int ret = -EINVAL;
+
+	while (total < pages) {
+		ret = zbud_reclaim_page(pool, 8);
+		if (ret < 0)
+			break;
+		total++;
+	}
+
+	if (reclaimed)
+		*reclaimed = total;
+
+	return ret;
+}
+
+static void *zbud_zpool_map(void *pool, unsigned long handle,
+			enum zpool_mapmode mm)
+{
+	return zbud_map(pool, handle);
+}
+static void zbud_zpool_unmap(void *pool, unsigned long handle)
+{
+	zbud_unmap(pool, handle);
+}
+
+static u64 zbud_zpool_total_size(void *pool)
+{
+	return zbud_get_pool_size(pool) * PAGE_SIZE;
+}
+
+static struct zpool_driver zbud_zpool_driver = {
+	.type =		"zbud",
+	.sleep_mapped = true,
+	.owner =	THIS_MODULE,
+	.create =	zbud_zpool_create,
+	.destroy =	zbud_zpool_destroy,
+	.malloc =	zbud_zpool_malloc,
+	.free =		zbud_zpool_free,
+	.shrink =	zbud_zpool_shrink,
+	.map =		zbud_zpool_map,
+	.unmap =	zbud_zpool_unmap,
+	.total_size =	zbud_zpool_total_size,
+};
+
+MODULE_ALIAS("zpool-zbud");
+#endif /* CONFIG_ZPOOL */
+
 static int __init init_zbud(void)
 {
 	/* Make sure the zbud header will fit in one chunk */