]>
Commit | Line | Data |
---|---|---|
306b0c95 | 1 | /* |
f1e3cfff | 2 | * Compressed RAM block device |
306b0c95 | 3 | * |
1130ebba | 4 | * Copyright (C) 2008, 2009, 2010 Nitin Gupta |
7bfb3de8 | 5 | * 2012, 2013 Minchan Kim |
306b0c95 NG |
6 | * |
7 | * This code is released using a dual license strategy: BSD/GPL | |
8 | * You can choose the licence that better fits your requirements. | |
9 | * | |
10 | * Released under the terms of 3-clause BSD License | |
11 | * Released under the terms of GNU General Public License Version 2.0 | |
12 | * | |
306b0c95 NG |
13 | */ |
14 | ||
f1e3cfff NG |
15 | #ifndef _ZRAM_DRV_H_ |
16 | #define _ZRAM_DRV_H_ | |
306b0c95 | 17 | |
415403be | 18 | #include <linux/rwsem.h> |
bcf1647d | 19 | #include <linux/zsmalloc.h> |
415403be | 20 | #include <linux/crypto.h> |
306b0c95 | 21 | |
b7ca232e SS |
22 | #include "zcomp.h" |
23 | ||
306b0c95 NG |
24 | /*-- Configurable parameters */ |
25 | ||
306b0c95 | 26 | /* |
306b0c95 NG |
27 | * Pages that compress to size greater than this are stored |
28 | * uncompressed in memory. | |
29 | */ | |
2ccbec05 | 30 | static const size_t max_zpage_size = PAGE_SIZE / 4 * 3; |
306b0c95 NG |
31 | |
32 | /* | |
97a06382 | 33 | * NOTE: max_zpage_size must be less than or equal to: |
55dcbbb1 MK |
34 | * ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would |
35 | * always return failure. | |
306b0c95 NG |
36 | */ |
37 | ||
38 | /*-- End of configurable params */ | |
39 | ||
40 | #define SECTOR_SHIFT 9 | |
306b0c95 NG |
41 | #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) |
42 | #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT) | |
924bd88d JM |
43 | #define ZRAM_LOGICAL_BLOCK_SHIFT 12 |
44 | #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT) | |
45 | #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \ | |
46 | (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT)) | |
306b0c95 | 47 | |
d2d5e762 WY |
48 | |
49 | /* | |
50 | * The lower ZRAM_FLAG_SHIFT bits of table.value is for | |
51 | * object size (excluding header), the higher bits is for | |
52 | * zram_pageflags. | |
53 | * | |
54 | * zram is mainly used for memory efficiency so we want to keep memory | |
55 | * footprint small so we can squeeze size and flags into a field. | |
56 | * The lower ZRAM_FLAG_SHIFT bits is for object size (excluding header), | |
57 | * the higher bits is for zram_pageflags. | |
58 | */ | |
59 | #define ZRAM_FLAG_SHIFT 24 | |
60 | ||
61 | /* Flags for zram pages (table[page_no].value) */ | |
f1e3cfff | 62 | enum zram_pageflags { |
306b0c95 | 63 | /* Page consists entirely of zeros */ |
8e19d540 | 64 | ZRAM_SAME = ZRAM_FLAG_SHIFT, |
d49b1c25 | 65 | ZRAM_ACCESS, /* page is now accessed */ |
306b0c95 | 66 | |
f1e3cfff | 67 | __NR_ZRAM_PAGEFLAGS, |
306b0c95 NG |
68 | }; |
69 | ||
70 | /*-- Data structures */ | |
71 | ||
f1e3cfff | 72 | /* Allocated for each disk page */ |
cb8f2eec | 73 | struct zram_table_entry { |
8e19d540 | 74 | union { |
75 | unsigned long handle; | |
76 | unsigned long element; | |
77 | }; | |
d2d5e762 WY |
78 | unsigned long value; |
79 | }; | |
306b0c95 | 80 | |
f1e3cfff | 81 | struct zram_stats { |
90a7806e | 82 | atomic64_t compr_data_size; /* compressed size of pages stored */ |
da5cc7d3 JL |
83 | atomic64_t num_reads; /* failed + successful */ |
84 | atomic64_t num_writes; /* --do-- */ | |
0cf1e9d6 | 85 | atomic64_t failed_reads; /* can happen when memory is too low */ |
da5cc7d3 JL |
86 | atomic64_t failed_writes; /* can happen when memory is too low */ |
87 | atomic64_t invalid_io; /* non-page-aligned I/O requests */ | |
88 | atomic64_t notify_free; /* no. of swap slot free notifications */ | |
8e19d540 | 89 | atomic64_t same_pages; /* no. of same element filled pages */ |
90a7806e | 90 | atomic64_t pages_stored; /* no. of pages currently stored */ |
461a8eee | 91 | atomic_long_t max_used_pages; /* no. of maximum pages stored */ |
623e47fc | 92 | atomic64_t writestall; /* no. of write slow paths */ |
306b0c95 NG |
93 | }; |
94 | ||
beb6602c | 95 | struct zram { |
cb8f2eec | 96 | struct zram_table_entry *table; |
8b3cc3ed | 97 | struct zs_pool *mem_pool; |
08eee69f | 98 | struct zcomp *comp; |
306b0c95 | 99 | struct gendisk *disk; |
08eee69f | 100 | /* Prevent concurrent execution of device init */ |
0900beae | 101 | struct rw_semaphore init_lock; |
306b0c95 | 102 | /* |
08eee69f | 103 | * the number of pages zram can consume for storing compressed data |
306b0c95 | 104 | */ |
08eee69f | 105 | unsigned long limit_pages; |
08eee69f | 106 | |
f1e3cfff | 107 | struct zram_stats stats; |
9ada9da9 | 108 | /* |
08eee69f MK |
109 | * This is the limit on amount of *uncompressed* worth of data |
110 | * we can store in a disk. | |
9ada9da9 | 111 | */ |
08eee69f | 112 | u64 disksize; /* bytes */ |
415403be | 113 | char compressor[CRYPTO_MAX_ALG_NAME]; |
f405c445 SS |
114 | /* |
115 | * zram is claimed so open request will be failed | |
116 | */ | |
117 | bool claim; /* Protected by bdev->bd_mutex */ | |
306b0c95 | 118 | }; |
6a907728 | 119 | #endif |