2 * Compressed RAM block device
4 * Copyright (C) 2008, 2009, 2010 Nitin Gupta
5 * 2012, 2013 Minchan Kim
7 * This code is released using a dual license strategy: BSD/GPL
8 * You can choose the licence 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 #define KMSG_COMPONENT "zram"
16 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/bio.h>
21 #include <linux/bitops.h>
22 #include <linux/blkdev.h>
23 #include <linux/buffer_head.h>
24 #include <linux/device.h>
25 #include <linux/genhd.h>
26 #include <linux/highmem.h>
27 #include <linux/slab.h>
28 #include <linux/backing-dev.h>
29 #include <linux/string.h>
30 #include <linux/vmalloc.h>
31 #include <linux/err.h>
32 #include <linux/idr.h>
33 #include <linux/sysfs.h>
34 #include <linux/debugfs.h>
35 #include <linux/cpuhotplug.h>
39 static DEFINE_IDR(zram_index_idr);
40 /* idr index must be protected */
41 static DEFINE_MUTEX(zram_index_mutex);
43 static int zram_major;
44 static const char *default_compressor = "lzo";
46 /* Module params (documentation at end) */
47 static unsigned int num_devices = 1;
49 * Pages that compress to sizes equals or greater than this are stored
50 * uncompressed in memory.
52 static size_t huge_class_size;
54 static void zram_free_page(struct zram *zram, size_t index);
56 static int zram_slot_trylock(struct zram *zram, u32 index)
58 return bit_spin_trylock(ZRAM_LOCK, &zram->table[index].value);
61 static void zram_slot_lock(struct zram *zram, u32 index)
63 bit_spin_lock(ZRAM_LOCK, &zram->table[index].value);
66 static void zram_slot_unlock(struct zram *zram, u32 index)
68 bit_spin_unlock(ZRAM_LOCK, &zram->table[index].value);
71 static inline bool init_done(struct zram *zram)
73 return zram->disksize;
76 static inline bool zram_allocated(struct zram *zram, u32 index)
79 return (zram->table[index].value >> (ZRAM_FLAG_SHIFT + 1)) ||
80 zram->table[index].handle;
83 static inline struct zram *dev_to_zram(struct device *dev)
85 return (struct zram *)dev_to_disk(dev)->private_data;
88 static unsigned long zram_get_handle(struct zram *zram, u32 index)
90 return zram->table[index].handle;
93 static void zram_set_handle(struct zram *zram, u32 index, unsigned long handle)
95 zram->table[index].handle = handle;
98 /* flag operations require table entry bit_spin_lock() being held */
99 static bool zram_test_flag(struct zram *zram, u32 index,
100 enum zram_pageflags flag)
102 return zram->table[index].value & BIT(flag);
105 static void zram_set_flag(struct zram *zram, u32 index,
106 enum zram_pageflags flag)
108 zram->table[index].value |= BIT(flag);
111 static void zram_clear_flag(struct zram *zram, u32 index,
112 enum zram_pageflags flag)
114 zram->table[index].value &= ~BIT(flag);
117 static inline void zram_set_element(struct zram *zram, u32 index,
118 unsigned long element)
120 zram->table[index].element = element;
123 static unsigned long zram_get_element(struct zram *zram, u32 index)
125 return zram->table[index].element;
128 static size_t zram_get_obj_size(struct zram *zram, u32 index)
130 return zram->table[index].value & (BIT(ZRAM_FLAG_SHIFT) - 1);
133 static void zram_set_obj_size(struct zram *zram,
134 u32 index, size_t size)
136 unsigned long flags = zram->table[index].value >> ZRAM_FLAG_SHIFT;
138 zram->table[index].value = (flags << ZRAM_FLAG_SHIFT) | size;
141 #if PAGE_SIZE != 4096
142 static inline bool is_partial_io(struct bio_vec *bvec)
144 return bvec->bv_len != PAGE_SIZE;
147 static inline bool is_partial_io(struct bio_vec *bvec)
154 * Check if request is within bounds and aligned on zram logical blocks.
156 static inline bool valid_io_request(struct zram *zram,
157 sector_t start, unsigned int size)
161 /* unaligned request */
162 if (unlikely(start & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)))
164 if (unlikely(size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))
167 end = start + (size >> SECTOR_SHIFT);
168 bound = zram->disksize >> SECTOR_SHIFT;
169 /* out of range range */
170 if (unlikely(start >= bound || end > bound || start > end))
173 /* I/O request is valid */
177 static void update_position(u32 *index, int *offset, struct bio_vec *bvec)
179 *index += (*offset + bvec->bv_len) / PAGE_SIZE;
180 *offset = (*offset + bvec->bv_len) % PAGE_SIZE;
183 static inline void update_used_max(struct zram *zram,
184 const unsigned long pages)
186 unsigned long old_max, cur_max;
188 old_max = atomic_long_read(&zram->stats.max_used_pages);
193 old_max = atomic_long_cmpxchg(
194 &zram->stats.max_used_pages, cur_max, pages);
195 } while (old_max != cur_max);
198 static inline void zram_fill_page(void *ptr, unsigned long len,
201 WARN_ON_ONCE(!IS_ALIGNED(len, sizeof(unsigned long)));
202 memset_l(ptr, value, len / sizeof(unsigned long));
205 static bool page_same_filled(void *ptr, unsigned long *element)
211 page = (unsigned long *)ptr;
214 for (pos = 1; pos < PAGE_SIZE / sizeof(*page); pos++) {
215 if (val != page[pos])
224 static ssize_t initstate_show(struct device *dev,
225 struct device_attribute *attr, char *buf)
228 struct zram *zram = dev_to_zram(dev);
230 down_read(&zram->init_lock);
231 val = init_done(zram);
232 up_read(&zram->init_lock);
234 return scnprintf(buf, PAGE_SIZE, "%u\n", val);
237 static ssize_t disksize_show(struct device *dev,
238 struct device_attribute *attr, char *buf)
240 struct zram *zram = dev_to_zram(dev);
242 return scnprintf(buf, PAGE_SIZE, "%llu\n", zram->disksize);
245 static ssize_t mem_limit_store(struct device *dev,
246 struct device_attribute *attr, const char *buf, size_t len)
250 struct zram *zram = dev_to_zram(dev);
252 limit = memparse(buf, &tmp);
253 if (buf == tmp) /* no chars parsed, invalid input */
256 down_write(&zram->init_lock);
257 zram->limit_pages = PAGE_ALIGN(limit) >> PAGE_SHIFT;
258 up_write(&zram->init_lock);
263 static ssize_t mem_used_max_store(struct device *dev,
264 struct device_attribute *attr, const char *buf, size_t len)
268 struct zram *zram = dev_to_zram(dev);
270 err = kstrtoul(buf, 10, &val);
274 down_read(&zram->init_lock);
275 if (init_done(zram)) {
276 atomic_long_set(&zram->stats.max_used_pages,
277 zs_get_total_pages(zram->mem_pool));
279 up_read(&zram->init_lock);
284 #ifdef CONFIG_ZRAM_WRITEBACK
285 static bool zram_wb_enabled(struct zram *zram)
287 return zram->backing_dev;
290 static void reset_bdev(struct zram *zram)
292 struct block_device *bdev;
294 if (!zram_wb_enabled(zram))
298 if (zram->old_block_size)
299 set_blocksize(bdev, zram->old_block_size);
300 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
301 /* hope filp_close flush all of IO */
302 filp_close(zram->backing_dev, NULL);
303 zram->backing_dev = NULL;
304 zram->old_block_size = 0;
306 zram->disk->queue->backing_dev_info->capabilities |=
307 BDI_CAP_SYNCHRONOUS_IO;
308 kvfree(zram->bitmap);
312 static ssize_t backing_dev_show(struct device *dev,
313 struct device_attribute *attr, char *buf)
315 struct zram *zram = dev_to_zram(dev);
316 struct file *file = zram->backing_dev;
320 down_read(&zram->init_lock);
321 if (!zram_wb_enabled(zram)) {
322 memcpy(buf, "none\n", 5);
323 up_read(&zram->init_lock);
327 p = file_path(file, buf, PAGE_SIZE - 1);
334 memmove(buf, p, ret);
337 up_read(&zram->init_lock);
341 static ssize_t backing_dev_store(struct device *dev,
342 struct device_attribute *attr, const char *buf, size_t len)
346 struct file *backing_dev = NULL;
348 struct address_space *mapping;
349 unsigned int bitmap_sz, old_block_size = 0;
350 unsigned long nr_pages, *bitmap = NULL;
351 struct block_device *bdev = NULL;
353 struct zram *zram = dev_to_zram(dev);
355 file_name = kmalloc(PATH_MAX, GFP_KERNEL);
359 down_write(&zram->init_lock);
360 if (init_done(zram)) {
361 pr_info("Can't setup backing device for initialized device\n");
366 strlcpy(file_name, buf, PATH_MAX);
367 /* ignore trailing newline */
368 sz = strlen(file_name);
369 if (sz > 0 && file_name[sz - 1] == '\n')
370 file_name[sz - 1] = 0x00;
372 backing_dev = filp_open(file_name, O_RDWR|O_LARGEFILE, 0);
373 if (IS_ERR(backing_dev)) {
374 err = PTR_ERR(backing_dev);
379 mapping = backing_dev->f_mapping;
380 inode = mapping->host;
382 /* Support only block device in this moment */
383 if (!S_ISBLK(inode->i_mode)) {
388 bdev = bdgrab(I_BDEV(inode));
389 err = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram);
395 nr_pages = i_size_read(inode) >> PAGE_SHIFT;
396 bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long);
397 bitmap = kvzalloc(bitmap_sz, GFP_KERNEL);
403 old_block_size = block_size(bdev);
404 err = set_blocksize(bdev, PAGE_SIZE);
410 zram->old_block_size = old_block_size;
412 zram->backing_dev = backing_dev;
413 zram->bitmap = bitmap;
414 zram->nr_pages = nr_pages;
416 * With writeback feature, zram does asynchronous IO so it's no longer
417 * synchronous device so let's remove synchronous io flag. Othewise,
418 * upper layer(e.g., swap) could wait IO completion rather than
419 * (submit and return), which will cause system sluggish.
420 * Furthermore, when the IO function returns(e.g., swap_readpage),
421 * upper layer expects IO was done so it could deallocate the page
422 * freely but in fact, IO is going on so finally could cause
423 * use-after-free when the IO is really done.
425 zram->disk->queue->backing_dev_info->capabilities &=
426 ~BDI_CAP_SYNCHRONOUS_IO;
427 up_write(&zram->init_lock);
429 pr_info("setup backing device %s\n", file_name);
438 blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
441 filp_close(backing_dev, NULL);
443 up_write(&zram->init_lock);
450 static unsigned long get_entry_bdev(struct zram *zram)
452 unsigned long blk_idx = 1;
454 /* skip 0 bit to confuse zram.handle = 0 */
455 blk_idx = find_next_zero_bit(zram->bitmap, zram->nr_pages, blk_idx);
456 if (blk_idx == zram->nr_pages)
459 if (test_and_set_bit(blk_idx, zram->bitmap))
465 static void put_entry_bdev(struct zram *zram, unsigned long entry)
469 was_set = test_and_clear_bit(entry, zram->bitmap);
470 WARN_ON_ONCE(!was_set);
473 static void zram_page_end_io(struct bio *bio)
475 struct page *page = bio_first_page_all(bio);
477 page_endio(page, op_is_write(bio_op(bio)),
478 blk_status_to_errno(bio->bi_status));
483 * Returns 1 if the submission is successful.
485 static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec,
486 unsigned long entry, struct bio *parent)
490 bio = bio_alloc(GFP_ATOMIC, 1);
494 bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
495 bio_set_dev(bio, zram->bdev);
496 if (!bio_add_page(bio, bvec->bv_page, bvec->bv_len, bvec->bv_offset)) {
502 bio->bi_opf = REQ_OP_READ;
503 bio->bi_end_io = zram_page_end_io;
505 bio->bi_opf = parent->bi_opf;
506 bio_chain(bio, parent);
514 struct work_struct work;
520 #if PAGE_SIZE != 4096
521 static void zram_sync_read(struct work_struct *work)
524 struct zram_work *zw = container_of(work, struct zram_work, work);
525 struct zram *zram = zw->zram;
526 unsigned long entry = zw->entry;
527 struct bio *bio = zw->bio;
529 read_from_bdev_async(zram, &bvec, entry, bio);
533 * Block layer want one ->make_request_fn to be active at a time
534 * so if we use chained IO with parent IO in same context,
535 * it's a deadlock. To avoid, it, it uses worker thread context.
537 static int read_from_bdev_sync(struct zram *zram, struct bio_vec *bvec,
538 unsigned long entry, struct bio *bio)
540 struct zram_work work;
546 INIT_WORK_ONSTACK(&work.work, zram_sync_read);
547 queue_work(system_unbound_wq, &work.work);
548 flush_work(&work.work);
549 destroy_work_on_stack(&work.work);
554 static int read_from_bdev_sync(struct zram *zram, struct bio_vec *bvec,
555 unsigned long entry, struct bio *bio)
562 static int read_from_bdev(struct zram *zram, struct bio_vec *bvec,
563 unsigned long entry, struct bio *parent, bool sync)
566 return read_from_bdev_sync(zram, bvec, entry, parent);
568 return read_from_bdev_async(zram, bvec, entry, parent);
571 static int write_to_bdev(struct zram *zram, struct bio_vec *bvec,
572 u32 index, struct bio *parent,
573 unsigned long *pentry)
578 bio = bio_alloc(GFP_ATOMIC, 1);
582 entry = get_entry_bdev(zram);
588 bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
589 bio_set_dev(bio, zram->bdev);
590 if (!bio_add_page(bio, bvec->bv_page, bvec->bv_len,
593 put_entry_bdev(zram, entry);
598 bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
599 bio->bi_end_io = zram_page_end_io;
601 bio->bi_opf = parent->bi_opf;
602 bio_chain(bio, parent);
611 static void zram_wb_clear(struct zram *zram, u32 index)
615 zram_clear_flag(zram, index, ZRAM_WB);
616 entry = zram_get_element(zram, index);
617 zram_set_element(zram, index, 0);
618 put_entry_bdev(zram, entry);
622 static bool zram_wb_enabled(struct zram *zram) { return false; }
623 static inline void reset_bdev(struct zram *zram) {};
624 static int write_to_bdev(struct zram *zram, struct bio_vec *bvec,
625 u32 index, struct bio *parent,
626 unsigned long *pentry)
632 static int read_from_bdev(struct zram *zram, struct bio_vec *bvec,
633 unsigned long entry, struct bio *parent, bool sync)
637 static void zram_wb_clear(struct zram *zram, u32 index) {}
640 #ifdef CONFIG_ZRAM_MEMORY_TRACKING
642 static struct dentry *zram_debugfs_root;
644 static void zram_debugfs_create(void)
646 zram_debugfs_root = debugfs_create_dir("zram", NULL);
649 static void zram_debugfs_destroy(void)
651 debugfs_remove_recursive(zram_debugfs_root);
654 static void zram_accessed(struct zram *zram, u32 index)
656 zram->table[index].ac_time = ktime_get_boottime();
659 static void zram_reset_access(struct zram *zram, u32 index)
661 zram->table[index].ac_time = 0;
664 static ssize_t read_block_state(struct file *file, char __user *buf,
665 size_t count, loff_t *ppos)
668 ssize_t index, written = 0;
669 struct zram *zram = file->private_data;
670 unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
671 struct timespec64 ts;
673 kbuf = kvmalloc(count, GFP_KERNEL);
677 down_read(&zram->init_lock);
678 if (!init_done(zram)) {
679 up_read(&zram->init_lock);
684 for (index = *ppos; index < nr_pages; index++) {
687 zram_slot_lock(zram, index);
688 if (!zram_allocated(zram, index))
691 ts = ktime_to_timespec64(zram->table[index].ac_time);
692 copied = snprintf(kbuf + written, count,
693 "%12zd %12lld.%06lu %c%c%c\n",
694 index, (s64)ts.tv_sec,
695 ts.tv_nsec / NSEC_PER_USEC,
696 zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.',
697 zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.',
698 zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.');
700 if (count < copied) {
701 zram_slot_unlock(zram, index);
707 zram_slot_unlock(zram, index);
711 up_read(&zram->init_lock);
712 if (copy_to_user(buf, kbuf, written))
719 static const struct file_operations proc_zram_block_state_op = {
721 .read = read_block_state,
722 .llseek = default_llseek,
725 static void zram_debugfs_register(struct zram *zram)
727 if (!zram_debugfs_root)
730 zram->debugfs_dir = debugfs_create_dir(zram->disk->disk_name,
732 debugfs_create_file("block_state", 0400, zram->debugfs_dir,
733 zram, &proc_zram_block_state_op);
736 static void zram_debugfs_unregister(struct zram *zram)
738 debugfs_remove_recursive(zram->debugfs_dir);
741 static void zram_debugfs_create(void) {};
742 static void zram_debugfs_destroy(void) {};
743 static void zram_accessed(struct zram *zram, u32 index) {};
744 static void zram_reset_access(struct zram *zram, u32 index) {};
745 static void zram_debugfs_register(struct zram *zram) {};
746 static void zram_debugfs_unregister(struct zram *zram) {};
750 * We switched to per-cpu streams and this attr is not needed anymore.
751 * However, we will keep it around for some time, because:
752 * a) we may revert per-cpu streams in the future
753 * b) it's visible to user space and we need to follow our 2 years
754 * retirement rule; but we already have a number of 'soon to be
755 * altered' attrs, so max_comp_streams need to wait for the next
758 static ssize_t max_comp_streams_show(struct device *dev,
759 struct device_attribute *attr, char *buf)
761 return scnprintf(buf, PAGE_SIZE, "%d\n", num_online_cpus());
764 static ssize_t max_comp_streams_store(struct device *dev,
765 struct device_attribute *attr, const char *buf, size_t len)
770 static ssize_t comp_algorithm_show(struct device *dev,
771 struct device_attribute *attr, char *buf)
774 struct zram *zram = dev_to_zram(dev);
776 down_read(&zram->init_lock);
777 sz = zcomp_available_show(zram->compressor, buf);
778 up_read(&zram->init_lock);
783 static ssize_t comp_algorithm_store(struct device *dev,
784 struct device_attribute *attr, const char *buf, size_t len)
786 struct zram *zram = dev_to_zram(dev);
787 char compressor[ARRAY_SIZE(zram->compressor)];
790 strlcpy(compressor, buf, sizeof(compressor));
791 /* ignore trailing newline */
792 sz = strlen(compressor);
793 if (sz > 0 && compressor[sz - 1] == '\n')
794 compressor[sz - 1] = 0x00;
796 if (!zcomp_available_algorithm(compressor))
799 down_write(&zram->init_lock);
800 if (init_done(zram)) {
801 up_write(&zram->init_lock);
802 pr_info("Can't change algorithm for initialized device\n");
806 strcpy(zram->compressor, compressor);
807 up_write(&zram->init_lock);
811 static ssize_t compact_store(struct device *dev,
812 struct device_attribute *attr, const char *buf, size_t len)
814 struct zram *zram = dev_to_zram(dev);
816 down_read(&zram->init_lock);
817 if (!init_done(zram)) {
818 up_read(&zram->init_lock);
822 zs_compact(zram->mem_pool);
823 up_read(&zram->init_lock);
828 static ssize_t io_stat_show(struct device *dev,
829 struct device_attribute *attr, char *buf)
831 struct zram *zram = dev_to_zram(dev);
834 down_read(&zram->init_lock);
835 ret = scnprintf(buf, PAGE_SIZE,
836 "%8llu %8llu %8llu %8llu\n",
837 (u64)atomic64_read(&zram->stats.failed_reads),
838 (u64)atomic64_read(&zram->stats.failed_writes),
839 (u64)atomic64_read(&zram->stats.invalid_io),
840 (u64)atomic64_read(&zram->stats.notify_free));
841 up_read(&zram->init_lock);
846 static ssize_t mm_stat_show(struct device *dev,
847 struct device_attribute *attr, char *buf)
849 struct zram *zram = dev_to_zram(dev);
850 struct zs_pool_stats pool_stats;
851 u64 orig_size, mem_used = 0;
855 memset(&pool_stats, 0x00, sizeof(struct zs_pool_stats));
857 down_read(&zram->init_lock);
858 if (init_done(zram)) {
859 mem_used = zs_get_total_pages(zram->mem_pool);
860 zs_pool_stats(zram->mem_pool, &pool_stats);
863 orig_size = atomic64_read(&zram->stats.pages_stored);
864 max_used = atomic_long_read(&zram->stats.max_used_pages);
866 ret = scnprintf(buf, PAGE_SIZE,
867 "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu\n",
868 orig_size << PAGE_SHIFT,
869 (u64)atomic64_read(&zram->stats.compr_data_size),
870 mem_used << PAGE_SHIFT,
871 zram->limit_pages << PAGE_SHIFT,
872 max_used << PAGE_SHIFT,
873 (u64)atomic64_read(&zram->stats.same_pages),
874 pool_stats.pages_compacted,
875 (u64)atomic64_read(&zram->stats.huge_pages));
876 up_read(&zram->init_lock);
881 static ssize_t debug_stat_show(struct device *dev,
882 struct device_attribute *attr, char *buf)
885 struct zram *zram = dev_to_zram(dev);
888 down_read(&zram->init_lock);
889 ret = scnprintf(buf, PAGE_SIZE,
890 "version: %d\n%8llu %8llu\n",
892 (u64)atomic64_read(&zram->stats.writestall),
893 (u64)atomic64_read(&zram->stats.miss_free));
894 up_read(&zram->init_lock);
899 static DEVICE_ATTR_RO(io_stat);
900 static DEVICE_ATTR_RO(mm_stat);
901 static DEVICE_ATTR_RO(debug_stat);
903 static void zram_meta_free(struct zram *zram, u64 disksize)
905 size_t num_pages = disksize >> PAGE_SHIFT;
908 /* Free all pages that are still in this zram device */
909 for (index = 0; index < num_pages; index++)
910 zram_free_page(zram, index);
912 zs_destroy_pool(zram->mem_pool);
916 static bool zram_meta_alloc(struct zram *zram, u64 disksize)
920 num_pages = disksize >> PAGE_SHIFT;
921 zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
925 zram->mem_pool = zs_create_pool(zram->disk->disk_name);
926 if (!zram->mem_pool) {
931 if (!huge_class_size)
932 huge_class_size = zs_huge_class_size(zram->mem_pool);
937 * To protect concurrent access to the same index entry,
938 * caller should hold this table index entry's bit_spinlock to
939 * indicate this index entry is accessing.
941 static void zram_free_page(struct zram *zram, size_t index)
943 unsigned long handle;
945 zram_reset_access(zram, index);
947 if (zram_test_flag(zram, index, ZRAM_HUGE)) {
948 zram_clear_flag(zram, index, ZRAM_HUGE);
949 atomic64_dec(&zram->stats.huge_pages);
952 if (zram_wb_enabled(zram) && zram_test_flag(zram, index, ZRAM_WB)) {
953 zram_wb_clear(zram, index);
954 atomic64_dec(&zram->stats.pages_stored);
959 * No memory is allocated for same element filled pages.
960 * Simply clear same page flag.
962 if (zram_test_flag(zram, index, ZRAM_SAME)) {
963 zram_clear_flag(zram, index, ZRAM_SAME);
964 zram_set_element(zram, index, 0);
965 atomic64_dec(&zram->stats.same_pages);
966 atomic64_dec(&zram->stats.pages_stored);
970 handle = zram_get_handle(zram, index);
974 zs_free(zram->mem_pool, handle);
976 atomic64_sub(zram_get_obj_size(zram, index),
977 &zram->stats.compr_data_size);
978 atomic64_dec(&zram->stats.pages_stored);
980 zram_set_handle(zram, index, 0);
981 zram_set_obj_size(zram, index, 0);
984 static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,
985 struct bio *bio, bool partial_io)
988 unsigned long handle;
992 if (zram_wb_enabled(zram)) {
993 zram_slot_lock(zram, index);
994 if (zram_test_flag(zram, index, ZRAM_WB)) {
997 zram_slot_unlock(zram, index);
1000 bvec.bv_len = PAGE_SIZE;
1002 return read_from_bdev(zram, &bvec,
1003 zram_get_element(zram, index),
1006 zram_slot_unlock(zram, index);
1009 zram_slot_lock(zram, index);
1010 handle = zram_get_handle(zram, index);
1011 if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) {
1012 unsigned long value;
1015 value = handle ? zram_get_element(zram, index) : 0;
1016 mem = kmap_atomic(page);
1017 zram_fill_page(mem, PAGE_SIZE, value);
1019 zram_slot_unlock(zram, index);
1023 size = zram_get_obj_size(zram, index);
1025 src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
1026 if (size == PAGE_SIZE) {
1027 dst = kmap_atomic(page);
1028 memcpy(dst, src, PAGE_SIZE);
1032 struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp);
1034 dst = kmap_atomic(page);
1035 ret = zcomp_decompress(zstrm, src, size, dst);
1037 zcomp_stream_put(zram->comp);
1039 zs_unmap_object(zram->mem_pool, handle);
1040 zram_slot_unlock(zram, index);
1042 /* Should NEVER happen. Return bio error if it does. */
1044 pr_err("Decompression failed! err=%d, page=%u\n", ret, index);
1049 static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
1050 u32 index, int offset, struct bio *bio)
1055 page = bvec->bv_page;
1056 if (is_partial_io(bvec)) {
1057 /* Use a temporary buffer to decompress the page */
1058 page = alloc_page(GFP_NOIO|__GFP_HIGHMEM);
1063 ret = __zram_bvec_read(zram, page, index, bio, is_partial_io(bvec));
1067 if (is_partial_io(bvec)) {
1068 void *dst = kmap_atomic(bvec->bv_page);
1069 void *src = kmap_atomic(page);
1071 memcpy(dst + bvec->bv_offset, src + offset, bvec->bv_len);
1076 if (is_partial_io(bvec))
1082 static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
1083 u32 index, struct bio *bio)
1086 unsigned long alloced_pages;
1087 unsigned long handle = 0;
1088 unsigned int comp_len = 0;
1089 void *src, *dst, *mem;
1090 struct zcomp_strm *zstrm;
1091 struct page *page = bvec->bv_page;
1092 unsigned long element = 0;
1093 enum zram_pageflags flags = 0;
1094 bool allow_wb = true;
1096 mem = kmap_atomic(page);
1097 if (page_same_filled(mem, &element)) {
1099 /* Free memory associated with this sector now. */
1101 atomic64_inc(&zram->stats.same_pages);
1107 zstrm = zcomp_stream_get(zram->comp);
1108 src = kmap_atomic(page);
1109 ret = zcomp_compress(zstrm, src, &comp_len);
1112 if (unlikely(ret)) {
1113 zcomp_stream_put(zram->comp);
1114 pr_err("Compression failed! err=%d\n", ret);
1115 zs_free(zram->mem_pool, handle);
1119 if (unlikely(comp_len >= huge_class_size)) {
1120 comp_len = PAGE_SIZE;
1121 if (zram_wb_enabled(zram) && allow_wb) {
1122 zcomp_stream_put(zram->comp);
1123 ret = write_to_bdev(zram, bvec, index, bio, &element);
1130 goto compress_again;
1135 * handle allocation has 2 paths:
1136 * a) fast path is executed with preemption disabled (for
1137 * per-cpu streams) and has __GFP_DIRECT_RECLAIM bit clear,
1138 * since we can't sleep;
1139 * b) slow path enables preemption and attempts to allocate
1140 * the page with __GFP_DIRECT_RECLAIM bit set. we have to
1141 * put per-cpu compression stream and, thus, to re-do
1142 * the compression once handle is allocated.
1144 * if we have a 'non-null' handle here then we are coming
1145 * from the slow path and handle has already been allocated.
1148 handle = zs_malloc(zram->mem_pool, comp_len,
1149 __GFP_KSWAPD_RECLAIM |
1154 zcomp_stream_put(zram->comp);
1155 atomic64_inc(&zram->stats.writestall);
1156 handle = zs_malloc(zram->mem_pool, comp_len,
1157 GFP_NOIO | __GFP_HIGHMEM |
1160 goto compress_again;
1164 alloced_pages = zs_get_total_pages(zram->mem_pool);
1165 update_used_max(zram, alloced_pages);
1167 if (zram->limit_pages && alloced_pages > zram->limit_pages) {
1168 zcomp_stream_put(zram->comp);
1169 zs_free(zram->mem_pool, handle);
1173 dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO);
1175 src = zstrm->buffer;
1176 if (comp_len == PAGE_SIZE)
1177 src = kmap_atomic(page);
1178 memcpy(dst, src, comp_len);
1179 if (comp_len == PAGE_SIZE)
1182 zcomp_stream_put(zram->comp);
1183 zs_unmap_object(zram->mem_pool, handle);
1184 atomic64_add(comp_len, &zram->stats.compr_data_size);
1187 * Free memory associated with this sector
1188 * before overwriting unused sectors.
1190 zram_slot_lock(zram, index);
1191 zram_free_page(zram, index);
1193 if (comp_len == PAGE_SIZE) {
1194 zram_set_flag(zram, index, ZRAM_HUGE);
1195 atomic64_inc(&zram->stats.huge_pages);
1199 zram_set_flag(zram, index, flags);
1200 zram_set_element(zram, index, element);
1202 zram_set_handle(zram, index, handle);
1203 zram_set_obj_size(zram, index, comp_len);
1205 zram_slot_unlock(zram, index);
1208 atomic64_inc(&zram->stats.pages_stored);
1212 static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
1213 u32 index, int offset, struct bio *bio)
1216 struct page *page = NULL;
1221 if (is_partial_io(bvec)) {
1224 * This is a partial IO. We need to read the full page
1225 * before to write the changes.
1227 page = alloc_page(GFP_NOIO|__GFP_HIGHMEM);
1231 ret = __zram_bvec_read(zram, page, index, bio, true);
1235 src = kmap_atomic(bvec->bv_page);
1236 dst = kmap_atomic(page);
1237 memcpy(dst + offset, src + bvec->bv_offset, bvec->bv_len);
1242 vec.bv_len = PAGE_SIZE;
1246 ret = __zram_bvec_write(zram, &vec, index, bio);
1248 if (is_partial_io(bvec))
1254 * zram_bio_discard - handler on discard request
1255 * @index: physical block index in PAGE_SIZE units
1256 * @offset: byte offset within physical block
1258 static void zram_bio_discard(struct zram *zram, u32 index,
1259 int offset, struct bio *bio)
1261 size_t n = bio->bi_iter.bi_size;
1264 * zram manages data in physical block size units. Because logical block
1265 * size isn't identical with physical block size on some arch, we
1266 * could get a discard request pointing to a specific offset within a
1267 * certain physical block. Although we can handle this request by
1268 * reading that physiclal block and decompressing and partially zeroing
1269 * and re-compressing and then re-storing it, this isn't reasonable
1270 * because our intent with a discard request is to save memory. So
1271 * skipping this logical block is appropriate here.
1274 if (n <= (PAGE_SIZE - offset))
1277 n -= (PAGE_SIZE - offset);
1281 while (n >= PAGE_SIZE) {
1282 zram_slot_lock(zram, index);
1283 zram_free_page(zram, index);
1284 zram_slot_unlock(zram, index);
1285 atomic64_inc(&zram->stats.notify_free);
1292 * Returns errno if it has some problem. Otherwise return 0 or 1.
1293 * Returns 0 if IO request was done synchronously
1294 * Returns 1 if IO request was successfully submitted.
1296 static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
1297 int offset, unsigned int op, struct bio *bio)
1299 unsigned long start_time = jiffies;
1300 struct request_queue *q = zram->disk->queue;
1303 generic_start_io_acct(q, op, bvec->bv_len >> SECTOR_SHIFT,
1304 &zram->disk->part0);
1306 if (!op_is_write(op)) {
1307 atomic64_inc(&zram->stats.num_reads);
1308 ret = zram_bvec_read(zram, bvec, index, offset, bio);
1309 flush_dcache_page(bvec->bv_page);
1311 atomic64_inc(&zram->stats.num_writes);
1312 ret = zram_bvec_write(zram, bvec, index, offset, bio);
1315 generic_end_io_acct(q, op, &zram->disk->part0, start_time);
1317 zram_slot_lock(zram, index);
1318 zram_accessed(zram, index);
1319 zram_slot_unlock(zram, index);
1321 if (unlikely(ret < 0)) {
1322 if (!op_is_write(op))
1323 atomic64_inc(&zram->stats.failed_reads);
1325 atomic64_inc(&zram->stats.failed_writes);
1331 static void __zram_make_request(struct zram *zram, struct bio *bio)
1335 struct bio_vec bvec;
1336 struct bvec_iter iter;
1338 index = bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;
1339 offset = (bio->bi_iter.bi_sector &
1340 (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT;
1342 switch (bio_op(bio)) {
1343 case REQ_OP_DISCARD:
1344 case REQ_OP_WRITE_ZEROES:
1345 zram_bio_discard(zram, index, offset, bio);
1352 bio_for_each_segment(bvec, bio, iter) {
1353 struct bio_vec bv = bvec;
1354 unsigned int unwritten = bvec.bv_len;
1357 bv.bv_len = min_t(unsigned int, PAGE_SIZE - offset,
1359 if (zram_bvec_rw(zram, &bv, index, offset,
1360 bio_op(bio), bio) < 0)
1363 bv.bv_offset += bv.bv_len;
1364 unwritten -= bv.bv_len;
1366 update_position(&index, &offset, &bv);
1367 } while (unwritten);
1378 * Handler function for all zram I/O requests.
1380 static blk_qc_t zram_make_request(struct request_queue *queue, struct bio *bio)
1382 struct zram *zram = queue->queuedata;
1384 if (!valid_io_request(zram, bio->bi_iter.bi_sector,
1385 bio->bi_iter.bi_size)) {
1386 atomic64_inc(&zram->stats.invalid_io);
1390 __zram_make_request(zram, bio);
1391 return BLK_QC_T_NONE;
1395 return BLK_QC_T_NONE;
1398 static void zram_slot_free_notify(struct block_device *bdev,
1399 unsigned long index)
1403 zram = bdev->bd_disk->private_data;
1405 atomic64_inc(&zram->stats.notify_free);
1406 if (!zram_slot_trylock(zram, index)) {
1407 atomic64_inc(&zram->stats.miss_free);
1411 zram_free_page(zram, index);
1412 zram_slot_unlock(zram, index);
1415 static int zram_rw_page(struct block_device *bdev, sector_t sector,
1416 struct page *page, unsigned int op)
1423 if (PageTransHuge(page))
1425 zram = bdev->bd_disk->private_data;
1427 if (!valid_io_request(zram, sector, PAGE_SIZE)) {
1428 atomic64_inc(&zram->stats.invalid_io);
1433 index = sector >> SECTORS_PER_PAGE_SHIFT;
1434 offset = (sector & (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT;
1437 bv.bv_len = PAGE_SIZE;
1440 ret = zram_bvec_rw(zram, &bv, index, offset, op, NULL);
1443 * If I/O fails, just return error(ie, non-zero) without
1444 * calling page_endio.
1445 * It causes resubmit the I/O with bio request by upper functions
1446 * of rw_page(e.g., swap_readpage, __swap_writepage) and
1447 * bio->bi_end_io does things to handle the error
1448 * (e.g., SetPageError, set_page_dirty and extra works).
1450 if (unlikely(ret < 0))
1455 page_endio(page, op_is_write(op), 0);
1466 static void zram_reset_device(struct zram *zram)
1471 down_write(&zram->init_lock);
1473 zram->limit_pages = 0;
1475 if (!init_done(zram)) {
1476 up_write(&zram->init_lock);
1481 disksize = zram->disksize;
1484 set_capacity(zram->disk, 0);
1485 part_stat_set_all(&zram->disk->part0, 0);
1487 up_write(&zram->init_lock);
1488 /* I/O operation under all of CPU are done so let's free */
1489 zram_meta_free(zram, disksize);
1490 memset(&zram->stats, 0, sizeof(zram->stats));
1491 zcomp_destroy(comp);
1495 static ssize_t disksize_store(struct device *dev,
1496 struct device_attribute *attr, const char *buf, size_t len)
1500 struct zram *zram = dev_to_zram(dev);
1503 disksize = memparse(buf, NULL);
1507 down_write(&zram->init_lock);
1508 if (init_done(zram)) {
1509 pr_info("Cannot change disksize for initialized device\n");
1514 disksize = PAGE_ALIGN(disksize);
1515 if (!zram_meta_alloc(zram, disksize)) {
1520 comp = zcomp_create(zram->compressor);
1522 pr_err("Cannot initialise %s compressing backend\n",
1524 err = PTR_ERR(comp);
1529 zram->disksize = disksize;
1530 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
1532 revalidate_disk(zram->disk);
1533 up_write(&zram->init_lock);
1538 zram_meta_free(zram, disksize);
1540 up_write(&zram->init_lock);
1544 static ssize_t reset_store(struct device *dev,
1545 struct device_attribute *attr, const char *buf, size_t len)
1548 unsigned short do_reset;
1550 struct block_device *bdev;
1552 ret = kstrtou16(buf, 10, &do_reset);
1559 zram = dev_to_zram(dev);
1560 bdev = bdget_disk(zram->disk, 0);
1564 mutex_lock(&bdev->bd_mutex);
1565 /* Do not reset an active device or claimed device */
1566 if (bdev->bd_openers || zram->claim) {
1567 mutex_unlock(&bdev->bd_mutex);
1572 /* From now on, anyone can't open /dev/zram[0-9] */
1574 mutex_unlock(&bdev->bd_mutex);
1576 /* Make sure all the pending I/O are finished */
1578 zram_reset_device(zram);
1579 revalidate_disk(zram->disk);
1582 mutex_lock(&bdev->bd_mutex);
1583 zram->claim = false;
1584 mutex_unlock(&bdev->bd_mutex);
1589 static int zram_open(struct block_device *bdev, fmode_t mode)
1594 WARN_ON(!mutex_is_locked(&bdev->bd_mutex));
1596 zram = bdev->bd_disk->private_data;
1597 /* zram was claimed to reset so open request fails */
1604 static const struct block_device_operations zram_devops = {
1606 .swap_slot_free_notify = zram_slot_free_notify,
1607 .rw_page = zram_rw_page,
1608 .owner = THIS_MODULE
1611 static DEVICE_ATTR_WO(compact);
1612 static DEVICE_ATTR_RW(disksize);
1613 static DEVICE_ATTR_RO(initstate);
1614 static DEVICE_ATTR_WO(reset);
1615 static DEVICE_ATTR_WO(mem_limit);
1616 static DEVICE_ATTR_WO(mem_used_max);
1617 static DEVICE_ATTR_RW(max_comp_streams);
1618 static DEVICE_ATTR_RW(comp_algorithm);
1619 #ifdef CONFIG_ZRAM_WRITEBACK
1620 static DEVICE_ATTR_RW(backing_dev);
1623 static struct attribute *zram_disk_attrs[] = {
1624 &dev_attr_disksize.attr,
1625 &dev_attr_initstate.attr,
1626 &dev_attr_reset.attr,
1627 &dev_attr_compact.attr,
1628 &dev_attr_mem_limit.attr,
1629 &dev_attr_mem_used_max.attr,
1630 &dev_attr_max_comp_streams.attr,
1631 &dev_attr_comp_algorithm.attr,
1632 #ifdef CONFIG_ZRAM_WRITEBACK
1633 &dev_attr_backing_dev.attr,
1635 &dev_attr_io_stat.attr,
1636 &dev_attr_mm_stat.attr,
1637 &dev_attr_debug_stat.attr,
1641 static const struct attribute_group zram_disk_attr_group = {
1642 .attrs = zram_disk_attrs,
1645 static const struct attribute_group *zram_disk_attr_groups[] = {
1646 &zram_disk_attr_group,
1651 * Allocate and initialize new zram device. the function returns
1652 * '>= 0' device_id upon success, and negative value otherwise.
1654 static int zram_add(void)
1657 struct request_queue *queue;
1660 zram = kzalloc(sizeof(struct zram), GFP_KERNEL);
1664 ret = idr_alloc(&zram_index_idr, zram, 0, 0, GFP_KERNEL);
1669 init_rwsem(&zram->init_lock);
1671 queue = blk_alloc_queue(GFP_KERNEL);
1673 pr_err("Error allocating disk queue for device %d\n",
1679 blk_queue_make_request(queue, zram_make_request);
1681 /* gendisk structure */
1682 zram->disk = alloc_disk(1);
1684 pr_err("Error allocating disk structure for device %d\n",
1687 goto out_free_queue;
1690 zram->disk->major = zram_major;
1691 zram->disk->first_minor = device_id;
1692 zram->disk->fops = &zram_devops;
1693 zram->disk->queue = queue;
1694 zram->disk->queue->queuedata = zram;
1695 zram->disk->private_data = zram;
1696 snprintf(zram->disk->disk_name, 16, "zram%d", device_id);
1698 /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */
1699 set_capacity(zram->disk, 0);
1700 /* zram devices sort of resembles non-rotational disks */
1701 blk_queue_flag_set(QUEUE_FLAG_NONROT, zram->disk->queue);
1702 blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, zram->disk->queue);
1705 * To ensure that we always get PAGE_SIZE aligned
1706 * and n*PAGE_SIZED sized I/O requests.
1708 blk_queue_physical_block_size(zram->disk->queue, PAGE_SIZE);
1709 blk_queue_logical_block_size(zram->disk->queue,
1710 ZRAM_LOGICAL_BLOCK_SIZE);
1711 blk_queue_io_min(zram->disk->queue, PAGE_SIZE);
1712 blk_queue_io_opt(zram->disk->queue, PAGE_SIZE);
1713 zram->disk->queue->limits.discard_granularity = PAGE_SIZE;
1714 blk_queue_max_discard_sectors(zram->disk->queue, UINT_MAX);
1715 blk_queue_flag_set(QUEUE_FLAG_DISCARD, zram->disk->queue);
1718 * zram_bio_discard() will clear all logical blocks if logical block
1719 * size is identical with physical block size(PAGE_SIZE). But if it is
1720 * different, we will skip discarding some parts of logical blocks in
1721 * the part of the request range which isn't aligned to physical block
1722 * size. So we can't ensure that all discarded logical blocks are
1725 if (ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE)
1726 blk_queue_max_write_zeroes_sectors(zram->disk->queue, UINT_MAX);
1728 zram->disk->queue->backing_dev_info->capabilities |=
1729 (BDI_CAP_STABLE_WRITES | BDI_CAP_SYNCHRONOUS_IO);
1730 device_add_disk(NULL, zram->disk, zram_disk_attr_groups);
1732 strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
1734 zram_debugfs_register(zram);
1735 pr_info("Added device: %s\n", zram->disk->disk_name);
1739 blk_cleanup_queue(queue);
1741 idr_remove(&zram_index_idr, device_id);
1747 static int zram_remove(struct zram *zram)
1749 struct block_device *bdev;
1751 bdev = bdget_disk(zram->disk, 0);
1755 mutex_lock(&bdev->bd_mutex);
1756 if (bdev->bd_openers || zram->claim) {
1757 mutex_unlock(&bdev->bd_mutex);
1763 mutex_unlock(&bdev->bd_mutex);
1765 zram_debugfs_unregister(zram);
1767 /* Make sure all the pending I/O are finished */
1769 zram_reset_device(zram);
1772 pr_info("Removed device: %s\n", zram->disk->disk_name);
1774 del_gendisk(zram->disk);
1775 blk_cleanup_queue(zram->disk->queue);
1776 put_disk(zram->disk);
1781 /* zram-control sysfs attributes */
1784 * NOTE: hot_add attribute is not the usual read-only sysfs attribute. In a
1785 * sense that reading from this file does alter the state of your system -- it
1786 * creates a new un-initialized zram device and returns back this device's
1787 * device_id (or an error code if it fails to create a new device).
1789 static ssize_t hot_add_show(struct class *class,
1790 struct class_attribute *attr,
1795 mutex_lock(&zram_index_mutex);
1797 mutex_unlock(&zram_index_mutex);
1801 return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
1803 static CLASS_ATTR_RO(hot_add);
1805 static ssize_t hot_remove_store(struct class *class,
1806 struct class_attribute *attr,
1813 /* dev_id is gendisk->first_minor, which is `int' */
1814 ret = kstrtoint(buf, 10, &dev_id);
1820 mutex_lock(&zram_index_mutex);
1822 zram = idr_find(&zram_index_idr, dev_id);
1824 ret = zram_remove(zram);
1826 idr_remove(&zram_index_idr, dev_id);
1831 mutex_unlock(&zram_index_mutex);
1832 return ret ? ret : count;
1834 static CLASS_ATTR_WO(hot_remove);
1836 static struct attribute *zram_control_class_attrs[] = {
1837 &class_attr_hot_add.attr,
1838 &class_attr_hot_remove.attr,
1841 ATTRIBUTE_GROUPS(zram_control_class);
1843 static struct class zram_control_class = {
1844 .name = "zram-control",
1845 .owner = THIS_MODULE,
1846 .class_groups = zram_control_class_groups,
1849 static int zram_remove_cb(int id, void *ptr, void *data)
1855 static void destroy_devices(void)
1857 class_unregister(&zram_control_class);
1858 idr_for_each(&zram_index_idr, &zram_remove_cb, NULL);
1859 zram_debugfs_destroy();
1860 idr_destroy(&zram_index_idr);
1861 unregister_blkdev(zram_major, "zram");
1862 cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
1865 static int __init zram_init(void)
1869 ret = cpuhp_setup_state_multi(CPUHP_ZCOMP_PREPARE, "block/zram:prepare",
1870 zcomp_cpu_up_prepare, zcomp_cpu_dead);
1874 ret = class_register(&zram_control_class);
1876 pr_err("Unable to register zram-control class\n");
1877 cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
1881 zram_debugfs_create();
1882 zram_major = register_blkdev(0, "zram");
1883 if (zram_major <= 0) {
1884 pr_err("Unable to get major number\n");
1885 class_unregister(&zram_control_class);
1886 cpuhp_remove_multi_state(CPUHP_ZCOMP_PREPARE);
1890 while (num_devices != 0) {
1891 mutex_lock(&zram_index_mutex);
1893 mutex_unlock(&zram_index_mutex);
1906 static void __exit zram_exit(void)
1911 module_init(zram_init);
1912 module_exit(zram_exit);
1914 module_param(num_devices, uint, 0);
1915 MODULE_PARM_DESC(num_devices, "Number of pre-created zram devices");
1917 MODULE_LICENSE("Dual BSD/GPL");
1918 MODULE_AUTHOR("Nitin Gupta <ngupta@vflare.org>");
1919 MODULE_DESCRIPTION("Compressed RAM Block Device");