Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 1 | /* |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 2 | * Compressed RAM block device |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 3 | * |
Nitin Gupta | 1130ebb | 2010-01-28 21:21:35 +0530 | [diff] [blame] | 4 | * Copyright (C) 2008, 2009, 2010 Nitin Gupta |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 5 | * |
| 6 | * This code is released using a dual license strategy: BSD/GPL |
| 7 | * You can choose the licence that better fits your requirements. |
| 8 | * |
| 9 | * Released under the terms of 3-clause BSD License |
| 10 | * Released under the terms of GNU General Public License Version 2.0 |
| 11 | * |
| 12 | * Project home: http://compcache.googlecode.com |
| 13 | */ |
| 14 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 15 | #define KMSG_COMPONENT "zram" |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 16 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 17 | |
Robert Jennings | b1f5b81 | 2011-01-28 08:59:26 -0600 | [diff] [blame] | 18 | #ifdef CONFIG_ZRAM_DEBUG |
| 19 | #define DEBUG |
| 20 | #endif |
| 21 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
Randy Dunlap | 8946a08 | 2010-06-23 20:27:09 -0700 | [diff] [blame] | 24 | #include <linux/bio.h> |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 25 | #include <linux/bitops.h> |
| 26 | #include <linux/blkdev.h> |
| 27 | #include <linux/buffer_head.h> |
| 28 | #include <linux/device.h> |
| 29 | #include <linux/genhd.h> |
| 30 | #include <linux/highmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 32 | #include <linux/lzo.h> |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 33 | #include <linux/string.h> |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 34 | #include <linux/vmalloc.h> |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 35 | |
Nitin Gupta | 16a4bfb | 2010-06-01 13:31:24 +0530 | [diff] [blame] | 36 | #include "zram_drv.h" |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 37 | |
| 38 | /* Globals */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 39 | static int zram_major; |
Noah Watkins | 43801f6 | 2011-07-20 17:05:57 -0600 | [diff] [blame] | 40 | struct zram *zram_devices; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 41 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 42 | /* Module params (documentation at end) */ |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 43 | static unsigned int num_devices; |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 44 | |
| 45 | static void zram_stat_inc(u32 *v) |
| 46 | { |
| 47 | *v = *v + 1; |
| 48 | } |
| 49 | |
| 50 | static void zram_stat_dec(u32 *v) |
| 51 | { |
| 52 | *v = *v - 1; |
| 53 | } |
| 54 | |
| 55 | static void zram_stat64_add(struct zram *zram, u64 *v, u64 inc) |
| 56 | { |
| 57 | spin_lock(&zram->stat64_lock); |
| 58 | *v = *v + inc; |
| 59 | spin_unlock(&zram->stat64_lock); |
| 60 | } |
| 61 | |
| 62 | static void zram_stat64_sub(struct zram *zram, u64 *v, u64 dec) |
| 63 | { |
| 64 | spin_lock(&zram->stat64_lock); |
| 65 | *v = *v - dec; |
| 66 | spin_unlock(&zram->stat64_lock); |
| 67 | } |
| 68 | |
| 69 | static void zram_stat64_inc(struct zram *zram, u64 *v) |
| 70 | { |
| 71 | zram_stat64_add(zram, v, 1); |
| 72 | } |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 73 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 74 | static int zram_test_flag(struct zram *zram, u32 index, |
| 75 | enum zram_pageflags flag) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 76 | { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 77 | return zram->table[index].flags & BIT(flag); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 78 | } |
| 79 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 80 | static void zram_set_flag(struct zram *zram, u32 index, |
| 81 | enum zram_pageflags flag) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 82 | { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 83 | zram->table[index].flags |= BIT(flag); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 84 | } |
| 85 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 86 | static void zram_clear_flag(struct zram *zram, u32 index, |
| 87 | enum zram_pageflags flag) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 88 | { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 89 | zram->table[index].flags &= ~BIT(flag); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static int page_zero_filled(void *ptr) |
| 93 | { |
| 94 | unsigned int pos; |
| 95 | unsigned long *page; |
| 96 | |
| 97 | page = (unsigned long *)ptr; |
| 98 | |
| 99 | for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) { |
| 100 | if (page[pos]) |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | return 1; |
| 105 | } |
| 106 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 107 | static void zram_set_disksize(struct zram *zram, size_t totalram_bytes) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 108 | { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 109 | if (!zram->disksize) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 110 | pr_info( |
| 111 | "disk size not provided. You can use disksize_kb module " |
| 112 | "param to specify size.\nUsing default: (%u%% of RAM).\n", |
| 113 | default_disksize_perc_ram |
| 114 | ); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 115 | zram->disksize = default_disksize_perc_ram * |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 116 | (totalram_bytes / 100); |
| 117 | } |
| 118 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 119 | if (zram->disksize > 2 * (totalram_bytes)) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 120 | pr_info( |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 121 | "There is little point creating a zram of greater than " |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 122 | "twice the size of memory since we expect a 2:1 compression " |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 123 | "ratio. Note that zram uses about 0.1%% of the size of " |
| 124 | "the disk when not in use so a huge zram is " |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 125 | "wasteful.\n" |
| 126 | "\tMemory Size: %zu kB\n" |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 127 | "\tSize you selected: %llu kB\n" |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 128 | "Continuing anyway ...\n", |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 129 | totalram_bytes >> 10, zram->disksize |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 130 | ); |
| 131 | } |
| 132 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 133 | zram->disksize &= PAGE_MASK; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 134 | } |
| 135 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 136 | static void zram_free_page(struct zram *zram, size_t index) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 137 | { |
Minchan Kim | c234434 | 2012-06-08 15:39:25 +0900 | [diff] [blame] | 138 | unsigned long handle = zram->table[index].handle; |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 139 | u16 size = zram->table[index].size; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 140 | |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 141 | if (unlikely(!handle)) { |
Nitin Gupta | 2e88228 | 2010-01-28 21:13:41 +0530 | [diff] [blame] | 142 | /* |
| 143 | * No memory is allocated for zero filled pages. |
| 144 | * Simply clear zero page flag. |
| 145 | */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 146 | if (zram_test_flag(zram, index, ZRAM_ZERO)) { |
| 147 | zram_clear_flag(zram, index, ZRAM_ZERO); |
| 148 | zram_stat_dec(&zram->stats.pages_zero); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 149 | } |
| 150 | return; |
| 151 | } |
| 152 | |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 153 | if (unlikely(size > max_zpage_size)) |
| 154 | zram_stat_dec(&zram->stats.bad_compress); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 155 | |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 156 | zs_free(zram->mem_pool, handle); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 157 | |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 158 | if (size <= PAGE_SIZE / 2) |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 159 | zram_stat_dec(&zram->stats.good_compress); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 160 | |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 161 | zram_stat64_sub(zram, &zram->stats.compr_size, |
| 162 | zram->table[index].size); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 163 | zram_stat_dec(&zram->stats.pages_stored); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 164 | |
Minchan Kim | c234434 | 2012-06-08 15:39:25 +0900 | [diff] [blame] | 165 | zram->table[index].handle = 0; |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 166 | zram->table[index].size = 0; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 167 | } |
| 168 | |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 169 | static void handle_zero_page(struct bio_vec *bvec) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 170 | { |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 171 | struct page *page = bvec->bv_page; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 172 | void *user_mem; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 173 | |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 174 | user_mem = kmap_atomic(page); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 175 | memset(user_mem + bvec->bv_offset, 0, bvec->bv_len); |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 176 | kunmap_atomic(user_mem); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 177 | |
Nitin Gupta | 30fb8a7 | 2009-12-12 11:44:46 +0530 | [diff] [blame] | 178 | flush_dcache_page(page); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 179 | } |
| 180 | |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 181 | static inline int is_partial_io(struct bio_vec *bvec) |
| 182 | { |
| 183 | return bvec->bv_len != PAGE_SIZE; |
| 184 | } |
| 185 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 186 | static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 187 | u32 index, int offset, struct bio *bio) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 188 | { |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 189 | int ret; |
| 190 | size_t clen; |
| 191 | struct page *page; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 192 | unsigned char *user_mem, *cmem, *uncmem = NULL; |
Nitin Gupta | a1dd52a | 2010-06-01 13:31:23 +0530 | [diff] [blame] | 193 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 194 | page = bvec->bv_page; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 195 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 196 | if (zram_test_flag(zram, index, ZRAM_ZERO)) { |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 197 | handle_zero_page(bvec); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 198 | return 0; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 199 | } |
| 200 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 201 | /* Requested page is not present in compressed area */ |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 202 | if (unlikely(!zram->table[index].handle)) { |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 203 | pr_debug("Read before write: sector=%lu, size=%u", |
| 204 | (ulong)(bio->bi_sector), bio->bi_size); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 205 | handle_zero_page(bvec); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 206 | return 0; |
| 207 | } |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 208 | |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 209 | if (is_partial_io(bvec)) { |
| 210 | /* Use a temporary buffer to decompress the page */ |
| 211 | uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 212 | if (!uncmem) { |
| 213 | pr_info("Error allocating temp memory!\n"); |
| 214 | return -ENOMEM; |
| 215 | } |
| 216 | } |
| 217 | |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 218 | user_mem = kmap_atomic(page); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 219 | if (!is_partial_io(bvec)) |
| 220 | uncmem = user_mem; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 221 | clen = PAGE_SIZE; |
| 222 | |
Seth Jennings | b741851 | 2012-07-02 16:15:52 -0500 | [diff] [blame] | 223 | cmem = zs_map_object(zram->mem_pool, zram->table[index].handle, |
| 224 | ZS_MM_RO); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 225 | |
Nitin Gupta | c8f2f0d | 2012-10-10 17:42:18 -0700 | [diff] [blame^] | 226 | if (zram->table[index].size == PAGE_SIZE) { |
| 227 | memcpy(uncmem, cmem, PAGE_SIZE); |
| 228 | ret = LZO_E_OK; |
| 229 | } else { |
| 230 | ret = lzo1x_decompress_safe(cmem, zram->table[index].size, |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 231 | uncmem, &clen); |
Nitin Gupta | c8f2f0d | 2012-10-10 17:42:18 -0700 | [diff] [blame^] | 232 | } |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 233 | |
| 234 | if (is_partial_io(bvec)) { |
| 235 | memcpy(user_mem + bvec->bv_offset, uncmem + offset, |
| 236 | bvec->bv_len); |
| 237 | kfree(uncmem); |
| 238 | } |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 239 | |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 240 | zs_unmap_object(zram->mem_pool, zram->table[index].handle); |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 241 | kunmap_atomic(user_mem); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 242 | |
| 243 | /* Should NEVER happen. Return bio error if it does. */ |
| 244 | if (unlikely(ret != LZO_E_OK)) { |
| 245 | pr_err("Decompression failed! err=%d, page=%u\n", ret, index); |
| 246 | zram_stat64_inc(zram, &zram->stats.failed_reads); |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | flush_dcache_page(page); |
| 251 | |
| 252 | return 0; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 253 | } |
| 254 | |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 255 | static int zram_read_before_write(struct zram *zram, char *mem, u32 index) |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 256 | { |
| 257 | int ret; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 258 | size_t clen = PAGE_SIZE; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 259 | unsigned char *cmem; |
Minchan Kim | 374a691 | 2012-06-08 15:39:26 +0900 | [diff] [blame] | 260 | unsigned long handle = zram->table[index].handle; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 261 | |
Minchan Kim | 374a691 | 2012-06-08 15:39:26 +0900 | [diff] [blame] | 262 | if (zram_test_flag(zram, index, ZRAM_ZERO) || !handle) { |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 263 | memset(mem, 0, PAGE_SIZE); |
| 264 | return 0; |
| 265 | } |
| 266 | |
Seth Jennings | b741851 | 2012-07-02 16:15:52 -0500 | [diff] [blame] | 267 | cmem = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 268 | ret = lzo1x_decompress_safe(cmem, zram->table[index].size, |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 269 | mem, &clen); |
Minchan Kim | 374a691 | 2012-06-08 15:39:26 +0900 | [diff] [blame] | 270 | zs_unmap_object(zram->mem_pool, handle); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 271 | |
| 272 | /* Should NEVER happen. Return bio error if it does. */ |
| 273 | if (unlikely(ret != LZO_E_OK)) { |
| 274 | pr_err("Decompression failed! err=%d, page=%u\n", ret, index); |
| 275 | zram_stat64_inc(zram, &zram->stats.failed_reads); |
| 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index, |
| 283 | int offset) |
| 284 | { |
| 285 | int ret; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 286 | size_t clen; |
Minchan Kim | c234434 | 2012-06-08 15:39:25 +0900 | [diff] [blame] | 287 | unsigned long handle; |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 288 | struct page *page; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 289 | unsigned char *user_mem, *cmem, *src, *uncmem = NULL; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 290 | |
| 291 | page = bvec->bv_page; |
| 292 | src = zram->compress_buffer; |
| 293 | |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 294 | if (is_partial_io(bvec)) { |
| 295 | /* |
| 296 | * This is a partial IO. We need to read the full page |
| 297 | * before to write the changes. |
| 298 | */ |
| 299 | uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 300 | if (!uncmem) { |
| 301 | pr_info("Error allocating temp memory!\n"); |
| 302 | ret = -ENOMEM; |
| 303 | goto out; |
| 304 | } |
| 305 | ret = zram_read_before_write(zram, uncmem, index); |
| 306 | if (ret) { |
| 307 | kfree(uncmem); |
| 308 | goto out; |
| 309 | } |
| 310 | } |
| 311 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 312 | /* |
| 313 | * System overwrites unused sectors. Free memory associated |
| 314 | * with this sector now. |
| 315 | */ |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 316 | if (zram->table[index].handle || |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 317 | zram_test_flag(zram, index, ZRAM_ZERO)) |
| 318 | zram_free_page(zram, index); |
| 319 | |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 320 | user_mem = kmap_atomic(page); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 321 | |
| 322 | if (is_partial_io(bvec)) |
| 323 | memcpy(uncmem + offset, user_mem + bvec->bv_offset, |
| 324 | bvec->bv_len); |
| 325 | else |
| 326 | uncmem = user_mem; |
| 327 | |
| 328 | if (page_zero_filled(uncmem)) { |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 329 | kunmap_atomic(user_mem); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 330 | if (is_partial_io(bvec)) |
| 331 | kfree(uncmem); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 332 | zram_stat_inc(&zram->stats.pages_zero); |
| 333 | zram_set_flag(zram, index, ZRAM_ZERO); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 334 | ret = 0; |
| 335 | goto out; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 338 | ret = lzo1x_1_compress(uncmem, PAGE_SIZE, src, &clen, |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 339 | zram->compress_workmem); |
| 340 | |
Cong Wang | ba82fe2 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 341 | kunmap_atomic(user_mem); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 342 | if (is_partial_io(bvec)) |
| 343 | kfree(uncmem); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 344 | |
| 345 | if (unlikely(ret != LZO_E_OK)) { |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 346 | pr_err("Compression failed! err=%d\n", ret); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 347 | goto out; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Nitin Gupta | c8f2f0d | 2012-10-10 17:42:18 -0700 | [diff] [blame^] | 350 | if (unlikely(clen > max_zpage_size)) { |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 351 | zram_stat_inc(&zram->stats.bad_compress); |
Nitin Gupta | c8f2f0d | 2012-10-10 17:42:18 -0700 | [diff] [blame^] | 352 | src = uncmem; |
| 353 | clen = PAGE_SIZE; |
| 354 | } |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 355 | |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 356 | handle = zs_malloc(zram->mem_pool, clen); |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 357 | if (!handle) { |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 358 | pr_info("Error allocating memory for compressed " |
| 359 | "page: %u, size=%zu\n", index, clen); |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 360 | ret = -ENOMEM; |
| 361 | goto out; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 362 | } |
Seth Jennings | b741851 | 2012-07-02 16:15:52 -0500 | [diff] [blame] | 363 | cmem = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 364 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 365 | memcpy(cmem, src, clen); |
| 366 | |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 367 | zs_unmap_object(zram->mem_pool, handle); |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 368 | |
| 369 | zram->table[index].handle = handle; |
| 370 | zram->table[index].size = clen; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 371 | |
| 372 | /* Update stats */ |
| 373 | zram_stat64_add(zram, &zram->stats.compr_size, clen); |
| 374 | zram_stat_inc(&zram->stats.pages_stored); |
| 375 | if (clen <= PAGE_SIZE / 2) |
| 376 | zram_stat_inc(&zram->stats.good_compress); |
| 377 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 378 | return 0; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 379 | |
| 380 | out: |
| 381 | if (ret) |
| 382 | zram_stat64_inc(zram, &zram->stats.failed_writes); |
| 383 | return ret; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 387 | int offset, struct bio *bio, int rw) |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 388 | { |
Jerome Marchand | c5bde23 | 2011-06-10 15:28:49 +0200 | [diff] [blame] | 389 | int ret; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 390 | |
Jerome Marchand | c5bde23 | 2011-06-10 15:28:49 +0200 | [diff] [blame] | 391 | if (rw == READ) { |
| 392 | down_read(&zram->lock); |
| 393 | ret = zram_bvec_read(zram, bvec, index, offset, bio); |
| 394 | up_read(&zram->lock); |
| 395 | } else { |
| 396 | down_write(&zram->lock); |
| 397 | ret = zram_bvec_write(zram, bvec, index, offset); |
| 398 | up_write(&zram->lock); |
| 399 | } |
| 400 | |
| 401 | return ret; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static void update_position(u32 *index, int *offset, struct bio_vec *bvec) |
| 405 | { |
| 406 | if (*offset + bvec->bv_len >= PAGE_SIZE) |
| 407 | (*index)++; |
| 408 | *offset = (*offset + bvec->bv_len) % PAGE_SIZE; |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void __zram_make_request(struct zram *zram, struct bio *bio, int rw) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 412 | { |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 413 | int i, offset; |
Nitin Gupta | a1dd52a | 2010-06-01 13:31:23 +0530 | [diff] [blame] | 414 | u32 index; |
| 415 | struct bio_vec *bvec; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 416 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 417 | switch (rw) { |
| 418 | case READ: |
| 419 | zram_stat64_inc(zram, &zram->stats.num_reads); |
| 420 | break; |
| 421 | case WRITE: |
| 422 | zram_stat64_inc(zram, &zram->stats.num_writes); |
| 423 | break; |
| 424 | } |
| 425 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 426 | index = bio->bi_sector >> SECTORS_PER_PAGE_SHIFT; |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 427 | offset = (bio->bi_sector & (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 428 | |
Nitin Gupta | a1dd52a | 2010-06-01 13:31:23 +0530 | [diff] [blame] | 429 | bio_for_each_segment(bvec, bio, i) { |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 430 | int max_transfer_size = PAGE_SIZE - offset; |
| 431 | |
| 432 | if (bvec->bv_len > max_transfer_size) { |
| 433 | /* |
| 434 | * zram_bvec_rw() can only make operation on a single |
| 435 | * zram page. Split the bio vector. |
| 436 | */ |
| 437 | struct bio_vec bv; |
| 438 | |
| 439 | bv.bv_page = bvec->bv_page; |
| 440 | bv.bv_len = max_transfer_size; |
| 441 | bv.bv_offset = bvec->bv_offset; |
| 442 | |
| 443 | if (zram_bvec_rw(zram, &bv, index, offset, bio, rw) < 0) |
| 444 | goto out; |
| 445 | |
| 446 | bv.bv_len = bvec->bv_len - max_transfer_size; |
| 447 | bv.bv_offset += max_transfer_size; |
| 448 | if (zram_bvec_rw(zram, &bv, index+1, 0, bio, rw) < 0) |
| 449 | goto out; |
| 450 | } else |
| 451 | if (zram_bvec_rw(zram, bvec, index, offset, bio, rw) |
| 452 | < 0) |
| 453 | goto out; |
| 454 | |
| 455 | update_position(&index, &offset, bvec); |
Nitin Gupta | a1dd52a | 2010-06-01 13:31:23 +0530 | [diff] [blame] | 456 | } |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 457 | |
| 458 | set_bit(BIO_UPTODATE, &bio->bi_flags); |
| 459 | bio_endio(bio, 0); |
Nitin Gupta | 7d7854b | 2011-01-22 07:36:15 -0500 | [diff] [blame] | 460 | return; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 461 | |
| 462 | out: |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 463 | bio_io_error(bio); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 464 | } |
| 465 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 466 | /* |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 467 | * Check if request is within bounds and aligned on zram logical blocks. |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 468 | */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 469 | static inline int valid_io_request(struct zram *zram, struct bio *bio) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 470 | { |
| 471 | if (unlikely( |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 472 | (bio->bi_sector >= (zram->disksize >> SECTOR_SHIFT)) || |
Jerome Marchand | 924bd88 | 2011-06-10 15:28:48 +0200 | [diff] [blame] | 473 | (bio->bi_sector & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)) || |
| 474 | (bio->bi_size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Nitin Gupta | a1dd52a | 2010-06-01 13:31:23 +0530 | [diff] [blame] | 479 | /* I/O request is valid */ |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 480 | return 1; |
| 481 | } |
| 482 | |
| 483 | /* |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 484 | * Handler function for all zram I/O requests. |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 485 | */ |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 486 | static void zram_make_request(struct request_queue *queue, struct bio *bio) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 487 | { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 488 | struct zram *zram = queue->queuedata; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 489 | |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 490 | if (unlikely(!zram->init_done) && zram_init_device(zram)) |
| 491 | goto error; |
| 492 | |
| 493 | down_read(&zram->init_lock); |
| 494 | if (unlikely(!zram->init_done)) |
| 495 | goto error_unlock; |
| 496 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 497 | if (!valid_io_request(zram, bio)) { |
| 498 | zram_stat64_inc(zram, &zram->stats.invalid_io); |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 499 | goto error_unlock; |
Jerome Marchand | 6642a67 | 2011-02-17 17:11:49 +0100 | [diff] [blame] | 500 | } |
| 501 | |
Jerome Marchand | 8c921b2 | 2011-06-10 15:28:47 +0200 | [diff] [blame] | 502 | __zram_make_request(zram, bio, bio_data_dir(bio)); |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 503 | up_read(&zram->init_lock); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 504 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame] | 505 | return; |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 506 | |
| 507 | error_unlock: |
| 508 | up_read(&zram->init_lock); |
| 509 | error: |
| 510 | bio_io_error(bio); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 511 | } |
| 512 | |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 513 | void __zram_reset_device(struct zram *zram) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 514 | { |
Nitin Gupta | 97a0638 | 2010-05-13 14:24:21 +0530 | [diff] [blame] | 515 | size_t index; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 516 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 517 | zram->init_done = 0; |
Nitin Gupta | 7eef753 | 2010-01-28 21:13:38 +0530 | [diff] [blame] | 518 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 519 | /* Free various per-device buffers */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 520 | kfree(zram->compress_workmem); |
| 521 | free_pages((unsigned long)zram->compress_buffer, 1); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 522 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 523 | zram->compress_workmem = NULL; |
| 524 | zram->compress_buffer = NULL; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 525 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 526 | /* Free all pages that are still in this zram device */ |
| 527 | for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) { |
Minchan Kim | c234434 | 2012-06-08 15:39:25 +0900 | [diff] [blame] | 528 | unsigned long handle = zram->table[index].handle; |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 529 | if (!handle) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 530 | continue; |
| 531 | |
Minchan Kim | 130f315 | 2012-06-08 15:39:27 +0900 | [diff] [blame] | 532 | zs_free(zram->mem_pool, handle); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 533 | } |
| 534 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 535 | vfree(zram->table); |
| 536 | zram->table = NULL; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 537 | |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 538 | zs_destroy_pool(zram->mem_pool); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 539 | zram->mem_pool = NULL; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 540 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 541 | /* Reset stats */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 542 | memset(&zram->stats, 0, sizeof(zram->stats)); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 543 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 544 | zram->disksize = 0; |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | void zram_reset_device(struct zram *zram) |
| 548 | { |
| 549 | down_write(&zram->init_lock); |
| 550 | __zram_reset_device(zram); |
| 551 | up_write(&zram->init_lock); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 552 | } |
| 553 | |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 554 | int zram_init_device(struct zram *zram) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 555 | { |
| 556 | int ret; |
| 557 | size_t num_pages; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 558 | |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 559 | down_write(&zram->init_lock); |
Nitin Gupta | 484875a | 2010-08-09 22:56:48 +0530 | [diff] [blame] | 560 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 561 | if (zram->init_done) { |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 562 | up_write(&zram->init_lock); |
Nitin Gupta | 484875a | 2010-08-09 22:56:48 +0530 | [diff] [blame] | 563 | return 0; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 564 | } |
| 565 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 566 | zram_set_disksize(zram, totalram_pages << PAGE_SHIFT); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 567 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 568 | zram->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); |
| 569 | if (!zram->compress_workmem) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 570 | pr_err("Error allocating compressor working memory!\n"); |
| 571 | ret = -ENOMEM; |
Jerome Marchand | 5a18c53 | 2011-09-06 15:02:12 +0200 | [diff] [blame] | 572 | goto fail_no_table; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 573 | } |
| 574 | |
Jerome Marchand | fb92728 | 2011-11-30 14:16:16 +0100 | [diff] [blame] | 575 | zram->compress_buffer = |
| 576 | (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 577 | if (!zram->compress_buffer) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 578 | pr_err("Error allocating compressor buffer space\n"); |
| 579 | ret = -ENOMEM; |
Jerome Marchand | 5a18c53 | 2011-09-06 15:02:12 +0200 | [diff] [blame] | 580 | goto fail_no_table; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 581 | } |
| 582 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 583 | num_pages = zram->disksize >> PAGE_SHIFT; |
Joe Perches | 5b84cc7 | 2010-11-04 20:07:59 -0700 | [diff] [blame] | 584 | zram->table = vzalloc(num_pages * sizeof(*zram->table)); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 585 | if (!zram->table) { |
| 586 | pr_err("Error allocating zram address table\n"); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 587 | ret = -ENOMEM; |
Jerome Marchand | 5a18c53 | 2011-09-06 15:02:12 +0200 | [diff] [blame] | 588 | goto fail_no_table; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 589 | } |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 590 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 591 | set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 592 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 593 | /* zram devices sort of resembles non-rotational disks */ |
| 594 | queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 595 | |
Nitin Gupta | fd1a30d | 2012-01-09 16:51:59 -0600 | [diff] [blame] | 596 | zram->mem_pool = zs_create_pool("zram", GFP_NOIO | __GFP_HIGHMEM); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 597 | if (!zram->mem_pool) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 598 | pr_err("Error creating memory pool\n"); |
| 599 | ret = -ENOMEM; |
| 600 | goto fail; |
| 601 | } |
| 602 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 603 | zram->init_done = 1; |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 604 | up_write(&zram->init_lock); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 605 | |
| 606 | pr_debug("Initialization done!\n"); |
| 607 | return 0; |
| 608 | |
Jerome Marchand | 5a18c53 | 2011-09-06 15:02:12 +0200 | [diff] [blame] | 609 | fail_no_table: |
| 610 | /* To prevent accessing table entries during cleanup */ |
| 611 | zram->disksize = 0; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 612 | fail: |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 613 | __zram_reset_device(zram); |
| 614 | up_write(&zram->init_lock); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 615 | pr_err("Initialization failed: err=%d\n", ret); |
| 616 | return ret; |
| 617 | } |
| 618 | |
Nitin Gupta | 2ccbec0 | 2011-09-09 19:01:00 -0400 | [diff] [blame] | 619 | static void zram_slot_free_notify(struct block_device *bdev, |
| 620 | unsigned long index) |
Nitin Gupta | 107c161 | 2010-05-17 11:02:44 +0530 | [diff] [blame] | 621 | { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 622 | struct zram *zram; |
Nitin Gupta | 107c161 | 2010-05-17 11:02:44 +0530 | [diff] [blame] | 623 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 624 | zram = bdev->bd_disk->private_data; |
| 625 | zram_free_page(zram, index); |
| 626 | zram_stat64_inc(zram, &zram->stats.notify_free); |
Nitin Gupta | 107c161 | 2010-05-17 11:02:44 +0530 | [diff] [blame] | 627 | } |
| 628 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 629 | static const struct block_device_operations zram_devops = { |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 630 | .swap_slot_free_notify = zram_slot_free_notify, |
Nitin Gupta | 107c161 | 2010-05-17 11:02:44 +0530 | [diff] [blame] | 631 | .owner = THIS_MODULE |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 632 | }; |
| 633 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 634 | static int create_device(struct zram *zram, int device_id) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 635 | { |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 636 | int ret = 0; |
| 637 | |
Jerome Marchand | c5bde23 | 2011-06-10 15:28:49 +0200 | [diff] [blame] | 638 | init_rwsem(&zram->lock); |
Jerome Marchand | 0900bea | 2011-09-06 15:02:11 +0200 | [diff] [blame] | 639 | init_rwsem(&zram->init_lock); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 640 | spin_lock_init(&zram->stat64_lock); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 641 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 642 | zram->queue = blk_alloc_queue(GFP_KERNEL); |
| 643 | if (!zram->queue) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 644 | pr_err("Error allocating disk queue for device %d\n", |
| 645 | device_id); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 646 | ret = -ENOMEM; |
| 647 | goto out; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 648 | } |
| 649 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 650 | blk_queue_make_request(zram->queue, zram_make_request); |
| 651 | zram->queue->queuedata = zram; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 652 | |
| 653 | /* gendisk structure */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 654 | zram->disk = alloc_disk(1); |
| 655 | if (!zram->disk) { |
| 656 | blk_cleanup_queue(zram->queue); |
Sam Hansen | 94b8435 | 2012-06-07 16:03:47 -0700 | [diff] [blame] | 657 | pr_warn("Error allocating disk structure for device %d\n", |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 658 | device_id); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 659 | ret = -ENOMEM; |
| 660 | goto out; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 661 | } |
| 662 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 663 | zram->disk->major = zram_major; |
| 664 | zram->disk->first_minor = device_id; |
| 665 | zram->disk->fops = &zram_devops; |
| 666 | zram->disk->queue = zram->queue; |
| 667 | zram->disk->private_data = zram; |
| 668 | snprintf(zram->disk->disk_name, 16, "zram%d", device_id); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 669 | |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 670 | /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 671 | set_capacity(zram->disk, 0); |
Nitin Gupta | 5d83d5a | 2010-01-28 21:13:39 +0530 | [diff] [blame] | 672 | |
Nitin Gupta | a1dd52a | 2010-06-01 13:31:23 +0530 | [diff] [blame] | 673 | /* |
| 674 | * To ensure that we always get PAGE_SIZE aligned |
| 675 | * and n*PAGE_SIZED sized I/O requests. |
| 676 | */ |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 677 | blk_queue_physical_block_size(zram->disk->queue, PAGE_SIZE); |
Robert Jennings | 7b19b8d | 2011-01-28 08:58:17 -0600 | [diff] [blame] | 678 | blk_queue_logical_block_size(zram->disk->queue, |
| 679 | ZRAM_LOGICAL_BLOCK_SIZE); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 680 | blk_queue_io_min(zram->disk->queue, PAGE_SIZE); |
| 681 | blk_queue_io_opt(zram->disk->queue, PAGE_SIZE); |
Nitin Gupta | 5d83d5a | 2010-01-28 21:13:39 +0530 | [diff] [blame] | 682 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 683 | add_disk(zram->disk); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 684 | |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 685 | ret = sysfs_create_group(&disk_to_dev(zram->disk)->kobj, |
| 686 | &zram_disk_attr_group); |
| 687 | if (ret < 0) { |
Sam Hansen | 94b8435 | 2012-06-07 16:03:47 -0700 | [diff] [blame] | 688 | pr_warn("Error creating sysfs group"); |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 689 | goto out; |
| 690 | } |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 691 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 692 | zram->init_done = 0; |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 693 | |
| 694 | out: |
| 695 | return ret; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 696 | } |
| 697 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 698 | static void destroy_device(struct zram *zram) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 699 | { |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 700 | sysfs_remove_group(&disk_to_dev(zram->disk)->kobj, |
| 701 | &zram_disk_attr_group); |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 702 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 703 | if (zram->disk) { |
| 704 | del_gendisk(zram->disk); |
| 705 | put_disk(zram->disk); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 706 | } |
| 707 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 708 | if (zram->queue) |
| 709 | blk_cleanup_queue(zram->queue); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 710 | } |
| 711 | |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 712 | unsigned int zram_get_num_devices(void) |
| 713 | { |
| 714 | return num_devices; |
| 715 | } |
| 716 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 717 | static int __init zram_init(void) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 718 | { |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 719 | int ret, dev_id; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 720 | |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 721 | if (num_devices > max_num_devices) { |
Sam Hansen | 94b8435 | 2012-06-07 16:03:47 -0700 | [diff] [blame] | 722 | pr_warn("Invalid value for num_devices: %u\n", |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 723 | num_devices); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 724 | ret = -EINVAL; |
| 725 | goto out; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 726 | } |
| 727 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 728 | zram_major = register_blkdev(0, "zram"); |
| 729 | if (zram_major <= 0) { |
Sam Hansen | 94b8435 | 2012-06-07 16:03:47 -0700 | [diff] [blame] | 730 | pr_warn("Unable to get major number\n"); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 731 | ret = -EBUSY; |
| 732 | goto out; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 733 | } |
| 734 | |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 735 | if (!num_devices) { |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 736 | pr_info("num_devices not specified. Using default: 1\n"); |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 737 | num_devices = 1; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* Allocate the device array and initialize each one */ |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 741 | pr_info("Creating %u devices ...\n", num_devices); |
| 742 | zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL); |
Noah Watkins | 43801f6 | 2011-07-20 17:05:57 -0600 | [diff] [blame] | 743 | if (!zram_devices) { |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 744 | ret = -ENOMEM; |
| 745 | goto unregister; |
| 746 | } |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 747 | |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 748 | for (dev_id = 0; dev_id < num_devices; dev_id++) { |
Noah Watkins | 43801f6 | 2011-07-20 17:05:57 -0600 | [diff] [blame] | 749 | ret = create_device(&zram_devices[dev_id], dev_id); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 750 | if (ret) |
Minchan Kim | 3bf040c | 2010-01-11 16:15:53 +0900 | [diff] [blame] | 751 | goto free_devices; |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 752 | } |
| 753 | |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 754 | return 0; |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 755 | |
Minchan Kim | 3bf040c | 2010-01-11 16:15:53 +0900 | [diff] [blame] | 756 | free_devices: |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 757 | while (dev_id) |
Noah Watkins | 43801f6 | 2011-07-20 17:05:57 -0600 | [diff] [blame] | 758 | destroy_device(&zram_devices[--dev_id]); |
| 759 | kfree(zram_devices); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 760 | unregister: |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 761 | unregister_blkdev(zram_major, "zram"); |
Nitin Gupta | de1a21a | 2010-01-28 21:13:40 +0530 | [diff] [blame] | 762 | out: |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 763 | return ret; |
| 764 | } |
| 765 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 766 | static void __exit zram_exit(void) |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 767 | { |
| 768 | int i; |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 769 | struct zram *zram; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 770 | |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 771 | for (i = 0; i < num_devices; i++) { |
Noah Watkins | 43801f6 | 2011-07-20 17:05:57 -0600 | [diff] [blame] | 772 | zram = &zram_devices[i]; |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 773 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 774 | destroy_device(zram); |
| 775 | if (zram->init_done) |
Nitin Gupta | 33863c2 | 2010-08-09 22:56:47 +0530 | [diff] [blame] | 776 | zram_reset_device(zram); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 777 | } |
| 778 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 779 | unregister_blkdev(zram_major, "zram"); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 780 | |
Noah Watkins | 43801f6 | 2011-07-20 17:05:57 -0600 | [diff] [blame] | 781 | kfree(zram_devices); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 782 | pr_debug("Cleanup done!\n"); |
| 783 | } |
| 784 | |
Nitin Gupta | 5fa5a90 | 2012-02-12 23:04:45 -0500 | [diff] [blame] | 785 | module_param(num_devices, uint, 0); |
| 786 | MODULE_PARM_DESC(num_devices, "Number of zram devices"); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 787 | |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 788 | module_init(zram_init); |
| 789 | module_exit(zram_exit); |
Nitin Gupta | 306b0c9 | 2009-09-22 10:26:53 +0530 | [diff] [blame] | 790 | |
| 791 | MODULE_LICENSE("Dual BSD/GPL"); |
| 792 | MODULE_AUTHOR("Nitin Gupta <ngupta@vflare.org>"); |
Nitin Gupta | f1e3cff | 2010-06-01 13:31:25 +0530 | [diff] [blame] | 793 | MODULE_DESCRIPTION("Compressed RAM Block Device"); |