OSDN Git Service

f2fs: Revert rapid GC
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / zpool.h
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 bool zpool_has_pool(char *type);
40
41 struct zpool *zpool_create_pool(const char *type, const char *name,
42                         gfp_t gfp, const struct zpool_ops *ops);
43
44 const char *zpool_get_type(struct zpool *pool);
45
46 void zpool_destroy_pool(struct zpool *pool);
47
48 int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp,
49                         unsigned long *handle);
50
51 void zpool_free(struct zpool *pool, unsigned long handle);
52
53 int zpool_shrink(struct zpool *pool, unsigned int pages,
54                         unsigned int *reclaimed);
55
56 void *zpool_map_handle(struct zpool *pool, unsigned long handle,
57                         enum zpool_mapmode mm);
58
59 void zpool_unmap_handle(struct zpool *pool, unsigned long handle);
60
61 u64 zpool_get_total_size(struct zpool *pool);
62
63 unsigned long zpool_compact(struct zpool *pool);
64
65 unsigned long zpool_get_num_compacted(struct zpool *pool);
66
67 /**
68  * struct zpool_driver - driver implementation for zpool
69  * @type:       name of the driver.
70  * @list:       entry in the list of zpool drivers.
71  * @create:     create a new pool.
72  * @destroy:    destroy a pool.
73  * @malloc:     allocate mem from a pool.
74  * @free:       free mem from a pool.
75  * @shrink:     shrink the pool.
76  * @map:        map a handle.
77  * @unmap:      unmap a handle.
78  * @total_size: get total size of a pool.
79  *
80  * This is created by a zpool implementation and registered
81  * with zpool.
82  */
83 struct zpool_driver {
84         char *type;
85         struct module *owner;
86         atomic_t refcount;
87         struct list_head list;
88
89         void *(*create)(const char *name,
90                         gfp_t gfp,
91                         const struct zpool_ops *ops,
92                         struct zpool *zpool);
93         void (*destroy)(void *pool);
94
95         int (*malloc)(void *pool, size_t size, gfp_t gfp,
96                                 unsigned long *handle);
97         void (*free)(void *pool, unsigned long handle);
98
99         int (*shrink)(void *pool, unsigned int pages,
100                                 unsigned int *reclaimed);
101
102         void *(*map)(void *pool, unsigned long handle,
103                                 enum zpool_mapmode mm);
104         void (*unmap)(void *pool, unsigned long handle);
105
106         u64 (*total_size)(void *pool);
107
108         unsigned long (*compact)(void *pool);
109
110         unsigned long (*get_num_compacted)(void *pool);
111 };
112
113 void zpool_register_driver(struct zpool_driver *driver);
114
115 int zpool_unregister_driver(struct zpool_driver *driver);
116
117 #endif