Skip to content

Commit

Permalink
zpool: add malloc_support_movable to zpool_driver
Browse files Browse the repository at this point in the history
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/[email protected]
Signed-off-by: Hui Zhu <[email protected]>
Reviewed-by: Shakeel Butt <[email protected]>
Cc: Dan Streetman <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Nitin Gupta <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Seth Jennings <[email protected]>
Cc: Vitaly Wool <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
teawater authored and torvalds committed Sep 24, 2019
1 parent 28eb3c8 commit c165f25
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions include/linux/zpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions mm/zpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 10 additions & 9 deletions mm/zsmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit c165f25

Please sign in to comment.