diff options
| author | Dan Streetman <ddstreet@ieee.org> | 2014-08-06 19:08:36 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 21:01:23 -0400 |
| commit | af8d417a04564bca0348e7e3c749ab12a3e837ad (patch) | |
| tree | ce222a9643ba4a0afa675ed1f2d1b1447ec5174b /include/linux | |
| parent | 99eef8e9369abe009006b4fa7f6ca5086c09cf46 (diff) | |
mm/zpool: implement common zpool api to zbud/zsmalloc
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 <ddstreet@ieee.org>
Tested-by: Seth Jennings <sjennings@variantweb.net>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Weijie Yang <weijie.yang@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/zpool.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/include/linux/zpool.h b/include/linux/zpool.h new file mode 100644 index 000000000000..f14bd75f08b3 --- /dev/null +++ b/include/linux/zpool.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* | ||
| 2 | * zpool memory storage api | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Dan Streetman | ||
| 5 | * | ||
| 6 | * This is a common frontend for the zbud and zsmalloc memory | ||
| 7 | * storage pool implementations. Typically, this is used to | ||
| 8 | * store compressed memory. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef _ZPOOL_H_ | ||
| 12 | #define _ZPOOL_H_ | ||
| 13 | |||
| 14 | struct zpool; | ||
| 15 | |||
| 16 | struct zpool_ops { | ||
| 17 | int (*evict)(struct zpool *pool, unsigned long handle); | ||
| 18 | }; | ||
| 19 | |||
| 20 | /* | ||
| 21 | * Control how a handle is mapped. It will be ignored if the | ||
| 22 | * implementation does not support it. Its use is optional. | ||
| 23 | * Note that this does not refer to memory protection, it | ||
| 24 | * refers to how the memory will be copied in/out if copying | ||
| 25 | * is necessary during mapping; read-write is the safest as | ||
| 26 | * it copies the existing memory in on map, and copies the | ||
| 27 | * changed memory back out on unmap. Write-only does not copy | ||
| 28 | * in the memory and should only be used for initialization. | ||
| 29 | * If in doubt, use ZPOOL_MM_DEFAULT which is read-write. | ||
| 30 | */ | ||
| 31 | enum zpool_mapmode { | ||
| 32 | ZPOOL_MM_RW, /* normal read-write mapping */ | ||
| 33 | ZPOOL_MM_RO, /* read-only (no copy-out at unmap time) */ | ||
| 34 | ZPOOL_MM_WO, /* write-only (no copy-in at map time) */ | ||
| 35 | |||
| 36 | ZPOOL_MM_DEFAULT = ZPOOL_MM_RW | ||
| 37 | }; | ||
| 38 | |||
| 39 | struct zpool *zpool_create_pool(char *type, gfp_t gfp, struct zpool_ops *ops); | ||
| 40 | |||
| 41 | char *zpool_get_type(struct zpool *pool); | ||
| 42 | |||
| 43 | void zpool_destroy_pool(struct zpool *pool); | ||
| 44 | |||
| 45 | int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp, | ||
| 46 | unsigned long *handle); | ||
| 47 | |||
| 48 | void zpool_free(struct zpool *pool, unsigned long handle); | ||
| 49 | |||
| 50 | int zpool_shrink(struct zpool *pool, unsigned int pages, | ||
| 51 | unsigned int *reclaimed); | ||
| 52 | |||
| 53 | void *zpool_map_handle(struct zpool *pool, unsigned long handle, | ||
| 54 | enum zpool_mapmode mm); | ||
| 55 | |||
| 56 | void zpool_unmap_handle(struct zpool *pool, unsigned long handle); | ||
| 57 | |||
| 58 | u64 zpool_get_total_size(struct zpool *pool); | ||
| 59 | |||
| 60 | |||
| 61 | /** | ||
| 62 | * struct zpool_driver - driver implementation for zpool | ||
| 63 | * @type: name of the driver. | ||
| 64 | * @list: entry in the list of zpool drivers. | ||
| 65 | * @create: create a new pool. | ||
| 66 | * @destroy: destroy a pool. | ||
| 67 | * @malloc: allocate mem from a pool. | ||
| 68 | * @free: free mem from a pool. | ||
| 69 | * @shrink: shrink the pool. | ||
| 70 | * @map: map a handle. | ||
| 71 | * @unmap: unmap a handle. | ||
| 72 | * @total_size: get total size of a pool. | ||
| 73 | * | ||
| 74 | * This is created by a zpool implementation and registered | ||
| 75 | * with zpool. | ||
| 76 | */ | ||
| 77 | struct zpool_driver { | ||
| 78 | char *type; | ||
| 79 | struct module *owner; | ||
| 80 | atomic_t refcount; | ||
| 81 | struct list_head list; | ||
| 82 | |||
| 83 | void *(*create)(gfp_t gfp, struct zpool_ops *ops); | ||
| 84 | void (*destroy)(void *pool); | ||
| 85 | |||
| 86 | int (*malloc)(void *pool, size_t size, gfp_t gfp, | ||
| 87 | unsigned long *handle); | ||
| 88 | void (*free)(void *pool, unsigned long handle); | ||
| 89 | |||
| 90 | int (*shrink)(void *pool, unsigned int pages, | ||
| 91 | unsigned int *reclaimed); | ||
| 92 | |||
| 93 | void *(*map)(void *pool, unsigned long handle, | ||
| 94 | enum zpool_mapmode mm); | ||
| 95 | void (*unmap)(void *pool, unsigned long handle); | ||
| 96 | |||
| 97 | u64 (*total_size)(void *pool); | ||
| 98 | }; | ||
| 99 | |||
| 100 | void zpool_register_driver(struct zpool_driver *driver); | ||
| 101 | |||
| 102 | int zpool_unregister_driver(struct zpool_driver *driver); | ||
| 103 | |||
| 104 | int zpool_evict(void *pool, unsigned long handle); | ||
| 105 | |||
| 106 | #endif | ||
