zpool: add malloc_support_movable to zpool_driver
authorHui Zhu <teawaterz@linux.alibaba.com>
Mon, 23 Sep 2019 22:39:37 +0000 (15:39 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 Sep 2019 22:54:12 +0000 (15:54 -0700)
As a zpool_driver, zsmalloc can allocate movable memory because it support
migate pages.  But zbud and z3fold cannot allocate movable memory.

Add malloc_support_movable to zpool_driver.  If a zpool_driver support
allocate movable memory, set it to true.  And add
zpool_malloc_support_movable check malloc_support_movable to make sure if
a zpool support allocate movable memory.

Link: http://lkml.kernel.org/r/20190605100630.13293-1-teawaterz@linux.alibaba.com
Signed-off-by: Hui Zhu <teawaterz@linux.alibaba.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitalywool@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/zpool.h
mm/zpool.c
mm/zsmalloc.c

index 7238865e75b00115f710d7c0d17e6e452edb51b3..51bf43076165d76aa0f313a65d526e912a15963e 100644 (file)
@@ -46,6 +46,8 @@ const char *zpool_get_type(struct zpool *pool);
 
 void zpool_destroy_pool(struct zpool *pool);
 
+bool zpool_malloc_support_movable(struct zpool *pool);
+
 int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp,
                        unsigned long *handle);
 
@@ -90,6 +92,7 @@ struct zpool_driver {
                        struct zpool *zpool);
        void (*destroy)(void *pool);
 
+       bool malloc_support_movable;
        int (*malloc)(void *pool, size_t size, gfp_t gfp,
                                unsigned long *handle);
        void (*free)(void *pool, unsigned long handle);
index a2dd9107857d44bc2573bc6976df5f5afa0306ca..863669212070433f2a7d37f05e4cc66a54260fbc 100644 (file)
@@ -238,6 +238,22 @@ const char *zpool_get_type(struct zpool *zpool)
        return zpool->driver->type;
 }
 
+/**
+ * zpool_malloc_support_movable() - Check if the zpool support
+ * allocate movable memory
+ * @zpool:     The zpool to check
+ *
+ * This returns if the zpool support allocate movable memory.
+ *
+ * Implementations must guarantee this to be thread-safe.
+ *
+ * Returns: true if if the zpool support allocate movable memory, false if not
+ */
+bool zpool_malloc_support_movable(struct zpool *zpool)
+{
+       return zpool->driver->malloc_support_movable;
+}
+
 /**
  * zpool_malloc() - Allocate memory
  * @zpool:     The zpool to allocate from.
index e98bb6ab4f7e76c8b3f6d29c165b43fd6a6da964..646858efd4684b7cbf22fd01d2c58ab7c9b3cfc6 100644 (file)
@@ -443,15 +443,16 @@ static u64 zs_zpool_total_size(void *pool)
 }
 
 static struct zpool_driver zs_zpool_driver = {
-       .type =         "zsmalloc",
-       .owner =        THIS_MODULE,
-       .create =       zs_zpool_create,
-       .destroy =      zs_zpool_destroy,
-       .malloc =       zs_zpool_malloc,
-       .free =         zs_zpool_free,
-       .map =          zs_zpool_map,
-       .unmap =        zs_zpool_unmap,
-       .total_size =   zs_zpool_total_size,
+       .type =                   "zsmalloc",
+       .owner =                  THIS_MODULE,
+       .create =                 zs_zpool_create,
+       .destroy =                zs_zpool_destroy,
+       .malloc_support_movable = true,
+       .malloc =                 zs_zpool_malloc,
+       .free =                   zs_zpool_free,
+       .map =                    zs_zpool_map,
+       .unmap =                  zs_zpool_unmap,
+       .total_size =             zs_zpool_total_size,
 };
 
 MODULE_ALIAS("zpool-zsmalloc");