blob: d30eff3d84d54282656e687313ca6db4ef8c8d90 [file] [log] [blame]
Dan Streetmanaf8d4172014-08-06 16:08:36 -07001/*
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
14struct zpool;
15
16struct 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 */
31enum 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
Ganesh Mahendran3eba0c62015-02-12 15:00:51 -080039struct zpool *zpool_create_pool(char *type, char *name,
40 gfp_t gfp, struct zpool_ops *ops);
Dan Streetmanaf8d4172014-08-06 16:08:36 -070041
42char *zpool_get_type(struct zpool *pool);
43
44void zpool_destroy_pool(struct zpool *pool);
45
46int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp,
47 unsigned long *handle);
48
49void zpool_free(struct zpool *pool, unsigned long handle);
50
51int zpool_shrink(struct zpool *pool, unsigned int pages,
52 unsigned int *reclaimed);
53
54void *zpool_map_handle(struct zpool *pool, unsigned long handle,
55 enum zpool_mapmode mm);
56
57void zpool_unmap_handle(struct zpool *pool, unsigned long handle);
58
59u64 zpool_get_total_size(struct zpool *pool);
60
61
62/**
63 * struct zpool_driver - driver implementation for zpool
64 * @type: name of the driver.
65 * @list: entry in the list of zpool drivers.
66 * @create: create a new pool.
67 * @destroy: destroy a pool.
68 * @malloc: allocate mem from a pool.
69 * @free: free mem from a pool.
70 * @shrink: shrink the pool.
71 * @map: map a handle.
72 * @unmap: unmap a handle.
73 * @total_size: get total size of a pool.
74 *
75 * This is created by a zpool implementation and registered
76 * with zpool.
77 */
78struct zpool_driver {
79 char *type;
80 struct module *owner;
81 atomic_t refcount;
82 struct list_head list;
83
Dan Streetman479305f2015-06-25 15:00:40 -070084 void *(*create)(char *name, gfp_t gfp, struct zpool_ops *ops,
85 struct zpool *zpool);
Dan Streetmanaf8d4172014-08-06 16:08:36 -070086 void (*destroy)(void *pool);
87
88 int (*malloc)(void *pool, size_t size, gfp_t gfp,
89 unsigned long *handle);
90 void (*free)(void *pool, unsigned long handle);
91
92 int (*shrink)(void *pool, unsigned int pages,
93 unsigned int *reclaimed);
94
95 void *(*map)(void *pool, unsigned long handle,
96 enum zpool_mapmode mm);
97 void (*unmap)(void *pool, unsigned long handle);
98
99 u64 (*total_size)(void *pool);
100};
101
102void zpool_register_driver(struct zpool_driver *driver);
103
104int zpool_unregister_driver(struct zpool_driver *driver);
105
Dan Streetmanaf8d4172014-08-06 16:08:36 -0700106#endif