2 * zsmalloc memory allocator
4 * Copyright (C) 2011 Nitin Gupta
5 * Copyright (C) 2012, 2013 Minchan Kim
7 * This code is released using a dual license strategy: BSD/GPL
8 * You can choose the license that better fits your requirements.
10 * Released under the terms of 3-clause BSD License
11 * Released under the terms of GNU General Public License Version 2.0
15 * This allocator is designed for use with zram. Thus, the allocator is
16 * supposed to work well under low memory conditions. In particular, it
17 * never attempts higher order page allocation which is very likely to
18 * fail under memory pressure. On the other hand, if we just use single
19 * (0-order) pages, it would suffer from very high fragmentation --
20 * any object of size PAGE_SIZE/2 or larger would occupy an entire page.
21 * This was one of the major issues with its predecessor (xvmalloc).
23 * To overcome these issues, zsmalloc allocates a bunch of 0-order pages
24 * and links them together using various 'struct page' fields. These linked
25 * pages act as a single higher-order page i.e. an object can span 0-order
26 * page boundaries. The code refers to these linked pages as a single entity
29 * For simplicity, zsmalloc can only allocate objects of size up to PAGE_SIZE
30 * since this satisfies the requirements of all its current users (in the
31 * worst case, page is incompressible and is thus stored "as-is" i.e. in
32 * uncompressed form). For allocation requests larger than this size, failure
33 * is returned (see zs_malloc).
35 * Additionally, zs_malloc() does not return a dereferenceable pointer.
36 * Instead, it returns an opaque handle (unsigned long) which encodes actual
37 * location of the allocated object. The reason for this indirection is that
38 * zsmalloc does not keep zspages permanently mapped since that would cause
39 * issues on 32-bit systems where the VA region for kernel space mappings
40 * is very small. So, before using the allocating memory, the object has to
41 * be mapped using zs_map_object() to get a usable pointer and subsequently
42 * unmapped using zs_unmap_object().
44 * Following is how we use various fields and flags of underlying
45 * struct page(s) to form a zspage.
47 * Usage of struct page fields:
48 * page->first_page: points to the first component (0-order) page
49 * page->index (union with page->freelist): offset of the first object
50 * starting in this page. For the first page, this is
51 * always 0, so we use this field (aka freelist) to point
52 * to the first free object in zspage.
53 * page->lru: links together all component pages (except the first page)
56 * For _first_ page only:
58 * page->private (union with page->first_page): refers to the
59 * component page after the first page
60 * If the page is first_page for huge object, it stores handle.
61 * Look at size_class->huge.
62 * page->freelist: points to the first free object in zspage.
63 * Free objects are linked together using in-place
65 * page->objects: maximum number of objects we can store in this
66 * zspage (class->zspage_order * PAGE_SIZE / class->size)
67 * page->lru: links together first pages of various zspages.
68 * Basically forming list of zspages in a fullness group.
69 * page->mapping: class index and fullness group of the zspage
71 * Usage of struct page flags:
72 * PG_private: identifies the first component page
73 * PG_private2: identifies the last component page
77 #ifdef CONFIG_ZSMALLOC_DEBUG
81 #include <linux/module.h>
82 #include <linux/kernel.h>
83 #include <linux/sched.h>
84 #include <linux/bitops.h>
85 #include <linux/errno.h>
86 #include <linux/highmem.h>
87 #include <linux/string.h>
88 #include <linux/slab.h>
89 #include <asm/tlbflush.h>
90 #include <asm/pgtable.h>
91 #include <linux/cpumask.h>
92 #include <linux/cpu.h>
93 #include <linux/vmalloc.h>
94 #include <linux/hardirq.h>
95 #include <linux/spinlock.h>
96 #include <linux/types.h>
97 #include <linux/debugfs.h>
98 #include <linux/zsmalloc.h>
99 #include <linux/zpool.h>
102 * This must be power of 2 and greater than of equal to sizeof(link_free).
103 * These two conditions ensure that any 'struct link_free' itself doesn't
104 * span more than 1 page which avoids complex case of mapping 2 pages simply
105 * to restore link_free pointer values.
110 * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single)
111 * pages. ZS_MAX_ZSPAGE_ORDER defines upper limit on N.
113 #define ZS_MAX_ZSPAGE_ORDER 2
114 #define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
116 #define ZS_HANDLE_SIZE (sizeof(unsigned long))
119 * Object location (<PFN>, <obj_idx>) is encoded as
120 * as single (unsigned long) handle value.
122 * Note that object index <obj_idx> is relative to system
123 * page <PFN> it is stored in, so for each sub-page belonging
124 * to a zspage, obj_idx starts with 0.
126 * This is made more complicated by various memory models and PAE.
129 #ifndef MAX_PHYSMEM_BITS
130 #ifdef CONFIG_HIGHMEM64G
131 #define MAX_PHYSMEM_BITS 36
132 #else /* !CONFIG_HIGHMEM64G */
134 * If this definition of MAX_PHYSMEM_BITS is used, OBJ_INDEX_BITS will just
137 #define MAX_PHYSMEM_BITS BITS_PER_LONG
140 #define _PFN_BITS (MAX_PHYSMEM_BITS - PAGE_SHIFT)
143 * Memory for allocating for handle keeps object position by
144 * encoding <page, obj_idx> and the encoded value has a room
145 * in least bit(ie, look at obj_to_location).
146 * We use the bit to synchronize between object access by
147 * user and migration.
149 #define HANDLE_PIN_BIT 0
152 * Head in allocated object should have OBJ_ALLOCATED_TAG
153 * to identify the object was allocated or not.
154 * It's okay to add the status bit in the least bit because
155 * header keeps handle which is 4byte-aligned address so we
156 * have room for two bit at least.
158 #define OBJ_ALLOCATED_TAG 1
159 #define OBJ_TAG_BITS 1
160 #define OBJ_INDEX_BITS (BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS)
161 #define OBJ_INDEX_MASK ((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
163 #define MAX(a, b) ((a) >= (b) ? (a) : (b))
164 /* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */
165 #define ZS_MIN_ALLOC_SIZE \
166 MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS))
167 /* each chunk includes extra space to keep handle */
168 #define ZS_MAX_ALLOC_SIZE PAGE_SIZE
171 * On systems with 4K page size, this gives 255 size classes! There is a
173 * - Large number of size classes is potentially wasteful as free page are
174 * spread across these classes
175 * - Small number of size classes causes large internal fragmentation
176 * - Probably its better to use specific size classes (empirically
177 * determined). NOTE: all those class sizes must be set as multiple of
178 * ZS_ALIGN to make sure link_free itself never has to span 2 pages.
180 * ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN
183 #define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8)
186 * We do not maintain any list for completely empty or full pages
188 enum fullness_group {
191 _ZS_NR_FULLNESS_GROUPS,
203 #ifdef CONFIG_ZSMALLOC_STAT
205 static struct dentry *zs_stat_root;
207 struct zs_size_stat {
208 unsigned long objs[NR_ZS_STAT_TYPE];
214 * number of size_classes
216 static int zs_size_classes;
219 * We assign a page to ZS_ALMOST_EMPTY fullness group when:
221 * n = number of allocated objects
222 * N = total number of objects zspage can store
223 * f = fullness_threshold_frac
225 * Similarly, we assign zspage to:
226 * ZS_ALMOST_FULL when n > N / f
227 * ZS_EMPTY when n == 0
228 * ZS_FULL when n == N
230 * (see: fix_fullness_group())
232 static const int fullness_threshold_frac = 4;
236 * Size of objects stored in this class. Must be multiple
242 /* Number of PAGE_SIZE sized pages to combine to form a 'zspage' */
243 int pages_per_zspage;
244 /* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */
247 #ifdef CONFIG_ZSMALLOC_STAT
248 struct zs_size_stat stats;
253 struct page *fullness_list[_ZS_NR_FULLNESS_GROUPS];
257 * Placed within free objects to form a singly linked list.
258 * For every zspage, first_page->freelist gives head of this list.
260 * This must be power of 2 and less than or equal to ZS_ALIGN
265 * Position of next free chunk (encodes <PFN, obj_idx>)
266 * It's valid for non-allocated object
270 * Handle of allocated object.
272 unsigned long handle;
279 struct size_class **size_class;
280 struct kmem_cache *handle_cachep;
282 gfp_t flags; /* allocation flags used when growing pool */
283 atomic_long_t pages_allocated;
285 #ifdef CONFIG_ZSMALLOC_STAT
286 struct dentry *stat_dentry;
291 * A zspage's class index and fullness group
292 * are encoded in its (first)page->mapping
294 #define CLASS_IDX_BITS 28
295 #define FULLNESS_BITS 4
296 #define CLASS_IDX_MASK ((1 << CLASS_IDX_BITS) - 1)
297 #define FULLNESS_MASK ((1 << FULLNESS_BITS) - 1)
299 struct mapping_area {
300 #ifdef CONFIG_PGTABLE_MAPPING
301 struct vm_struct *vm; /* vm area for mapping object that span pages */
303 char *vm_buf; /* copy buffer for objects that span pages */
305 char *vm_addr; /* address of kmap_atomic()'ed pages */
306 enum zs_mapmode vm_mm; /* mapping mode */
310 static int create_handle_cache(struct zs_pool *pool)
312 pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,
314 return pool->handle_cachep ? 0 : 1;
317 static void destroy_handle_cache(struct zs_pool *pool)
319 kmem_cache_destroy(pool->handle_cachep);
322 static unsigned long alloc_handle(struct zs_pool *pool)
324 return (unsigned long)kmem_cache_alloc(pool->handle_cachep,
325 pool->flags & ~__GFP_HIGHMEM);
328 static void free_handle(struct zs_pool *pool, unsigned long handle)
330 kmem_cache_free(pool->handle_cachep, (void *)handle);
333 static void record_obj(unsigned long handle, unsigned long obj)
335 *(unsigned long *)handle = obj;
342 static void *zs_zpool_create(char *name, gfp_t gfp, struct zpool_ops *zpool_ops)
344 return zs_create_pool(name, gfp);
347 static void zs_zpool_destroy(void *pool)
349 zs_destroy_pool(pool);
352 static int zs_zpool_malloc(void *pool, size_t size, gfp_t gfp,
353 unsigned long *handle)
355 *handle = zs_malloc(pool, size);
356 return *handle ? 0 : -1;
358 static void zs_zpool_free(void *pool, unsigned long handle)
360 zs_free(pool, handle);
363 static int zs_zpool_shrink(void *pool, unsigned int pages,
364 unsigned int *reclaimed)
369 static void *zs_zpool_map(void *pool, unsigned long handle,
370 enum zpool_mapmode mm)
372 enum zs_mapmode zs_mm;
381 case ZPOOL_MM_RW: /* fallthru */
387 return zs_map_object(pool, handle, zs_mm);
389 static void zs_zpool_unmap(void *pool, unsigned long handle)
391 zs_unmap_object(pool, handle);
394 static u64 zs_zpool_total_size(void *pool)
396 return zs_get_total_pages(pool) << PAGE_SHIFT;
399 static struct zpool_driver zs_zpool_driver = {
401 .owner = THIS_MODULE,
402 .create = zs_zpool_create,
403 .destroy = zs_zpool_destroy,
404 .malloc = zs_zpool_malloc,
405 .free = zs_zpool_free,
406 .shrink = zs_zpool_shrink,
408 .unmap = zs_zpool_unmap,
409 .total_size = zs_zpool_total_size,
412 MODULE_ALIAS("zpool-zsmalloc");
413 #endif /* CONFIG_ZPOOL */
415 /* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
416 static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
418 static int is_first_page(struct page *page)
420 return PagePrivate(page);
423 static int is_last_page(struct page *page)
425 return PagePrivate2(page);
428 static void get_zspage_mapping(struct page *page, unsigned int *class_idx,
429 enum fullness_group *fullness)
432 BUG_ON(!is_first_page(page));
434 m = (unsigned long)page->mapping;
435 *fullness = m & FULLNESS_MASK;
436 *class_idx = (m >> FULLNESS_BITS) & CLASS_IDX_MASK;
439 static void set_zspage_mapping(struct page *page, unsigned int class_idx,
440 enum fullness_group fullness)
443 BUG_ON(!is_first_page(page));
445 m = ((class_idx & CLASS_IDX_MASK) << FULLNESS_BITS) |
446 (fullness & FULLNESS_MASK);
447 page->mapping = (struct address_space *)m;
451 * zsmalloc divides the pool into various size classes where each
452 * class maintains a list of zspages where each zspage is divided
453 * into equal sized chunks. Each allocation falls into one of these
454 * classes depending on its size. This function returns index of the
455 * size class which has chunk size big enough to hold the give size.
457 static int get_size_class_index(int size)
461 if (likely(size > ZS_MIN_ALLOC_SIZE))
462 idx = DIV_ROUND_UP(size - ZS_MIN_ALLOC_SIZE,
463 ZS_SIZE_CLASS_DELTA);
465 return min(zs_size_classes - 1, idx);
469 * For each size class, zspages are divided into different groups
470 * depending on how "full" they are. This was done so that we could
471 * easily find empty or nearly empty zspages when we try to shrink
472 * the pool (not yet implemented). This function returns fullness
473 * status of the given page.
475 static enum fullness_group get_fullness_group(struct page *page)
477 int inuse, max_objects;
478 enum fullness_group fg;
479 BUG_ON(!is_first_page(page));
482 max_objects = page->objects;
486 else if (inuse == max_objects)
488 else if (inuse <= 3 * max_objects / fullness_threshold_frac)
489 fg = ZS_ALMOST_EMPTY;
497 * Each size class maintains various freelists and zspages are assigned
498 * to one of these freelists based on the number of live objects they
499 * have. This functions inserts the given zspage into the freelist
500 * identified by <class, fullness_group>.
502 static void insert_zspage(struct page *page, struct size_class *class,
503 enum fullness_group fullness)
507 BUG_ON(!is_first_page(page));
509 if (fullness >= _ZS_NR_FULLNESS_GROUPS)
512 head = &class->fullness_list[fullness];
514 list_add_tail(&page->lru, &(*head)->lru);
520 * This function removes the given zspage from the freelist identified
521 * by <class, fullness_group>.
523 static void remove_zspage(struct page *page, struct size_class *class,
524 enum fullness_group fullness)
528 BUG_ON(!is_first_page(page));
530 if (fullness >= _ZS_NR_FULLNESS_GROUPS)
533 head = &class->fullness_list[fullness];
535 if (list_empty(&(*head)->lru))
537 else if (*head == page)
538 *head = (struct page *)list_entry((*head)->lru.next,
541 list_del_init(&page->lru);
545 * Each size class maintains zspages in different fullness groups depending
546 * on the number of live objects they contain. When allocating or freeing
547 * objects, the fullness status of the page can change, say, from ALMOST_FULL
548 * to ALMOST_EMPTY when freeing an object. This function checks if such
549 * a status change has occurred for the given page and accordingly moves the
550 * page from the freelist of the old fullness group to that of the new
553 static enum fullness_group fix_fullness_group(struct size_class *class,
557 enum fullness_group currfg, newfg;
559 BUG_ON(!is_first_page(page));
561 get_zspage_mapping(page, &class_idx, &currfg);
562 newfg = get_fullness_group(page);
566 remove_zspage(page, class, currfg);
567 insert_zspage(page, class, newfg);
568 set_zspage_mapping(page, class_idx, newfg);
575 * We have to decide on how many pages to link together
576 * to form a zspage for each size class. This is important
577 * to reduce wastage due to unusable space left at end of
578 * each zspage which is given as:
579 * wastage = Zp - Zp % size_class
580 * where Zp = zspage size = k * PAGE_SIZE where k = 1, 2, ...
582 * For example, for size class of 3/8 * PAGE_SIZE, we should
583 * link together 3 PAGE_SIZE sized pages to form a zspage
584 * since then we can perfectly fit in 8 such objects.
586 static int get_pages_per_zspage(int class_size)
588 int i, max_usedpc = 0;
589 /* zspage order which gives maximum used size per KB */
590 int max_usedpc_order = 1;
592 for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) {
596 zspage_size = i * PAGE_SIZE;
597 waste = zspage_size % class_size;
598 usedpc = (zspage_size - waste) * 100 / zspage_size;
600 if (usedpc > max_usedpc) {
602 max_usedpc_order = i;
606 return max_usedpc_order;
610 * A single 'zspage' is composed of many system pages which are
611 * linked together using fields in struct page. This function finds
612 * the first/head page, given any component page of a zspage.
614 static struct page *get_first_page(struct page *page)
616 if (is_first_page(page))
619 return page->first_page;
622 static struct page *get_next_page(struct page *page)
626 if (is_last_page(page))
628 else if (is_first_page(page))
629 next = (struct page *)page_private(page);
631 next = list_entry(page->lru.next, struct page, lru);
637 * Encode <page, obj_idx> as a single handle value.
638 * We use the least bit of handle for tagging.
640 static void *location_to_obj(struct page *page, unsigned long obj_idx)
649 obj = page_to_pfn(page) << OBJ_INDEX_BITS;
650 obj |= ((obj_idx) & OBJ_INDEX_MASK);
651 obj <<= OBJ_TAG_BITS;
657 * Decode <page, obj_idx> pair from the given object handle. We adjust the
658 * decoded obj_idx back to its original value since it was adjusted in
661 static void obj_to_location(unsigned long obj, struct page **page,
662 unsigned long *obj_idx)
664 obj >>= OBJ_TAG_BITS;
665 *page = pfn_to_page(obj >> OBJ_INDEX_BITS);
666 *obj_idx = (obj & OBJ_INDEX_MASK);
669 static unsigned long handle_to_obj(unsigned long handle)
671 return *(unsigned long *)handle;
674 static unsigned long obj_to_head(struct size_class *class, struct page *page,
678 VM_BUG_ON(!is_first_page(page));
679 return *(unsigned long *)page_private(page);
681 return *(unsigned long *)obj;
684 static unsigned long obj_idx_to_offset(struct page *page,
685 unsigned long obj_idx, int class_size)
687 unsigned long off = 0;
689 if (!is_first_page(page))
692 return off + obj_idx * class_size;
695 static inline int trypin_tag(unsigned long handle)
697 unsigned long *ptr = (unsigned long *)handle;
699 return !test_and_set_bit_lock(HANDLE_PIN_BIT, ptr);
702 static void pin_tag(unsigned long handle)
704 while (!trypin_tag(handle));
707 static void unpin_tag(unsigned long handle)
709 unsigned long *ptr = (unsigned long *)handle;
711 clear_bit_unlock(HANDLE_PIN_BIT, ptr);
714 static void reset_page(struct page *page)
716 clear_bit(PG_private, &page->flags);
717 clear_bit(PG_private_2, &page->flags);
718 set_page_private(page, 0);
719 page->mapping = NULL;
720 page->freelist = NULL;
721 page_mapcount_reset(page);
724 static void free_zspage(struct page *first_page)
726 struct page *nextp, *tmp, *head_extra;
728 BUG_ON(!is_first_page(first_page));
729 BUG_ON(first_page->inuse);
731 head_extra = (struct page *)page_private(first_page);
733 reset_page(first_page);
734 __free_page(first_page);
736 /* zspage with only 1 system page */
740 list_for_each_entry_safe(nextp, tmp, &head_extra->lru, lru) {
741 list_del(&nextp->lru);
745 reset_page(head_extra);
746 __free_page(head_extra);
749 /* Initialize a newly allocated zspage */
750 static void init_zspage(struct page *first_page, struct size_class *class)
752 unsigned long off = 0;
753 struct page *page = first_page;
755 BUG_ON(!is_first_page(first_page));
757 struct page *next_page;
758 struct link_free *link;
763 * page->index stores offset of first object starting
764 * in the page. For the first page, this is always 0,
765 * so we use first_page->index (aka ->freelist) to store
766 * head of corresponding zspage's freelist.
768 if (page != first_page)
771 vaddr = kmap_atomic(page);
772 link = (struct link_free *)vaddr + off / sizeof(*link);
774 while ((off += class->size) < PAGE_SIZE) {
775 link->next = location_to_obj(page, i++);
776 link += class->size / sizeof(*link);
780 * We now come to the last (full or partial) object on this
781 * page, which must point to the first object on the next
784 next_page = get_next_page(page);
785 link->next = location_to_obj(next_page, 0);
786 kunmap_atomic(vaddr);
793 * Allocate a zspage for the given size class
795 static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
798 struct page *first_page = NULL, *uninitialized_var(prev_page);
801 * Allocate individual pages and link them together as:
802 * 1. first page->private = first sub-page
803 * 2. all sub-pages are linked together using page->lru
804 * 3. each sub-page is linked to the first page using page->first_page
806 * For each size class, First/Head pages are linked together using
807 * page->lru. Also, we set PG_private to identify the first page
808 * (i.e. no other sub-page has this flag set) and PG_private_2 to
809 * identify the last page.
812 for (i = 0; i < class->pages_per_zspage; i++) {
815 page = alloc_page(flags);
819 INIT_LIST_HEAD(&page->lru);
820 if (i == 0) { /* first page */
821 SetPagePrivate(page);
822 set_page_private(page, 0);
824 first_page->inuse = 0;
827 set_page_private(first_page, (unsigned long)page);
829 page->first_page = first_page;
831 list_add(&page->lru, &prev_page->lru);
832 if (i == class->pages_per_zspage - 1) /* last page */
833 SetPagePrivate2(page);
837 init_zspage(first_page, class);
839 first_page->freelist = location_to_obj(first_page, 0);
840 /* Maximum number of objects we can store in this zspage */
841 first_page->objects = class->pages_per_zspage * PAGE_SIZE / class->size;
843 error = 0; /* Success */
846 if (unlikely(error) && first_page) {
847 free_zspage(first_page);
854 static struct page *find_get_zspage(struct size_class *class)
859 for (i = 0; i < _ZS_NR_FULLNESS_GROUPS; i++) {
860 page = class->fullness_list[i];
868 #ifdef CONFIG_PGTABLE_MAPPING
869 static inline int __zs_cpu_up(struct mapping_area *area)
872 * Make sure we don't leak memory if a cpu UP notification
873 * and zs_init() race and both call zs_cpu_up() on the same cpu
877 area->vm = alloc_vm_area(PAGE_SIZE * 2, NULL);
883 static inline void __zs_cpu_down(struct mapping_area *area)
886 free_vm_area(area->vm);
890 static inline void *__zs_map_object(struct mapping_area *area,
891 struct page *pages[2], int off, int size)
893 BUG_ON(map_vm_area(area->vm, PAGE_KERNEL, pages));
894 area->vm_addr = area->vm->addr;
895 return area->vm_addr + off;
898 static inline void __zs_unmap_object(struct mapping_area *area,
899 struct page *pages[2], int off, int size)
901 unsigned long addr = (unsigned long)area->vm_addr;
903 unmap_kernel_range(addr, PAGE_SIZE * 2);
906 #else /* CONFIG_PGTABLE_MAPPING */
908 static inline int __zs_cpu_up(struct mapping_area *area)
911 * Make sure we don't leak memory if a cpu UP notification
912 * and zs_init() race and both call zs_cpu_up() on the same cpu
916 area->vm_buf = kmalloc(ZS_MAX_ALLOC_SIZE, GFP_KERNEL);
922 static inline void __zs_cpu_down(struct mapping_area *area)
928 static void *__zs_map_object(struct mapping_area *area,
929 struct page *pages[2], int off, int size)
933 char *buf = area->vm_buf;
935 /* disable page faults to match kmap_atomic() return conditions */
938 /* no read fastpath */
939 if (area->vm_mm == ZS_MM_WO)
942 sizes[0] = PAGE_SIZE - off;
943 sizes[1] = size - sizes[0];
945 /* copy object to per-cpu buffer */
946 addr = kmap_atomic(pages[0]);
947 memcpy(buf, addr + off, sizes[0]);
949 addr = kmap_atomic(pages[1]);
950 memcpy(buf + sizes[0], addr, sizes[1]);
956 static void __zs_unmap_object(struct mapping_area *area,
957 struct page *pages[2], int off, int size)
963 /* no write fastpath */
964 if (area->vm_mm == ZS_MM_RO)
969 buf = buf + ZS_HANDLE_SIZE;
970 size -= ZS_HANDLE_SIZE;
971 off += ZS_HANDLE_SIZE;
974 sizes[0] = PAGE_SIZE - off;
975 sizes[1] = size - sizes[0];
977 /* copy per-cpu buffer to object */
978 addr = kmap_atomic(pages[0]);
979 memcpy(addr + off, buf, sizes[0]);
981 addr = kmap_atomic(pages[1]);
982 memcpy(addr, buf + sizes[0], sizes[1]);
986 /* enable page faults to match kunmap_atomic() return conditions */
990 #endif /* CONFIG_PGTABLE_MAPPING */
992 static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
995 int ret, cpu = (long)pcpu;
996 struct mapping_area *area;
1000 area = &per_cpu(zs_map_area, cpu);
1001 ret = __zs_cpu_up(area);
1003 return notifier_from_errno(ret);
1006 case CPU_UP_CANCELED:
1007 area = &per_cpu(zs_map_area, cpu);
1008 __zs_cpu_down(area);
1015 static struct notifier_block zs_cpu_nb = {
1016 .notifier_call = zs_cpu_notifier
1019 static int zs_register_cpu_notifier(void)
1021 int cpu, uninitialized_var(ret);
1023 cpu_notifier_register_begin();
1025 __register_cpu_notifier(&zs_cpu_nb);
1026 for_each_online_cpu(cpu) {
1027 ret = zs_cpu_notifier(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
1028 if (notifier_to_errno(ret))
1032 cpu_notifier_register_done();
1033 return notifier_to_errno(ret);
1036 static void zs_unregister_cpu_notifier(void)
1040 cpu_notifier_register_begin();
1042 for_each_online_cpu(cpu)
1043 zs_cpu_notifier(NULL, CPU_DEAD, (void *)(long)cpu);
1044 __unregister_cpu_notifier(&zs_cpu_nb);
1046 cpu_notifier_register_done();
1049 static void init_zs_size_classes(void)
1053 nr = (ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / ZS_SIZE_CLASS_DELTA + 1;
1054 if ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) % ZS_SIZE_CLASS_DELTA)
1057 zs_size_classes = nr;
1060 static unsigned int get_maxobj_per_zspage(int size, int pages_per_zspage)
1062 return pages_per_zspage * PAGE_SIZE / size;
1065 static bool can_merge(struct size_class *prev, int size, int pages_per_zspage)
1067 if (prev->pages_per_zspage != pages_per_zspage)
1070 if (get_maxobj_per_zspage(prev->size, prev->pages_per_zspage)
1071 != get_maxobj_per_zspage(size, pages_per_zspage))
1077 static bool zspage_full(struct page *page)
1079 BUG_ON(!is_first_page(page));
1081 return page->inuse == page->objects;
1084 #ifdef CONFIG_ZSMALLOC_STAT
1086 static inline void zs_stat_inc(struct size_class *class,
1087 enum zs_stat_type type, unsigned long cnt)
1089 class->stats.objs[type] += cnt;
1092 static inline void zs_stat_dec(struct size_class *class,
1093 enum zs_stat_type type, unsigned long cnt)
1095 class->stats.objs[type] -= cnt;
1098 static inline unsigned long zs_stat_get(struct size_class *class,
1099 enum zs_stat_type type)
1101 return class->stats.objs[type];
1104 static int __init zs_stat_init(void)
1106 if (!debugfs_initialized())
1109 zs_stat_root = debugfs_create_dir("zsmalloc", NULL);
1116 static void __exit zs_stat_exit(void)
1118 debugfs_remove_recursive(zs_stat_root);
1121 static int zs_stats_size_show(struct seq_file *s, void *v)
1124 struct zs_pool *pool = s->private;
1125 struct size_class *class;
1126 int objs_per_zspage;
1127 unsigned long obj_allocated, obj_used, pages_used;
1128 unsigned long total_objs = 0, total_used_objs = 0, total_pages = 0;
1130 seq_printf(s, " %5s %5s %13s %10s %10s\n", "class", "size",
1131 "obj_allocated", "obj_used", "pages_used");
1133 for (i = 0; i < zs_size_classes; i++) {
1134 class = pool->size_class[i];
1136 if (class->index != i)
1139 spin_lock(&class->lock);
1140 obj_allocated = zs_stat_get(class, OBJ_ALLOCATED);
1141 obj_used = zs_stat_get(class, OBJ_USED);
1142 spin_unlock(&class->lock);
1144 objs_per_zspage = get_maxobj_per_zspage(class->size,
1145 class->pages_per_zspage);
1146 pages_used = obj_allocated / objs_per_zspage *
1147 class->pages_per_zspage;
1149 seq_printf(s, " %5u %5u %10lu %10lu %10lu\n", i,
1150 class->size, obj_allocated, obj_used, pages_used);
1152 total_objs += obj_allocated;
1153 total_used_objs += obj_used;
1154 total_pages += pages_used;
1158 seq_printf(s, " %5s %5s %10lu %10lu %10lu\n", "Total", "",
1159 total_objs, total_used_objs, total_pages);
1164 static int zs_stats_size_open(struct inode *inode, struct file *file)
1166 return single_open(file, zs_stats_size_show, inode->i_private);
1169 static const struct file_operations zs_stat_size_ops = {
1170 .open = zs_stats_size_open,
1172 .llseek = seq_lseek,
1173 .release = single_release,
1176 static int zs_pool_stat_create(char *name, struct zs_pool *pool)
1178 struct dentry *entry;
1183 entry = debugfs_create_dir(name, zs_stat_root);
1185 pr_warn("debugfs dir <%s> creation failed\n", name);
1188 pool->stat_dentry = entry;
1190 entry = debugfs_create_file("obj_in_classes", S_IFREG | S_IRUGO,
1191 pool->stat_dentry, pool, &zs_stat_size_ops);
1193 pr_warn("%s: debugfs file entry <%s> creation failed\n",
1194 name, "obj_in_classes");
1201 static void zs_pool_stat_destroy(struct zs_pool *pool)
1203 debugfs_remove_recursive(pool->stat_dentry);
1206 #else /* CONFIG_ZSMALLOC_STAT */
1208 static inline void zs_stat_inc(struct size_class *class,
1209 enum zs_stat_type type, unsigned long cnt)
1213 static inline void zs_stat_dec(struct size_class *class,
1214 enum zs_stat_type type, unsigned long cnt)
1218 static inline unsigned long zs_stat_get(struct size_class *class,
1219 enum zs_stat_type type)
1224 static int __init zs_stat_init(void)
1229 static void __exit zs_stat_exit(void)
1233 static inline int zs_pool_stat_create(char *name, struct zs_pool *pool)
1238 static inline void zs_pool_stat_destroy(struct zs_pool *pool)
1244 unsigned long zs_get_total_pages(struct zs_pool *pool)
1246 return atomic_long_read(&pool->pages_allocated);
1248 EXPORT_SYMBOL_GPL(zs_get_total_pages);
1251 * zs_map_object - get address of allocated object from handle.
1252 * @pool: pool from which the object was allocated
1253 * @handle: handle returned from zs_malloc
1255 * Before using an object allocated from zs_malloc, it must be mapped using
1256 * this function. When done with the object, it must be unmapped using
1259 * Only one object can be mapped per cpu at a time. There is no protection
1260 * against nested mappings.
1262 * This function returns with preemption and page faults disabled.
1264 void *zs_map_object(struct zs_pool *pool, unsigned long handle,
1268 unsigned long obj, obj_idx, off;
1270 unsigned int class_idx;
1271 enum fullness_group fg;
1272 struct size_class *class;
1273 struct mapping_area *area;
1274 struct page *pages[2];
1280 * Because we use per-cpu mapping areas shared among the
1281 * pools/users, we can't allow mapping in interrupt context
1282 * because it can corrupt another users mappings.
1284 BUG_ON(in_interrupt());
1286 /* From now on, migration cannot move the object */
1289 obj = handle_to_obj(handle);
1290 obj_to_location(obj, &page, &obj_idx);
1291 get_zspage_mapping(get_first_page(page), &class_idx, &fg);
1292 class = pool->size_class[class_idx];
1293 off = obj_idx_to_offset(page, obj_idx, class->size);
1295 area = &get_cpu_var(zs_map_area);
1297 if (off + class->size <= PAGE_SIZE) {
1298 /* this object is contained entirely within a page */
1299 area->vm_addr = kmap_atomic(page);
1300 ret = area->vm_addr + off;
1304 /* this object spans two pages */
1306 pages[1] = get_next_page(page);
1309 ret = __zs_map_object(area, pages, off, class->size);
1312 ret += ZS_HANDLE_SIZE;
1316 EXPORT_SYMBOL_GPL(zs_map_object);
1318 void zs_unmap_object(struct zs_pool *pool, unsigned long handle)
1321 unsigned long obj, obj_idx, off;
1323 unsigned int class_idx;
1324 enum fullness_group fg;
1325 struct size_class *class;
1326 struct mapping_area *area;
1330 obj = handle_to_obj(handle);
1331 obj_to_location(obj, &page, &obj_idx);
1332 get_zspage_mapping(get_first_page(page), &class_idx, &fg);
1333 class = pool->size_class[class_idx];
1334 off = obj_idx_to_offset(page, obj_idx, class->size);
1336 area = this_cpu_ptr(&zs_map_area);
1337 if (off + class->size <= PAGE_SIZE)
1338 kunmap_atomic(area->vm_addr);
1340 struct page *pages[2];
1343 pages[1] = get_next_page(page);
1346 __zs_unmap_object(area, pages, off, class->size);
1348 put_cpu_var(zs_map_area);
1351 EXPORT_SYMBOL_GPL(zs_unmap_object);
1353 static unsigned long obj_malloc(struct page *first_page,
1354 struct size_class *class, unsigned long handle)
1357 struct link_free *link;
1359 struct page *m_page;
1360 unsigned long m_objidx, m_offset;
1363 handle |= OBJ_ALLOCATED_TAG;
1364 obj = (unsigned long)first_page->freelist;
1365 obj_to_location(obj, &m_page, &m_objidx);
1366 m_offset = obj_idx_to_offset(m_page, m_objidx, class->size);
1368 vaddr = kmap_atomic(m_page);
1369 link = (struct link_free *)vaddr + m_offset / sizeof(*link);
1370 first_page->freelist = link->next;
1372 /* record handle in the header of allocated chunk */
1373 link->handle = handle;
1375 /* record handle in first_page->private */
1376 set_page_private(first_page, handle);
1377 kunmap_atomic(vaddr);
1378 first_page->inuse++;
1379 zs_stat_inc(class, OBJ_USED, 1);
1386 * zs_malloc - Allocate block of given size from pool.
1387 * @pool: pool to allocate from
1388 * @size: size of block to allocate
1390 * On success, handle to the allocated object is returned,
1392 * Allocation requests with size > ZS_MAX_ALLOC_SIZE will fail.
1394 unsigned long zs_malloc(struct zs_pool *pool, size_t size)
1396 unsigned long handle, obj;
1397 struct size_class *class;
1398 struct page *first_page;
1400 if (unlikely(!size || size > ZS_MAX_ALLOC_SIZE))
1403 handle = alloc_handle(pool);
1407 /* extra space in chunk to keep the handle */
1408 size += ZS_HANDLE_SIZE;
1409 class = pool->size_class[get_size_class_index(size)];
1410 /* In huge class size, we store the handle into first_page->private */
1412 size -= ZS_HANDLE_SIZE;
1413 class = pool->size_class[get_size_class_index(size)];
1416 spin_lock(&class->lock);
1417 first_page = find_get_zspage(class);
1420 spin_unlock(&class->lock);
1421 first_page = alloc_zspage(class, pool->flags);
1422 if (unlikely(!first_page)) {
1423 free_handle(pool, handle);
1427 set_zspage_mapping(first_page, class->index, ZS_EMPTY);
1428 atomic_long_add(class->pages_per_zspage,
1429 &pool->pages_allocated);
1431 spin_lock(&class->lock);
1432 zs_stat_inc(class, OBJ_ALLOCATED, get_maxobj_per_zspage(
1433 class->size, class->pages_per_zspage));
1436 obj = obj_malloc(first_page, class, handle);
1437 /* Now move the zspage to another fullness group, if required */
1438 fix_fullness_group(class, first_page);
1439 record_obj(handle, obj);
1440 spin_unlock(&class->lock);
1444 EXPORT_SYMBOL_GPL(zs_malloc);
1446 static void obj_free(struct zs_pool *pool, struct size_class *class,
1449 struct link_free *link;
1450 struct page *first_page, *f_page;
1451 unsigned long f_objidx, f_offset;
1454 enum fullness_group fullness;
1458 obj &= ~OBJ_ALLOCATED_TAG;
1459 obj_to_location(obj, &f_page, &f_objidx);
1460 first_page = get_first_page(f_page);
1462 get_zspage_mapping(first_page, &class_idx, &fullness);
1463 f_offset = obj_idx_to_offset(f_page, f_objidx, class->size);
1465 vaddr = kmap_atomic(f_page);
1467 /* Insert this object in containing zspage's freelist */
1468 link = (struct link_free *)(vaddr + f_offset);
1469 link->next = first_page->freelist;
1471 set_page_private(first_page, 0);
1472 kunmap_atomic(vaddr);
1473 first_page->freelist = (void *)obj;
1474 first_page->inuse--;
1475 zs_stat_dec(class, OBJ_USED, 1);
1478 void zs_free(struct zs_pool *pool, unsigned long handle)
1480 struct page *first_page, *f_page;
1481 unsigned long obj, f_objidx;
1483 struct size_class *class;
1484 enum fullness_group fullness;
1486 if (unlikely(!handle))
1490 obj = handle_to_obj(handle);
1491 obj_to_location(obj, &f_page, &f_objidx);
1492 first_page = get_first_page(f_page);
1494 get_zspage_mapping(first_page, &class_idx, &fullness);
1495 class = pool->size_class[class_idx];
1497 spin_lock(&class->lock);
1498 obj_free(pool, class, obj);
1499 fullness = fix_fullness_group(class, first_page);
1500 if (fullness == ZS_EMPTY) {
1501 zs_stat_dec(class, OBJ_ALLOCATED, get_maxobj_per_zspage(
1502 class->size, class->pages_per_zspage));
1503 atomic_long_sub(class->pages_per_zspage,
1504 &pool->pages_allocated);
1505 free_zspage(first_page);
1507 spin_unlock(&class->lock);
1510 free_handle(pool, handle);
1512 EXPORT_SYMBOL_GPL(zs_free);
1514 static void zs_object_copy(unsigned long src, unsigned long dst,
1515 struct size_class *class)
1517 struct page *s_page, *d_page;
1518 unsigned long s_objidx, d_objidx;
1519 unsigned long s_off, d_off;
1520 void *s_addr, *d_addr;
1521 int s_size, d_size, size;
1524 s_size = d_size = class->size;
1526 obj_to_location(src, &s_page, &s_objidx);
1527 obj_to_location(dst, &d_page, &d_objidx);
1529 s_off = obj_idx_to_offset(s_page, s_objidx, class->size);
1530 d_off = obj_idx_to_offset(d_page, d_objidx, class->size);
1532 if (s_off + class->size > PAGE_SIZE)
1533 s_size = PAGE_SIZE - s_off;
1535 if (d_off + class->size > PAGE_SIZE)
1536 d_size = PAGE_SIZE - d_off;
1538 s_addr = kmap_atomic(s_page);
1539 d_addr = kmap_atomic(d_page);
1542 size = min(s_size, d_size);
1543 memcpy(d_addr + d_off, s_addr + s_off, size);
1546 if (written == class->size)
1549 if (s_off + size >= PAGE_SIZE) {
1550 kunmap_atomic(d_addr);
1551 kunmap_atomic(s_addr);
1552 s_page = get_next_page(s_page);
1554 s_addr = kmap_atomic(s_page);
1555 d_addr = kmap_atomic(d_page);
1556 s_size = class->size - written;
1563 if (d_off + size >= PAGE_SIZE) {
1564 kunmap_atomic(d_addr);
1565 d_page = get_next_page(d_page);
1567 d_addr = kmap_atomic(d_page);
1568 d_size = class->size - written;
1576 kunmap_atomic(d_addr);
1577 kunmap_atomic(s_addr);
1581 * Find alloced object in zspage from index object and
1584 static unsigned long find_alloced_obj(struct page *page, int index,
1585 struct size_class *class)
1589 unsigned long handle = 0;
1590 void *addr = kmap_atomic(page);
1592 if (!is_first_page(page))
1593 offset = page->index;
1594 offset += class->size * index;
1596 while (offset < PAGE_SIZE) {
1597 head = obj_to_head(class, page, addr + offset);
1598 if (head & OBJ_ALLOCATED_TAG) {
1599 handle = head & ~OBJ_ALLOCATED_TAG;
1600 if (trypin_tag(handle))
1605 offset += class->size;
1609 kunmap_atomic(addr);
1613 struct zs_compact_control {
1614 /* Source page for migration which could be a subpage of zspage. */
1615 struct page *s_page;
1616 /* Destination page for migration which should be a first page
1618 struct page *d_page;
1619 /* Starting object index within @s_page which used for live object
1620 * in the subpage. */
1622 /* how many of objects are migrated */
1626 static int migrate_zspage(struct zs_pool *pool, struct size_class *class,
1627 struct zs_compact_control *cc)
1629 unsigned long used_obj, free_obj;
1630 unsigned long handle;
1631 struct page *s_page = cc->s_page;
1632 struct page *d_page = cc->d_page;
1633 unsigned long index = cc->index;
1634 int nr_migrated = 0;
1638 handle = find_alloced_obj(s_page, index, class);
1640 s_page = get_next_page(s_page);
1647 /* Stop if there is no more space */
1648 if (zspage_full(d_page)) {
1654 used_obj = handle_to_obj(handle);
1655 free_obj = obj_malloc(d_page, class, handle);
1656 zs_object_copy(used_obj, free_obj, class);
1658 record_obj(handle, free_obj);
1660 obj_free(pool, class, used_obj);
1664 /* Remember last position in this iteration */
1665 cc->s_page = s_page;
1667 cc->nr_migrated = nr_migrated;
1672 static struct page *alloc_target_page(struct size_class *class)
1677 for (i = 0; i < _ZS_NR_FULLNESS_GROUPS; i++) {
1678 page = class->fullness_list[i];
1680 remove_zspage(page, class, i);
1688 static void putback_zspage(struct zs_pool *pool, struct size_class *class,
1689 struct page *first_page)
1692 enum fullness_group fullness;
1694 BUG_ON(!is_first_page(first_page));
1696 get_zspage_mapping(first_page, &class_idx, &fullness);
1697 insert_zspage(first_page, class, fullness);
1698 fullness = fix_fullness_group(class, first_page);
1699 if (fullness == ZS_EMPTY) {
1700 zs_stat_dec(class, OBJ_ALLOCATED, get_maxobj_per_zspage(
1701 class->size, class->pages_per_zspage));
1702 atomic_long_sub(class->pages_per_zspage,
1703 &pool->pages_allocated);
1705 free_zspage(first_page);
1709 static struct page *isolate_source_page(struct size_class *class)
1713 page = class->fullness_list[ZS_ALMOST_EMPTY];
1715 remove_zspage(page, class, ZS_ALMOST_EMPTY);
1720 static unsigned long __zs_compact(struct zs_pool *pool,
1721 struct size_class *class)
1724 struct zs_compact_control cc;
1725 struct page *src_page;
1726 struct page *dst_page = NULL;
1727 unsigned long nr_total_migrated = 0;
1731 spin_lock(&class->lock);
1732 while ((src_page = isolate_source_page(class))) {
1734 BUG_ON(!is_first_page(src_page));
1736 /* The goal is to migrate all live objects in source page */
1737 nr_to_migrate = src_page->inuse;
1739 cc.s_page = src_page;
1741 while ((dst_page = alloc_target_page(class))) {
1742 cc.d_page = dst_page;
1744 * If there is no more space in dst_page, try to
1745 * allocate another zspage.
1747 if (!migrate_zspage(pool, class, &cc))
1750 putback_zspage(pool, class, dst_page);
1751 nr_total_migrated += cc.nr_migrated;
1752 nr_to_migrate -= cc.nr_migrated;
1755 /* Stop if we couldn't find slot */
1756 if (dst_page == NULL)
1759 putback_zspage(pool, class, dst_page);
1760 putback_zspage(pool, class, src_page);
1761 spin_unlock(&class->lock);
1762 nr_total_migrated += cc.nr_migrated;
1764 spin_lock(&class->lock);
1768 putback_zspage(pool, class, src_page);
1770 spin_unlock(&class->lock);
1772 return nr_total_migrated;
1775 unsigned long zs_compact(struct zs_pool *pool)
1778 unsigned long nr_migrated = 0;
1779 struct size_class *class;
1781 for (i = zs_size_classes - 1; i >= 0; i--) {
1782 class = pool->size_class[i];
1785 if (class->index != i)
1787 nr_migrated += __zs_compact(pool, class);
1794 EXPORT_SYMBOL_GPL(zs_compact);
1797 * zs_create_pool - Creates an allocation pool to work from.
1798 * @flags: allocation flags used to allocate pool metadata
1800 * This function must be called before anything when using
1801 * the zsmalloc allocator.
1803 * On success, a pointer to the newly created pool is returned,
1806 struct zs_pool *zs_create_pool(char *name, gfp_t flags)
1809 struct zs_pool *pool;
1810 struct size_class *prev_class = NULL;
1812 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
1816 pool->size_class = kcalloc(zs_size_classes, sizeof(struct size_class *),
1818 if (!pool->size_class) {
1823 pool->name = kstrdup(name, GFP_KERNEL);
1827 if (create_handle_cache(pool))
1831 * Iterate reversly, because, size of size_class that we want to use
1832 * for merging should be larger or equal to current size.
1834 for (i = zs_size_classes - 1; i >= 0; i--) {
1836 int pages_per_zspage;
1837 struct size_class *class;
1839 size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA;
1840 if (size > ZS_MAX_ALLOC_SIZE)
1841 size = ZS_MAX_ALLOC_SIZE;
1842 pages_per_zspage = get_pages_per_zspage(size);
1845 * size_class is used for normal zsmalloc operation such
1846 * as alloc/free for that size. Although it is natural that we
1847 * have one size_class for each size, there is a chance that we
1848 * can get more memory utilization if we use one size_class for
1849 * many different sizes whose size_class have same
1850 * characteristics. So, we makes size_class point to
1851 * previous size_class if possible.
1854 if (can_merge(prev_class, size, pages_per_zspage)) {
1855 pool->size_class[i] = prev_class;
1860 class = kzalloc(sizeof(struct size_class), GFP_KERNEL);
1866 class->pages_per_zspage = pages_per_zspage;
1867 if (pages_per_zspage == 1 &&
1868 get_maxobj_per_zspage(size, pages_per_zspage) == 1)
1870 spin_lock_init(&class->lock);
1871 pool->size_class[i] = class;
1876 pool->flags = flags;
1878 if (zs_pool_stat_create(name, pool))
1884 zs_destroy_pool(pool);
1887 EXPORT_SYMBOL_GPL(zs_create_pool);
1889 void zs_destroy_pool(struct zs_pool *pool)
1893 zs_pool_stat_destroy(pool);
1895 for (i = 0; i < zs_size_classes; i++) {
1897 struct size_class *class = pool->size_class[i];
1902 if (class->index != i)
1905 for (fg = 0; fg < _ZS_NR_FULLNESS_GROUPS; fg++) {
1906 if (class->fullness_list[fg]) {
1907 pr_info("Freeing non-empty class with size %db, fullness group %d\n",
1914 destroy_handle_cache(pool);
1915 kfree(pool->size_class);
1919 EXPORT_SYMBOL_GPL(zs_destroy_pool);
1921 static int __init zs_init(void)
1923 int ret = zs_register_cpu_notifier();
1928 init_zs_size_classes();
1931 zpool_register_driver(&zs_zpool_driver);
1934 ret = zs_stat_init();
1936 pr_err("zs stat initialization failed\n");
1943 zpool_unregister_driver(&zs_zpool_driver);
1946 zs_unregister_cpu_notifier();
1951 static void __exit zs_exit(void)
1954 zpool_unregister_driver(&zs_zpool_driver);
1956 zs_unregister_cpu_notifier();
1961 module_init(zs_init);
1962 module_exit(zs_exit);
1964 MODULE_LICENSE("Dual BSD/GPL");
1965 MODULE_AUTHOR("Nitin Gupta <ngupta@vflare.org>");