Skip to content

Commit

Permalink
mm/zpool: implement common zpool api to zbud/zsmalloc
Browse files Browse the repository at this point in the history
Add zpool api.

zpool provides an interface for memory storage, typically of compressed
memory.  Users can select what backend to use; currently the only
implementations are zbud, a low density implementation with up to two
compressed pages per storage page, and zsmalloc, a higher density
implementation with multiple compressed pages per storage page.

Signed-off-by: Dan Streetman <[email protected]>
Tested-by: Seth Jennings <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Nitin Gupta <[email protected]>
Cc: Weijie Yang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ddstreet authored and torvalds committed Aug 7, 2014
1 parent 99eef8e commit af8d417
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 18 deletions.
106 changes: 106 additions & 0 deletions include/linux/zpool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* zpool memory storage api
*
* Copyright (C) 2014 Dan Streetman
*
* This is a common frontend for the zbud and zsmalloc memory
* storage pool implementations. Typically, this is used to
* store compressed memory.
*/

#ifndef _ZPOOL_H_
#define _ZPOOL_H_

struct zpool;

struct zpool_ops {
int (*evict)(struct zpool *pool, unsigned long handle);
};

/*
* Control how a handle is mapped. It will be ignored if the
* implementation does not support it. Its use is optional.
* Note that this does not refer to memory protection, it
* refers to how the memory will be copied in/out if copying
* is necessary during mapping; read-write is the safest as
* it copies the existing memory in on map, and copies the
* changed memory back out on unmap. Write-only does not copy
* in the memory and should only be used for initialization.
* If in doubt, use ZPOOL_MM_DEFAULT which is read-write.
*/
enum zpool_mapmode {
ZPOOL_MM_RW, /* normal read-write mapping */
ZPOOL_MM_RO, /* read-only (no copy-out at unmap time) */
ZPOOL_MM_WO, /* write-only (no copy-in at map time) */

ZPOOL_MM_DEFAULT = ZPOOL_MM_RW
};

struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops);

char *zpool_get_type(struct zpool *pool);

void zpool_destroy_pool(struct zpool *pool);

int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp,
unsigned long *handle);

void zpool_free(struct zpool *pool, unsigned long handle);

int zpool_shrink(struct zpool *pool, unsigned int pages,
unsigned int *reclaimed);

void *zpool_map_handle(struct zpool *pool, unsigned long handle,
enum zpool_mapmode mm);

void zpool_unmap_handle(struct zpool *pool, unsigned long handle);

u64 zpool_get_total_size(struct zpool *pool);


/**
* struct zpool_driver - driver implementation for zpool
* @type: name of the driver.
* @list: entry in the list of zpool drivers.
* @create: create a new pool.
* @destroy: destroy a pool.
* @malloc: allocate mem from a pool.
* @free: free mem from a pool.
* @shrink: shrink the pool.
* @map: map a handle.
* @unmap: unmap a handle.
* @total_size: get total size of a pool.
*
* This is created by a zpool implementation and registered
* with zpool.
*/
struct zpool_driver {
char *type;
struct module *owner;
atomic_t refcount;
struct list_head list;

void *(*create)(gfp_t gfp, struct zpool_ops *ops);
void (*destroy)(void *pool);

int (*malloc)(void *pool, size_t size, gfp_t gfp,
unsigned long *handle);
void (*free)(void *pool, unsigned long handle);

int (*shrink)(void *pool, unsigned int pages,
unsigned int *reclaimed);

void *(*map)(void *pool, unsigned long handle,
enum zpool_mapmode mm);
void (*unmap)(void *pool, unsigned long handle);

u64 (*total_size)(void *pool);
};

void zpool_register_driver(struct zpool_driver *driver);

int zpool_unregister_driver(struct zpool_driver *driver);

int zpool_evict(void *pool, unsigned long handle);

#endif
41 changes: 24 additions & 17 deletions mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,17 @@ config CMA_AREAS

If unsure, leave the default value "7".

config ZBUD
tristate
default n
config MEM_SOFT_DIRTY
bool "Track memory changes"
depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY && PROC_FS
select PROC_PAGE_MONITOR
help
A special purpose allocator for storing compressed pages.
It is designed to store up to two compressed pages per physical
page. While this design limits storage density, it has simple and
deterministic reclaim properties that make it preferable to a higher
density approach when reclaim will be used.
This option enables memory changes tracking by introducing a
soft-dirty bit on pte-s. This bit it set when someone writes
into a page just as regular dirty bit, but unlike the latter
it can be cleared by hands.

See Documentation/vm/soft-dirty.txt for more details.

config ZSWAP
bool "Compressed cache for swap pages (EXPERIMENTAL)"
Expand All @@ -549,17 +551,22 @@ config ZSWAP
they have not be fully explored on the large set of potential
configurations and workloads that exist.

config MEM_SOFT_DIRTY
bool "Track memory changes"
depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY && PROC_FS
select PROC_PAGE_MONITOR
config ZPOOL
tristate "Common API for compressed memory storage"
default n
help
This option enables memory changes tracking by introducing a
soft-dirty bit on pte-s. This bit it set when someone writes
into a page just as regular dirty bit, but unlike the latter
it can be cleared by hands.
Compressed memory storage API. This allows using either zbud or
zsmalloc.

See Documentation/vm/soft-dirty.txt for more details.
config ZBUD
tristate "Low density storage for compressed pages"
default n
help
A special purpose allocator for storing compressed pages.
It is designed to store up to two compressed pages per physical
page. While this design limits storage density, it has simple and
deterministic reclaim properties that make it preferable to a higher
density approach when reclaim will be used.

config ZSMALLOC
tristate "Memory allocator for compressed pages"
Expand Down
1 change: 1 addition & 0 deletions mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
obj-$(CONFIG_CLEANCACHE) += cleancache.o
obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
obj-$(CONFIG_ZPOOL) += zpool.o
obj-$(CONFIG_ZBUD) += zbud.o
obj-$(CONFIG_ZSMALLOC) += zsmalloc.o
obj-$(CONFIG_GENERIC_EARLY_IOREMAP) += early_ioremap.o
Expand Down
Loading

0 comments on commit af8d417

Please sign in to comment.