blob: 261be4654848a0a355d0843e5dc6a651e9608c4e [file] [log] [blame]
Nitin Gupta61989a82012-01-09 16:51:56 -06001/*
2 * zsmalloc memory allocator
3 *
4 * Copyright (C) 2011 Nitin Gupta
Minchan Kim00cfab32014-01-30 15:45:55 -08005 * Copyright (C) 2012, 2013 Minchan Kim
Nitin Gupta61989a82012-01-09 16:51:56 -06006 *
7 * This code is released using a dual license strategy: BSD/GPL
8 * You can choose the license that better fits your requirements.
9 *
10 * Released under the terms of 3-clause BSD License
11 * Released under the terms of GNU General Public License Version 2.0
12 */
13
Nitin Gupta2db51da2012-06-09 17:41:14 -070014
15/*
16 * This allocator is designed for use with zcache and zram. Thus, the
17 * allocator is supposed to work well under low memory conditions. In
18 * particular, it never attempts higher order page allocation which is
19 * very likely to fail under memory pressure. On the other hand, if we
20 * just use single (0-order) pages, it would suffer from very high
21 * fragmentation -- any object of size PAGE_SIZE/2 or larger would occupy
22 * an entire page. This was one of the major issues with its predecessor
23 * (xvmalloc).
24 *
25 * To overcome these issues, zsmalloc allocates a bunch of 0-order pages
26 * and links them together using various 'struct page' fields. These linked
27 * pages act as a single higher-order page i.e. an object can span 0-order
28 * page boundaries. The code refers to these linked pages as a single entity
29 * called zspage.
30 *
31 * Following is how we use various fields and flags of underlying
32 * struct page(s) to form a zspage.
33 *
34 * Usage of struct page fields:
35 * page->first_page: points to the first component (0-order) page
36 * page->index (union with page->freelist): offset of the first object
37 * starting in this page. For the first page, this is
38 * always 0, so we use this field (aka freelist) to point
39 * to the first free object in zspage.
40 * page->lru: links together all component pages (except the first page)
41 * of a zspage
42 *
43 * For _first_ page only:
44 *
45 * page->private (union with page->first_page): refers to the
46 * component page after the first page
47 * page->freelist: points to the first free object in zspage.
48 * Free objects are linked together using in-place
49 * metadata.
50 * page->objects: maximum number of objects we can store in this
51 * zspage (class->zspage_order * PAGE_SIZE / class->size)
52 * page->lru: links together first pages of various zspages.
53 * Basically forming list of zspages in a fullness group.
54 * page->mapping: class index and fullness group of the zspage
55 *
56 * Usage of struct page flags:
57 * PG_private: identifies the first component page
58 * PG_private2: identifies the last component page
59 *
60 */
61
Nitin Gupta61989a82012-01-09 16:51:56 -060062#ifdef CONFIG_ZSMALLOC_DEBUG
63#define DEBUG
64#endif
65
66#include <linux/module.h>
67#include <linux/kernel.h>
68#include <linux/bitops.h>
69#include <linux/errno.h>
70#include <linux/highmem.h>
71#include <linux/init.h>
72#include <linux/string.h>
73#include <linux/slab.h>
74#include <asm/tlbflush.h>
75#include <asm/pgtable.h>
76#include <linux/cpumask.h>
77#include <linux/cpu.h>
Seth Jennings0cbb6132012-02-13 08:47:49 -060078#include <linux/vmalloc.h>
Seth Jenningsc60369f2012-07-18 11:55:55 -050079#include <linux/hardirq.h>
Seth Jennings0959c632012-08-08 15:12:17 +090080#include <linux/spinlock.h>
81#include <linux/types.h>
Minchan Kim03dc2ac2014-01-30 15:45:50 -080082#include <linux/zsmalloc.h>
Dan Streetman7b5c9b22014-08-06 16:08:38 -070083#include <linux/zpool.h>
Seth Jennings0959c632012-08-08 15:12:17 +090084
85/*
86 * This must be power of 2 and greater than of equal to sizeof(link_free).
87 * These two conditions ensure that any 'struct link_free' itself doesn't
88 * span more than 1 page which avoids complex case of mapping 2 pages simply
89 * to restore link_free pointer values.
90 */
91#define ZS_ALIGN 8
92
93/*
94 * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single)
95 * pages. ZS_MAX_ZSPAGE_ORDER defines upper limit on N.
96 */
97#define ZS_MAX_ZSPAGE_ORDER 2
98#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
99
100/*
101 * Object location (<PFN>, <obj_idx>) is encoded as
102 * as single (void *) handle value.
103 *
104 * Note that object index <obj_idx> is relative to system
105 * page <PFN> it is stored in, so for each sub-page belonging
106 * to a zspage, obj_idx starts with 0.
107 *
108 * This is made more complicated by various memory models and PAE.
109 */
110
111#ifndef MAX_PHYSMEM_BITS
112#ifdef CONFIG_HIGHMEM64G
113#define MAX_PHYSMEM_BITS 36
114#else /* !CONFIG_HIGHMEM64G */
115/*
116 * If this definition of MAX_PHYSMEM_BITS is used, OBJ_INDEX_BITS will just
117 * be PAGE_SHIFT
118 */
119#define MAX_PHYSMEM_BITS BITS_PER_LONG
120#endif
121#endif
122#define _PFN_BITS (MAX_PHYSMEM_BITS - PAGE_SHIFT)
123#define OBJ_INDEX_BITS (BITS_PER_LONG - _PFN_BITS)
124#define OBJ_INDEX_MASK ((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
125
126#define MAX(a, b) ((a) >= (b) ? (a) : (b))
127/* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */
128#define ZS_MIN_ALLOC_SIZE \
129 MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))
130#define ZS_MAX_ALLOC_SIZE PAGE_SIZE
131
132/*
Weijie Yangc398e6a2014-06-04 16:11:08 -0700133 * On systems with 4K page size, this gives 255 size classes! There is a
Seth Jennings0959c632012-08-08 15:12:17 +0900134 * trader-off here:
135 * - Large number of size classes is potentially wasteful as free page are
136 * spread across these classes
137 * - Small number of size classes causes large internal fragmentation
138 * - Probably its better to use specific size classes (empirically
139 * determined). NOTE: all those class sizes must be set as multiple of
140 * ZS_ALIGN to make sure link_free itself never has to span 2 pages.
141 *
142 * ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN
143 * (reason above)
144 */
Seth Jenningsd662b8e2013-01-25 11:46:18 -0600145#define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8)
Seth Jennings0959c632012-08-08 15:12:17 +0900146#define ZS_SIZE_CLASSES ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / \
147 ZS_SIZE_CLASS_DELTA + 1)
148
149/*
150 * We do not maintain any list for completely empty or full pages
151 */
152enum fullness_group {
153 ZS_ALMOST_FULL,
154 ZS_ALMOST_EMPTY,
155 _ZS_NR_FULLNESS_GROUPS,
156
157 ZS_EMPTY,
158 ZS_FULL
159};
160
161/*
162 * We assign a page to ZS_ALMOST_EMPTY fullness group when:
163 * n <= N / f, where
164 * n = number of allocated objects
165 * N = total number of objects zspage can store
166 * f = 1/fullness_threshold_frac
167 *
168 * Similarly, we assign zspage to:
169 * ZS_ALMOST_FULL when n > N / f
170 * ZS_EMPTY when n == 0
171 * ZS_FULL when n == N
172 *
173 * (see: fix_fullness_group())
174 */
175static const int fullness_threshold_frac = 4;
176
177struct size_class {
178 /*
179 * Size of objects stored in this class. Must be multiple
180 * of ZS_ALIGN.
181 */
182 int size;
183 unsigned int index;
184
185 /* Number of PAGE_SIZE sized pages to combine to form a 'zspage' */
186 int pages_per_zspage;
187
188 spinlock_t lock;
189
Seth Jennings0959c632012-08-08 15:12:17 +0900190 struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS];
191};
192
193/*
194 * Placed within free objects to form a singly linked list.
195 * For every zspage, first_page->freelist gives head of this list.
196 *
197 * This must be power of 2 and less than or equal to ZS_ALIGN
198 */
199struct link_free {
200 /* Handle of next free chunk (encodes <PFN, obj_idx>) */
201 void *next;
202};
203
204struct zs_pool {
205 struct size_class size_class[ZS_SIZE_CLASSES];
206
207 gfp_t flags; /* allocation flags used when growing pool */
Minchan Kim8ccca722014-10-09 15:29:48 -0700208 atomic_long_t pages_allocated;
Seth Jennings0959c632012-08-08 15:12:17 +0900209};
Nitin Gupta61989a82012-01-09 16:51:56 -0600210
211/*
212 * A zspage's class index and fullness group
213 * are encoded in its (first)page->mapping
214 */
215#define CLASS_IDX_BITS 28
216#define FULLNESS_BITS 4
217#define CLASS_IDX_MASK ((1 << CLASS_IDX_BITS) - 1)
218#define FULLNESS_MASK ((1 << FULLNESS_BITS) - 1)
219
Seth Jenningsf5536462012-07-18 11:55:56 -0500220/*
221 * By default, zsmalloc uses a copy-based object mapping method to access
222 * allocations that span two pages. However, if a particular architecture
Minchan Kim99155182013-01-28 10:00:08 +0900223 * performs VM mapping faster than copying, then it should be added here
224 * so that USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use
225 * page table mapping rather than copying for object mapping.
Seth Jenningsf5536462012-07-18 11:55:56 -0500226*/
Arnd Bergmann796ce5a2013-04-23 18:30:48 +0200227#if defined(CONFIG_ARM) && !defined(MODULE)
Seth Jenningsf5536462012-07-18 11:55:56 -0500228#define USE_PGTABLE_MAPPING
229#endif
230
231struct mapping_area {
232#ifdef USE_PGTABLE_MAPPING
233 struct vm_struct *vm; /* vm area for mapping object that span pages */
234#else
235 char *vm_buf; /* copy buffer for objects that span pages */
236#endif
237 char *vm_addr; /* address of kmap_atomic()'ed pages */
238 enum zs_mapmode vm_mm; /* mapping mode */
239};
240
Dan Streetman7b5c9b22014-08-06 16:08:38 -0700241/* zpool driver */
242
243#ifdef CONFIG_ZPOOL
244
245static void *zs_zpool_create(gfp_t gfp, struct zpool_ops *zpool_ops)
246{
247 return zs_create_pool(gfp);
248}
249
250static void zs_zpool_destroy(void *pool)
251{
252 zs_destroy_pool(pool);
253}
254
255static int zs_zpool_malloc(void *pool, size_t size, gfp_t gfp,
256 unsigned long *handle)
257{
258 *handle = zs_malloc(pool, size);
259 return *handle ? 0 : -1;
260}
261static void zs_zpool_free(void *pool, unsigned long handle)
262{
263 zs_free(pool, handle);
264}
265
266static int zs_zpool_shrink(void *pool, unsigned int pages,
267 unsigned int *reclaimed)
268{
269 return -EINVAL;
270}
271
272static void *zs_zpool_map(void *pool, unsigned long handle,
273 enum zpool_mapmode mm)
274{
275 enum zs_mapmode zs_mm;
276
277 switch (mm) {
278 case ZPOOL_MM_RO:
279 zs_mm = ZS_MM_RO;
280 break;
281 case ZPOOL_MM_WO:
282 zs_mm = ZS_MM_WO;
283 break;
284 case ZPOOL_MM_RW: /* fallthru */
285 default:
286 zs_mm = ZS_MM_RW;
287 break;
288 }
289
290 return zs_map_object(pool, handle, zs_mm);
291}
292static void zs_zpool_unmap(void *pool, unsigned long handle)
293{
294 zs_unmap_object(pool, handle);
295}
296
297static u64 zs_zpool_total_size(void *pool)
298{
299 return zs_get_total_size_bytes(pool);
300}
301
302static struct zpool_driver zs_zpool_driver = {
303 .type = "zsmalloc",
304 .owner = THIS_MODULE,
305 .create = zs_zpool_create,
306 .destroy = zs_zpool_destroy,
307 .malloc = zs_zpool_malloc,
308 .free = zs_zpool_free,
309 .shrink = zs_zpool_shrink,
310 .map = zs_zpool_map,
311 .unmap = zs_zpool_unmap,
312 .total_size = zs_zpool_total_size,
313};
314
Kees Cook60fafac2014-08-29 15:18:40 -0700315MODULE_ALIAS("zpool-zsmalloc");
Dan Streetman7b5c9b22014-08-06 16:08:38 -0700316#endif /* CONFIG_ZPOOL */
317
Nitin Gupta61989a82012-01-09 16:51:56 -0600318/* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
319static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
320
321static int is_first_page(struct page *page)
322{
Minchan Kima27545bf2012-04-25 15:23:09 +0900323 return PagePrivate(page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600324}
325
326static int is_last_page(struct page *page)
327{
Minchan Kima27545bf2012-04-25 15:23:09 +0900328 return PagePrivate2(page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600329}
330
331static void get_zspage_mapping(struct page *page, unsigned int *class_idx,
332 enum fullness_group *fullness)
333{
334 unsigned long m;
335 BUG_ON(!is_first_page(page));
336
337 m = (unsigned long)page->mapping;
338 *fullness = m & FULLNESS_MASK;
339 *class_idx = (m >> FULLNESS_BITS) & CLASS_IDX_MASK;
340}
341
342static void set_zspage_mapping(struct page *page, unsigned int class_idx,
343 enum fullness_group fullness)
344{
345 unsigned long m;
346 BUG_ON(!is_first_page(page));
347
348 m = ((class_idx & CLASS_IDX_MASK) << FULLNESS_BITS) |
349 (fullness & FULLNESS_MASK);
350 page->mapping = (struct address_space *)m;
351}
352
353static int get_size_class_index(int size)
354{
355 int idx = 0;
356
357 if (likely(size > ZS_MIN_ALLOC_SIZE))
358 idx = DIV_ROUND_UP(size - ZS_MIN_ALLOC_SIZE,
359 ZS_SIZE_CLASS_DELTA);
360
361 return idx;
362}
363
364static enum fullness_group get_fullness_group(struct page *page)
365{
366 int inuse, max_objects;
367 enum fullness_group fg;
368 BUG_ON(!is_first_page(page));
369
370 inuse = page->inuse;
371 max_objects = page->objects;
372
373 if (inuse == 0)
374 fg = ZS_EMPTY;
375 else if (inuse == max_objects)
376 fg = ZS_FULL;
377 else if (inuse <= max_objects / fullness_threshold_frac)
378 fg = ZS_ALMOST_EMPTY;
379 else
380 fg = ZS_ALMOST_FULL;
381
382 return fg;
383}
384
385static void insert_zspage(struct page *page, struct size_class *class,
386 enum fullness_group fullness)
387{
388 struct page **head;
389
390 BUG_ON(!is_first_page(page));
391
392 if (fullness >= _ZS_NR_FULLNESS_GROUPS)
393 return;
394
395 head = &class->fullness_list[fullness];
396 if (*head)
397 list_add_tail(&page->lru, &(*head)->lru);
398
399 *head = page;
400}
401
402static void remove_zspage(struct page *page, struct size_class *class,
403 enum fullness_group fullness)
404{
405 struct page **head;
406
407 BUG_ON(!is_first_page(page));
408
409 if (fullness >= _ZS_NR_FULLNESS_GROUPS)
410 return;
411
412 head = &class->fullness_list[fullness];
413 BUG_ON(!*head);
414 if (list_empty(&(*head)->lru))
415 *head = NULL;
416 else if (*head == page)
417 *head = (struct page *)list_entry((*head)->lru.next,
418 struct page, lru);
419
420 list_del_init(&page->lru);
421}
422
423static enum fullness_group fix_fullness_group(struct zs_pool *pool,
424 struct page *page)
425{
426 int class_idx;
427 struct size_class *class;
428 enum fullness_group currfg, newfg;
429
430 BUG_ON(!is_first_page(page));
431
432 get_zspage_mapping(page, &class_idx, &currfg);
433 newfg = get_fullness_group(page);
434 if (newfg == currfg)
435 goto out;
436
437 class = &pool->size_class[class_idx];
438 remove_zspage(page, class, currfg);
439 insert_zspage(page, class, newfg);
440 set_zspage_mapping(page, class_idx, newfg);
441
442out:
443 return newfg;
444}
445
446/*
447 * We have to decide on how many pages to link together
448 * to form a zspage for each size class. This is important
449 * to reduce wastage due to unusable space left at end of
450 * each zspage which is given as:
451 * wastage = Zp - Zp % size_class
452 * where Zp = zspage size = k * PAGE_SIZE where k = 1, 2, ...
453 *
454 * For example, for size class of 3/8 * PAGE_SIZE, we should
455 * link together 3 PAGE_SIZE sized pages to form a zspage
456 * since then we can perfectly fit in 8 such objects.
457 */
Minchan Kim2e3b61542012-05-03 15:40:39 +0900458static int get_pages_per_zspage(int class_size)
Nitin Gupta61989a82012-01-09 16:51:56 -0600459{
460 int i, max_usedpc = 0;
461 /* zspage order which gives maximum used size per KB */
462 int max_usedpc_order = 1;
463
Seth Jennings84d4faa2012-03-05 11:33:21 -0600464 for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
Nitin Gupta61989a82012-01-09 16:51:56 -0600465 int zspage_size;
466 int waste, usedpc;
467
468 zspage_size = i * PAGE_SIZE;
469 waste = zspage_size % class_size;
470 usedpc = (zspage_size - waste) * 100 / zspage_size;
471
472 if (usedpc > max_usedpc) {
473 max_usedpc = usedpc;
474 max_usedpc_order = i;
475 }
476 }
477
478 return max_usedpc_order;
479}
480
481/*
482 * A single 'zspage' is composed of many system pages which are
483 * linked together using fields in struct page. This function finds
484 * the first/head page, given any component page of a zspage.
485 */
486static struct page *get_first_page(struct page *page)
487{
488 if (is_first_page(page))
489 return page;
490 else
491 return page->first_page;
492}
493
494static struct page *get_next_page(struct page *page)
495{
496 struct page *next;
497
498 if (is_last_page(page))
499 next = NULL;
500 else if (is_first_page(page))
501 next = (struct page *)page->private;
502 else
503 next = list_entry(page->lru.next, struct page, lru);
504
505 return next;
506}
507
Olav Haugan6871b982013-11-22 09:30:41 -0800508/*
509 * Encode <page, obj_idx> as a single handle value.
510 * On hardware platforms with physical memory starting at 0x0 the pfn
511 * could be 0 so we ensure that the handle will never be 0 by adjusting the
512 * encoded obj_idx value before encoding.
513 */
Nitin Gupta61989a82012-01-09 16:51:56 -0600514static void *obj_location_to_handle(struct page *page, unsigned long obj_idx)
515{
516 unsigned long handle;
517
518 if (!page) {
519 BUG_ON(obj_idx);
520 return NULL;
521 }
522
523 handle = page_to_pfn(page) << OBJ_INDEX_BITS;
Olav Haugan6871b982013-11-22 09:30:41 -0800524 handle |= ((obj_idx + 1) & OBJ_INDEX_MASK);
Nitin Gupta61989a82012-01-09 16:51:56 -0600525
526 return (void *)handle;
527}
528
Olav Haugan6871b982013-11-22 09:30:41 -0800529/*
530 * Decode <page, obj_idx> pair from the given object handle. We adjust the
531 * decoded obj_idx back to its original value since it was adjusted in
532 * obj_location_to_handle().
533 */
Minchan Kimc2344342012-06-08 15:39:25 +0900534static void obj_handle_to_location(unsigned long handle, struct page **page,
Nitin Gupta61989a82012-01-09 16:51:56 -0600535 unsigned long *obj_idx)
536{
Minchan Kimc2344342012-06-08 15:39:25 +0900537 *page = pfn_to_page(handle >> OBJ_INDEX_BITS);
Olav Haugan6871b982013-11-22 09:30:41 -0800538 *obj_idx = (handle & OBJ_INDEX_MASK) - 1;
Nitin Gupta61989a82012-01-09 16:51:56 -0600539}
540
541static unsigned long obj_idx_to_offset(struct page *page,
542 unsigned long obj_idx, int class_size)
543{
544 unsigned long off = 0;
545
546 if (!is_first_page(page))
547 off = page->index;
548
549 return off + obj_idx * class_size;
550}
551
Nitin Guptaf4477e92012-04-02 09:13:56 -0500552static void reset_page(struct page *page)
553{
554 clear_bit(PG_private, &page->flags);
555 clear_bit(PG_private_2, &page->flags);
556 set_page_private(page, 0);
557 page->mapping = NULL;
558 page->freelist = NULL;
Mel Gorman22b751c2013-02-22 16:34:59 -0800559 page_mapcount_reset(page);
Nitin Guptaf4477e92012-04-02 09:13:56 -0500560}
561
Nitin Gupta61989a82012-01-09 16:51:56 -0600562static void free_zspage(struct page *first_page)
563{
Nitin Guptaf4477e92012-04-02 09:13:56 -0500564 struct page *nextp, *tmp, *head_extra;
Nitin Gupta61989a82012-01-09 16:51:56 -0600565
566 BUG_ON(!is_first_page(first_page));
567 BUG_ON(first_page->inuse);
568
Nitin Guptaf4477e92012-04-02 09:13:56 -0500569 head_extra = (struct page *)page_private(first_page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600570
Nitin Guptaf4477e92012-04-02 09:13:56 -0500571 reset_page(first_page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600572 __free_page(first_page);
573
574 /* zspage with only 1 system page */
Nitin Guptaf4477e92012-04-02 09:13:56 -0500575 if (!head_extra)
Nitin Gupta61989a82012-01-09 16:51:56 -0600576 return;
577
Nitin Guptaf4477e92012-04-02 09:13:56 -0500578 list_for_each_entry_safe(nextp, tmp, &head_extra->lru, lru) {
Nitin Gupta61989a82012-01-09 16:51:56 -0600579 list_del(&nextp->lru);
Nitin Guptaf4477e92012-04-02 09:13:56 -0500580 reset_page(nextp);
Nitin Gupta61989a82012-01-09 16:51:56 -0600581 __free_page(nextp);
582 }
Nitin Guptaf4477e92012-04-02 09:13:56 -0500583 reset_page(head_extra);
584 __free_page(head_extra);
Nitin Gupta61989a82012-01-09 16:51:56 -0600585}
586
587/* Initialize a newly allocated zspage */
588static void init_zspage(struct page *first_page, struct size_class *class)
589{
590 unsigned long off = 0;
591 struct page *page = first_page;
592
593 BUG_ON(!is_first_page(first_page));
594 while (page) {
595 struct page *next_page;
596 struct link_free *link;
597 unsigned int i, objs_on_page;
598
599 /*
600 * page->index stores offset of first object starting
601 * in the page. For the first page, this is always 0,
602 * so we use first_page->index (aka ->freelist) to store
603 * head of corresponding zspage's freelist.
604 */
605 if (page != first_page)
606 page->index = off;
607
608 link = (struct link_free *)kmap_atomic(page) +
609 off / sizeof(*link);
610 objs_on_page = (PAGE_SIZE - off) / class->size;
611
612 for (i = 1; i <= objs_on_page; i++) {
613 off += class->size;
614 if (off < PAGE_SIZE) {
615 link->next = obj_location_to_handle(page, i);
616 link += class->size / sizeof(*link);
617 }
618 }
619
620 /*
621 * We now come to the last (full or partial) object on this
622 * page, which must point to the first object on the next
623 * page (if present)
624 */
625 next_page = get_next_page(page);
626 link->next = obj_location_to_handle(next_page, 0);
627 kunmap_atomic(link);
628 page = next_page;
629 off = (off + class->size) % PAGE_SIZE;
630 }
631}
632
633/*
634 * Allocate a zspage for the given size class
635 */
636static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
637{
638 int i, error;
Seth Jenningsb4b700c2012-06-13 16:03:42 -0500639 struct page *first_page = NULL, *uninitialized_var(prev_page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600640
641 /*
642 * Allocate individual pages and link them together as:
643 * 1. first page->private = first sub-page
644 * 2. all sub-pages are linked together using page->lru
645 * 3. each sub-page is linked to the first page using page->first_page
646 *
647 * For each size class, First/Head pages are linked together using
648 * page->lru. Also, we set PG_private to identify the first page
649 * (i.e. no other sub-page has this flag set) and PG_private_2 to
650 * identify the last page.
651 */
652 error = -ENOMEM;
Minchan Kim2e3b61542012-05-03 15:40:39 +0900653 for (i = 0; i < class->pages_per_zspage; i++) {
Seth Jenningsb4b700c2012-06-13 16:03:42 -0500654 struct page *page;
Nitin Gupta61989a82012-01-09 16:51:56 -0600655
656 page = alloc_page(flags);
657 if (!page)
658 goto cleanup;
659
660 INIT_LIST_HEAD(&page->lru);
661 if (i == 0) { /* first page */
Minchan Kima27545bf2012-04-25 15:23:09 +0900662 SetPagePrivate(page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600663 set_page_private(page, 0);
664 first_page = page;
665 first_page->inuse = 0;
666 }
667 if (i == 1)
668 first_page->private = (unsigned long)page;
669 if (i >= 1)
670 page->first_page = first_page;
671 if (i >= 2)
672 list_add(&page->lru, &prev_page->lru);
Minchan Kim2e3b61542012-05-03 15:40:39 +0900673 if (i == class->pages_per_zspage - 1) /* last page */
Minchan Kima27545bf2012-04-25 15:23:09 +0900674 SetPagePrivate2(page);
Nitin Gupta61989a82012-01-09 16:51:56 -0600675 prev_page = page;
676 }
677
678 init_zspage(first_page, class);
679
680 first_page->freelist = obj_location_to_handle(first_page, 0);
681 /* Maximum number of objects we can store in this zspage */
Minchan Kim2e3b61542012-05-03 15:40:39 +0900682 first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
Nitin Gupta61989a82012-01-09 16:51:56 -0600683
684 error = 0; /* Success */
685
686cleanup:
687 if (unlikely(error) && first_page) {
688 free_zspage(first_page);
689 first_page = NULL;
690 }
691
692 return first_page;
693}
694
695static struct page *find_get_zspage(struct size_class *class)
696{
697 int i;
698 struct page *page;
699
700 for (i = 0; i < _ZS_NR_FULLNESS_GROUPS; i++) {
701 page = class->fullness_list[i];
702 if (page)
703 break;
704 }
705
706 return page;
707}
708
Seth Jenningsf5536462012-07-18 11:55:56 -0500709#ifdef USE_PGTABLE_MAPPING
710static inline int __zs_cpu_up(struct mapping_area *area)
Seth Jennings5f601902012-07-02 16:15:49 -0500711{
Seth Jenningsf5536462012-07-18 11:55:56 -0500712 /*
713 * Make sure we don't leak memory if a cpu UP notification
714 * and zs_init() race and both call zs_cpu_up() on the same cpu
715 */
716 if (area->vm)
717 return 0;
718 area->vm = alloc_vm_area(PAGE_SIZE * 2, NULL);
719 if (!area->vm)
720 return -ENOMEM;
721 return 0;
722}
723
724static inline void __zs_cpu_down(struct mapping_area *area)
725{
726 if (area->vm)
727 free_vm_area(area->vm);
728 area->vm = NULL;
729}
730
731static inline void *__zs_map_object(struct mapping_area *area,
732 struct page *pages[2], int off, int size)
733{
734 BUG_ON(map_vm_area(area->vm, PAGE_KERNEL, &pages));
735 area->vm_addr = area->vm->addr;
736 return area->vm_addr + off;
737}
738
739static inline void __zs_unmap_object(struct mapping_area *area,
740 struct page *pages[2], int off, int size)
741{
742 unsigned long addr = (unsigned long)area->vm_addr;
Seth Jenningsf5536462012-07-18 11:55:56 -0500743
Joerg Roedeld95abbb2013-03-27 01:43:14 +0100744 unmap_kernel_range(addr, PAGE_SIZE * 2);
Seth Jenningsf5536462012-07-18 11:55:56 -0500745}
746
747#else /* USE_PGTABLE_MAPPING */
748
749static inline int __zs_cpu_up(struct mapping_area *area)
750{
751 /*
752 * Make sure we don't leak memory if a cpu UP notification
753 * and zs_init() race and both call zs_cpu_up() on the same cpu
754 */
755 if (area->vm_buf)
756 return 0;
757 area->vm_buf = (char *)__get_free_page(GFP_KERNEL);
758 if (!area->vm_buf)
759 return -ENOMEM;
760 return 0;
761}
762
763static inline void __zs_cpu_down(struct mapping_area *area)
764{
765 if (area->vm_buf)
766 free_page((unsigned long)area->vm_buf);
767 area->vm_buf = NULL;
768}
769
770static void *__zs_map_object(struct mapping_area *area,
771 struct page *pages[2], int off, int size)
772{
Seth Jennings5f601902012-07-02 16:15:49 -0500773 int sizes[2];
774 void *addr;
Seth Jenningsf5536462012-07-18 11:55:56 -0500775 char *buf = area->vm_buf;
Seth Jennings5f601902012-07-02 16:15:49 -0500776
Seth Jenningsf5536462012-07-18 11:55:56 -0500777 /* disable page faults to match kmap_atomic() return conditions */
778 pagefault_disable();
779
780 /* no read fastpath */
781 if (area->vm_mm == ZS_MM_WO)
782 goto out;
Seth Jennings5f601902012-07-02 16:15:49 -0500783
784 sizes[0] = PAGE_SIZE - off;
785 sizes[1] = size - sizes[0];
786
Seth Jennings5f601902012-07-02 16:15:49 -0500787 /* copy object to per-cpu buffer */
788 addr = kmap_atomic(pages[0]);
789 memcpy(buf, addr + off, sizes[0]);
790 kunmap_atomic(addr);
791 addr = kmap_atomic(pages[1]);
792 memcpy(buf + sizes[0], addr, sizes[1]);
793 kunmap_atomic(addr);
Seth Jenningsf5536462012-07-18 11:55:56 -0500794out:
795 return area->vm_buf;
Seth Jennings5f601902012-07-02 16:15:49 -0500796}
797
Seth Jenningsf5536462012-07-18 11:55:56 -0500798static void __zs_unmap_object(struct mapping_area *area,
799 struct page *pages[2], int off, int size)
Seth Jennings5f601902012-07-02 16:15:49 -0500800{
Seth Jennings5f601902012-07-02 16:15:49 -0500801 int sizes[2];
802 void *addr;
Seth Jenningsf5536462012-07-18 11:55:56 -0500803 char *buf = area->vm_buf;
Seth Jennings5f601902012-07-02 16:15:49 -0500804
Seth Jenningsf5536462012-07-18 11:55:56 -0500805 /* no write fastpath */
806 if (area->vm_mm == ZS_MM_RO)
807 goto out;
Seth Jennings5f601902012-07-02 16:15:49 -0500808
809 sizes[0] = PAGE_SIZE - off;
810 sizes[1] = size - sizes[0];
811
812 /* copy per-cpu buffer to object */
813 addr = kmap_atomic(pages[0]);
814 memcpy(addr + off, buf, sizes[0]);
815 kunmap_atomic(addr);
816 addr = kmap_atomic(pages[1]);
817 memcpy(addr, buf + sizes[0], sizes[1]);
818 kunmap_atomic(addr);
Seth Jenningsf5536462012-07-18 11:55:56 -0500819
820out:
821 /* enable page faults to match kunmap_atomic() return conditions */
822 pagefault_enable();
Seth Jennings5f601902012-07-02 16:15:49 -0500823}
Nitin Gupta61989a82012-01-09 16:51:56 -0600824
Seth Jenningsf5536462012-07-18 11:55:56 -0500825#endif /* USE_PGTABLE_MAPPING */
826
Nitin Gupta61989a82012-01-09 16:51:56 -0600827static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
828 void *pcpu)
829{
Seth Jenningsf5536462012-07-18 11:55:56 -0500830 int ret, cpu = (long)pcpu;
Nitin Gupta61989a82012-01-09 16:51:56 -0600831 struct mapping_area *area;
832
833 switch (action) {
834 case CPU_UP_PREPARE:
835 area = &per_cpu(zs_map_area, cpu);
Seth Jenningsf5536462012-07-18 11:55:56 -0500836 ret = __zs_cpu_up(area);
837 if (ret)
838 return notifier_from_errno(ret);
Nitin Gupta61989a82012-01-09 16:51:56 -0600839 break;
840 case CPU_DEAD:
841 case CPU_UP_CANCELED:
842 area = &per_cpu(zs_map_area, cpu);
Seth Jenningsf5536462012-07-18 11:55:56 -0500843 __zs_cpu_down(area);
Nitin Gupta61989a82012-01-09 16:51:56 -0600844 break;
845 }
846
847 return NOTIFY_OK;
848}
849
850static struct notifier_block zs_cpu_nb = {
851 .notifier_call = zs_cpu_notifier
852};
853
854static void zs_exit(void)
855{
856 int cpu;
857
Dan Streetman7b5c9b22014-08-06 16:08:38 -0700858#ifdef CONFIG_ZPOOL
859 zpool_unregister_driver(&zs_zpool_driver);
860#endif
861
Srivatsa S. Bhatcda631a2014-03-11 02:09:59 +0530862 cpu_notifier_register_begin();
863
Nitin Gupta61989a82012-01-09 16:51:56 -0600864 for_each_online_cpu(cpu)
865 zs_cpu_notifier(NULL, CPU_DEAD, (void *)(long)cpu);
Srivatsa S. Bhatcda631a2014-03-11 02:09:59 +0530866 __unregister_cpu_notifier(&zs_cpu_nb);
867
868 cpu_notifier_register_done();
Nitin Gupta61989a82012-01-09 16:51:56 -0600869}
870
871static int zs_init(void)
872{
873 int cpu, ret;
874
Srivatsa S. Bhatcda631a2014-03-11 02:09:59 +0530875 cpu_notifier_register_begin();
876
877 __register_cpu_notifier(&zs_cpu_nb);
Nitin Gupta61989a82012-01-09 16:51:56 -0600878 for_each_online_cpu(cpu) {
879 ret = zs_cpu_notifier(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
Srivatsa S. Bhatcda631a2014-03-11 02:09:59 +0530880 if (notifier_to_errno(ret)) {
881 cpu_notifier_register_done();
Nitin Gupta61989a82012-01-09 16:51:56 -0600882 goto fail;
Srivatsa S. Bhatcda631a2014-03-11 02:09:59 +0530883 }
Nitin Gupta61989a82012-01-09 16:51:56 -0600884 }
Srivatsa S. Bhatcda631a2014-03-11 02:09:59 +0530885
886 cpu_notifier_register_done();
887
Dan Streetman7b5c9b22014-08-06 16:08:38 -0700888#ifdef CONFIG_ZPOOL
889 zpool_register_driver(&zs_zpool_driver);
890#endif
891
Nitin Gupta61989a82012-01-09 16:51:56 -0600892 return 0;
893fail:
894 zs_exit();
895 return notifier_to_errno(ret);
896}
897
Davidlohr Bueso4bbc0bc2013-01-04 12:14:00 -0800898/**
899 * zs_create_pool - Creates an allocation pool to work from.
Seth Jennings0d145a52013-01-30 09:36:52 -0600900 * @flags: allocation flags used to allocate pool metadata
Davidlohr Bueso4bbc0bc2013-01-04 12:14:00 -0800901 *
902 * This function must be called before anything when using
903 * the zsmalloc allocator.
904 *
905 * On success, a pointer to the newly created pool is returned,
906 * otherwise NULL.
907 */
Seth Jennings0d145a52013-01-30 09:36:52 -0600908struct zs_pool *zs_create_pool(gfp_t flags)
Nitin Gupta61989a82012-01-09 16:51:56 -0600909{
Ben Hutchings069f1012012-06-20 02:31:11 +0100910 int i, ovhd_size;
Nitin Gupta61989a82012-01-09 16:51:56 -0600911 struct zs_pool *pool;
912
Nitin Gupta61989a82012-01-09 16:51:56 -0600913 ovhd_size = roundup(sizeof(*pool), PAGE_SIZE);
914 pool = kzalloc(ovhd_size, GFP_KERNEL);
915 if (!pool)
916 return NULL;
917
918 for (i = 0; i < ZS_SIZE_CLASSES; i++) {
919 int size;
920 struct size_class *class;
921
922 size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
923 if (size > ZS_MAX_ALLOC_SIZE)
924 size = ZS_MAX_ALLOC_SIZE;
925
926 class = &pool->size_class[i];
927 class->size = size;
928 class->index = i;
929 spin_lock_init(&class->lock);
Minchan Kim2e3b61542012-05-03 15:40:39 +0900930 class->pages_per_zspage = get_pages_per_zspage(size);
Nitin Gupta61989a82012-01-09 16:51:56 -0600931
932 }
933
Nitin Gupta61989a82012-01-09 16:51:56 -0600934 pool->flags = flags;
Nitin Gupta61989a82012-01-09 16:51:56 -0600935
Nitin Gupta61989a82012-01-09 16:51:56 -0600936 return pool;
937}
938EXPORT_SYMBOL_GPL(zs_create_pool);
939
940void zs_destroy_pool(struct zs_pool *pool)
941{
942 int i;
943
944 for (i = 0; i < ZS_SIZE_CLASSES; i++) {
945 int fg;
946 struct size_class *class = &pool->size_class[i];
947
948 for (fg = 0; fg < _ZS_NR_FULLNESS_GROUPS; fg++) {
949 if (class->fullness_list[fg]) {
950 pr_info("Freeing non-empty class with size "
951 "%db, fullness group %d\n",
952 class->size, fg);
953 }
954 }
955 }
956 kfree(pool);
957}
958EXPORT_SYMBOL_GPL(zs_destroy_pool);
959
960/**
961 * zs_malloc - Allocate block of given size from pool.
962 * @pool: pool to allocate from
963 * @size: size of block to allocate
Nitin Gupta61989a82012-01-09 16:51:56 -0600964 *
Minchan Kim00a61d82012-05-03 15:40:40 +0900965 * On success, handle to the allocated object is returned,
Minchan Kimc2344342012-06-08 15:39:25 +0900966 * otherwise 0.
Nitin Gupta61989a82012-01-09 16:51:56 -0600967 * Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail.
968 */
Minchan Kimc2344342012-06-08 15:39:25 +0900969unsigned long zs_malloc(struct zs_pool *pool, size_t size)
Nitin Gupta61989a82012-01-09 16:51:56 -0600970{
Minchan Kimc2344342012-06-08 15:39:25 +0900971 unsigned long obj;
Nitin Gupta61989a82012-01-09 16:51:56 -0600972 struct link_free *link;
973 int class_idx;
974 struct size_class *class;
975
976 struct page *first_page, *m_page;
977 unsigned long m_objidx, m_offset;
978
979 if (unlikely(!size || size > ZS_MAX_ALLOC_SIZE))
Minchan Kimc2344342012-06-08 15:39:25 +0900980 return 0;
Nitin Gupta61989a82012-01-09 16:51:56 -0600981
982 class_idx = get_size_class_index(size);
983 class = &pool->size_class[class_idx];
984 BUG_ON(class_idx != class->index);
985
986 spin_lock(&class->lock);
987 first_page = find_get_zspage(class);
988
989 if (!first_page) {
990 spin_unlock(&class->lock);
991 first_page = alloc_zspage(class, pool->flags);
992 if (unlikely(!first_page))
Minchan Kimc2344342012-06-08 15:39:25 +0900993 return 0;
Nitin Gupta61989a82012-01-09 16:51:56 -0600994
995 set_zspage_mapping(first_page, class->index, ZS_EMPTY);
Minchan Kim8ccca722014-10-09 15:29:48 -0700996 atomic_long_add(class->pages_per_zspage,
997 &pool->pages_allocated);
Nitin Gupta61989a82012-01-09 16:51:56 -0600998 spin_lock(&class->lock);
Nitin Gupta61989a82012-01-09 16:51:56 -0600999 }
1000
Minchan Kimc2344342012-06-08 15:39:25 +09001001 obj = (unsigned long)first_page->freelist;
Nitin Gupta61989a82012-01-09 16:51:56 -06001002 obj_handle_to_location(obj, &m_page, &m_objidx);
1003 m_offset = obj_idx_to_offset(m_page, m_objidx, class->size);
1004
1005 link = (struct link_free *)kmap_atomic(m_page) +
1006 m_offset / sizeof(*link);
1007 first_page->freelist = link->next;
1008 memset(link, POISON_INUSE, sizeof(*link));
1009 kunmap_atomic(link);
1010
1011 first_page->inuse++;
1012 /* Now move the zspage to another fullness group, if required */
1013 fix_fullness_group(pool, first_page);
1014 spin_unlock(&class->lock);
1015
1016 return obj;
1017}
1018EXPORT_SYMBOL_GPL(zs_malloc);
1019
Minchan Kimc2344342012-06-08 15:39:25 +09001020void zs_free(struct zs_pool *pool, unsigned long obj)
Nitin Gupta61989a82012-01-09 16:51:56 -06001021{
1022 struct link_free *link;
1023 struct page *first_page, *f_page;
1024 unsigned long f_objidx, f_offset;
1025
1026 int class_idx;
1027 struct size_class *class;
1028 enum fullness_group fullness;
1029
1030 if (unlikely(!obj))
1031 return;
1032
1033 obj_handle_to_location(obj, &f_page, &f_objidx);
1034 first_page = get_first_page(f_page);
1035
1036 get_zspage_mapping(first_page, &class_idx, &fullness);
1037 class = &pool->size_class[class_idx];
1038 f_offset = obj_idx_to_offset(f_page, f_objidx, class->size);
1039
1040 spin_lock(&class->lock);
1041
1042 /* Insert this object in containing zspage's freelist */
1043 link = (struct link_free *)((unsigned char *)kmap_atomic(f_page)
1044 + f_offset);
1045 link->next = first_page->freelist;
1046 kunmap_atomic(link);
Minchan Kimc2344342012-06-08 15:39:25 +09001047 first_page->freelist = (void *)obj;
Nitin Gupta61989a82012-01-09 16:51:56 -06001048
1049 first_page->inuse--;
1050 fullness = fix_fullness_group(pool, first_page);
Nitin Gupta61989a82012-01-09 16:51:56 -06001051 spin_unlock(&class->lock);
1052
Minchan Kim8ccca722014-10-09 15:29:48 -07001053 if (fullness == ZS_EMPTY) {
1054 atomic_long_sub(class->pages_per_zspage,
1055 &pool->pages_allocated);
Nitin Gupta61989a82012-01-09 16:51:56 -06001056 free_zspage(first_page);
Minchan Kim8ccca722014-10-09 15:29:48 -07001057 }
Nitin Gupta61989a82012-01-09 16:51:56 -06001058}
1059EXPORT_SYMBOL_GPL(zs_free);
1060
Minchan Kim00a61d82012-05-03 15:40:40 +09001061/**
1062 * zs_map_object - get address of allocated object from handle.
1063 * @pool: pool from which the object was allocated
1064 * @handle: handle returned from zs_malloc
1065 *
1066 * Before using an object allocated from zs_malloc, it must be mapped using
1067 * this function. When done with the object, it must be unmapped using
Seth Jennings166cfda2012-07-02 16:15:51 -05001068 * zs_unmap_object.
1069 *
1070 * Only one object can be mapped per cpu at a time. There is no protection
1071 * against nested mappings.
1072 *
1073 * This function returns with preemption and page faults disabled.
Minchan Kim00a61d82012-05-03 15:40:40 +09001074*/
Seth Jenningsb7418512012-07-02 16:15:52 -05001075void *zs_map_object(struct zs_pool *pool, unsigned long handle,
1076 enum zs_mapmode mm)
Nitin Gupta61989a82012-01-09 16:51:56 -06001077{
1078 struct page *page;
1079 unsigned long obj_idx, off;
1080
1081 unsigned int class_idx;
1082 enum fullness_group fg;
1083 struct size_class *class;
1084 struct mapping_area *area;
Seth Jenningsf5536462012-07-18 11:55:56 -05001085 struct page *pages[2];
Nitin Gupta61989a82012-01-09 16:51:56 -06001086
1087 BUG_ON(!handle);
1088
Seth Jenningsc60369f2012-07-18 11:55:55 -05001089 /*
1090 * Because we use per-cpu mapping areas shared among the
1091 * pools/users, we can't allow mapping in interrupt context
1092 * because it can corrupt another users mappings.
1093 */
1094 BUG_ON(in_interrupt());
1095
Nitin Gupta61989a82012-01-09 16:51:56 -06001096 obj_handle_to_location(handle, &page, &obj_idx);
1097 get_zspage_mapping(get_first_page(page), &class_idx, &fg);
1098 class = &pool->size_class[class_idx];
1099 off = obj_idx_to_offset(page, obj_idx, class->size);
1100
1101 area = &get_cpu_var(zs_map_area);
Seth Jenningsf5536462012-07-18 11:55:56 -05001102 area->vm_mm = mm;
Nitin Gupta61989a82012-01-09 16:51:56 -06001103 if (off + class->size <= PAGE_SIZE) {
1104 /* this object is contained entirely within a page */
1105 area->vm_addr = kmap_atomic(page);
Seth Jennings5f601902012-07-02 16:15:49 -05001106 return area->vm_addr + off;
Nitin Gupta61989a82012-01-09 16:51:56 -06001107 }
1108
Seth Jenningsf5536462012-07-18 11:55:56 -05001109 /* this object spans two pages */
1110 pages[0] = page;
1111 pages[1] = get_next_page(page);
1112 BUG_ON(!pages[1]);
Seth Jenningsb7418512012-07-02 16:15:52 -05001113
Seth Jenningsf5536462012-07-18 11:55:56 -05001114 return __zs_map_object(area, pages, off, class->size);
Nitin Gupta61989a82012-01-09 16:51:56 -06001115}
1116EXPORT_SYMBOL_GPL(zs_map_object);
1117
Minchan Kimc2344342012-06-08 15:39:25 +09001118void zs_unmap_object(struct zs_pool *pool, unsigned long handle)
Nitin Gupta61989a82012-01-09 16:51:56 -06001119{
1120 struct page *page;
1121 unsigned long obj_idx, off;
1122
1123 unsigned int class_idx;
1124 enum fullness_group fg;
1125 struct size_class *class;
1126 struct mapping_area *area;
1127
1128 BUG_ON(!handle);
1129
1130 obj_handle_to_location(handle, &page, &obj_idx);
1131 get_zspage_mapping(get_first_page(page), &class_idx, &fg);
1132 class = &pool->size_class[class_idx];
1133 off = obj_idx_to_offset(page, obj_idx, class->size);
1134
Seth Jenningsf5536462012-07-18 11:55:56 -05001135 area = &__get_cpu_var(zs_map_area);
1136 if (off + class->size <= PAGE_SIZE)
1137 kunmap_atomic(area->vm_addr);
1138 else {
1139 struct page *pages[2];
Seth Jenningsb7418512012-07-02 16:15:52 -05001140
Seth Jenningsf5536462012-07-18 11:55:56 -05001141 pages[0] = page;
1142 pages[1] = get_next_page(page);
1143 BUG_ON(!pages[1]);
1144
1145 __zs_unmap_object(area, pages, off, class->size);
1146 }
Nitin Gupta61989a82012-01-09 16:51:56 -06001147 put_cpu_var(zs_map_area);
1148}
1149EXPORT_SYMBOL_GPL(zs_unmap_object);
1150
1151u64 zs_get_total_size_bytes(struct zs_pool *pool)
1152{
Minchan Kim8ccca722014-10-09 15:29:48 -07001153 u64 npages = atomic_long_read(&pool->pages_allocated);
Nitin Gupta61989a82012-01-09 16:51:56 -06001154 return npages << PAGE_SHIFT;
1155}
1156EXPORT_SYMBOL_GPL(zs_get_total_size_bytes);
Ben Hutchings069f1012012-06-20 02:31:11 +01001157
1158module_init(zs_init);
1159module_exit(zs_exit);
1160
1161MODULE_LICENSE("Dual BSD/GPL");
1162MODULE_AUTHOR("Nitin Gupta <ngupta@vflare.org>");