aboutsummaryrefslogtreecommitdiffstats
path: root/mm/zbud.c
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2014-08-06 19:08:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 21:01:23 -0400
commitc795779df29e180738568d2a5eb3a42f3b5e47f0 (patch)
tree920f3d48aa48b68801c0ce8dabb67b757850b58d /mm/zbud.c
parentaf8d417a04564bca0348e7e3c749ab12a3e837ad (diff)
mm/zpool: zbud/zsmalloc implement zpool
Update zbud and zsmalloc to implement the zpool api. [fengguang.wu@intel.com: make functions static] 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 'mm/zbud.c')
-rw-r--r--mm/zbud.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/mm/zbud.c b/mm/zbud.c
index d01226117b8d..a05790b1915e 100644
--- a/mm/zbud.c
+++ b/mm/zbud.c
@@ -51,6 +51,7 @@
51#include <linux/slab.h> 51#include <linux/slab.h>
52#include <linux/spinlock.h> 52#include <linux/spinlock.h>
53#include <linux/zbud.h> 53#include <linux/zbud.h>
54#include <linux/zpool.h>
54 55
55/***************** 56/*****************
56 * Structures 57 * Structures
@@ -113,6 +114,90 @@ struct zbud_header {
113}; 114};
114 115
115/***************** 116/*****************
117 * zpool
118 ****************/
119
120#ifdef CONFIG_ZPOOL
121
122static int zbud_zpool_evict(struct zbud_pool *pool, unsigned long handle)
123{
124 return zpool_evict(pool, handle);
125}
126
127static struct zbud_ops zbud_zpool_ops = {
128 .evict = zbud_zpool_evict
129};
130
131static void *zbud_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops)
132{
133 return zbud_create_pool(gfp, &zbud_zpool_ops);
134}
135
136static void zbud_zpool_destroy(void *pool)
137{
138 zbud_destroy_pool(pool);
139}
140
141static int zbud_zpool_malloc(void *pool, size_t size, gfp_t gfp,
142 unsigned long *handle)
143{
144 return zbud_alloc(pool, size, gfp, handle);
145}
146static void zbud_zpool_free(void *pool, unsigned long handle)
147{
148 zbud_free(pool, handle);
149}
150
151static int zbud_zpool_shrink(void *pool, unsigned int pages,
152 unsigned int *reclaimed)
153{
154 unsigned int total = 0;
155 int ret = -EINVAL;
156
157 while (total < pages) {
158 ret = zbud_reclaim_page(pool, 8);
159 if (ret < 0)
160 break;
161 total++;
162 }
163
164 if (reclaimed)
165 *reclaimed = total;
166
167 return ret;
168}
169
170static void *zbud_zpool_map(void *pool, unsigned long handle,
171 enum zpool_mapmode mm)
172{
173 return zbud_map(pool, handle);
174}
175static void zbud_zpool_unmap(void *pool, unsigned long handle)
176{
177 zbud_unmap(pool, handle);
178}
179
180static u64 zbud_zpool_total_size(void *pool)
181{
182 return zbud_get_pool_size(pool) * PAGE_SIZE;
183}
184
185static struct zpool_driver zbud_zpool_driver = {
186 .type = "zbud",
187 .owner = THIS_MODULE,
188 .create = zbud_zpool_create,
189 .destroy = zbud_zpool_destroy,
190 .malloc = zbud_zpool_malloc,
191 .free = zbud_zpool_free,
192 .shrink = zbud_zpool_shrink,
193 .map = zbud_zpool_map,
194 .unmap = zbud_zpool_unmap,
195 .total_size = zbud_zpool_total_size,
196};
197
198#endif /* CONFIG_ZPOOL */
199
200/*****************
116 * Helpers 201 * Helpers
117*****************/ 202*****************/
118/* Just to make the code easier to read */ 203/* Just to make the code easier to read */
@@ -511,11 +596,20 @@ static int __init init_zbud(void)
511 /* Make sure the zbud header will fit in one chunk */ 596 /* Make sure the zbud header will fit in one chunk */
512 BUILD_BUG_ON(sizeof(struct zbud_header) > ZHDR_SIZE_ALIGNED); 597 BUILD_BUG_ON(sizeof(struct zbud_header) > ZHDR_SIZE_ALIGNED);
513 pr_info("loaded\n"); 598 pr_info("loaded\n");
599
600#ifdef CONFIG_ZPOOL
601 zpool_register_driver(&zbud_zpool_driver);
602#endif
603
514 return 0; 604 return 0;
515} 605}
516 606
517static void __exit exit_zbud(void) 607static void __exit exit_zbud(void)
518{ 608{
609#ifdef CONFIG_ZPOOL
610 zpool_unregister_driver(&zbud_zpool_driver);
611#endif
612
519 pr_info("unloaded\n"); 613 pr_info("unloaded\n");
520} 614}
521 615