1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #ifndef _ZRAM_DRV_H_
16 #define _ZRAM_DRV_H_
17
18 #include <linux/rwsem.h>
19 #include <linux/zsmalloc.h>
20 #include <linux/crypto.h>
21
22 #include "zcomp.h"
23
24 #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
25 #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
26 #define ZRAM_LOGICAL_BLOCK_SHIFT 12
27 #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
28 #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
29 (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
30
31
32
33
34
35
36
37
38
39
40
41
42 #define ZRAM_FLAG_SHIFT 24
43
44
45 enum zram_pageflags {
46
47 ZRAM_LOCK = ZRAM_FLAG_SHIFT,
48 ZRAM_SAME,
49 ZRAM_WB,
50 ZRAM_UNDER_WB,
51 ZRAM_HUGE,
52 ZRAM_IDLE,
53
54 __NR_ZRAM_PAGEFLAGS,
55 };
56
57
58
59
60 struct zram_table_entry {
61 union {
62 unsigned long handle;
63 unsigned long element;
64 };
65 unsigned long flags;
66 #ifdef CONFIG_ZRAM_MEMORY_TRACKING
67 ktime_t ac_time;
68 #endif
69 };
70
71 struct zram_stats {
72 atomic64_t compr_data_size;
73 atomic64_t num_reads;
74 atomic64_t num_writes;
75 atomic64_t failed_reads;
76 atomic64_t failed_writes;
77 atomic64_t invalid_io;
78 atomic64_t notify_free;
79 atomic64_t same_pages;
80 atomic64_t huge_pages;
81 atomic64_t pages_stored;
82 atomic_long_t max_used_pages;
83 atomic64_t writestall;
84 atomic64_t miss_free;
85 #ifdef CONFIG_ZRAM_WRITEBACK
86 atomic64_t bd_count;
87 atomic64_t bd_reads;
88 atomic64_t bd_writes;
89 #endif
90 };
91
92 struct zram {
93 struct zram_table_entry *table;
94 struct zs_pool *mem_pool;
95 struct zcomp *comp;
96 struct gendisk *disk;
97
98 struct rw_semaphore init_lock;
99
100
101
102 unsigned long limit_pages;
103
104 struct zram_stats stats;
105
106
107
108
109 u64 disksize;
110 char compressor[CRYPTO_MAX_ALG_NAME];
111
112
113
114 bool claim;
115 struct file *backing_dev;
116 #ifdef CONFIG_ZRAM_WRITEBACK
117 spinlock_t wb_limit_lock;
118 bool wb_limit_enable;
119 u64 bd_wb_limit;
120 struct block_device *bdev;
121 unsigned int old_block_size;
122 unsigned long *bitmap;
123 unsigned long nr_pages;
124 #endif
125 #ifdef CONFIG_ZRAM_MEMORY_TRACKING
126 struct dentry *debugfs_dir;
127 #endif
128 };
129 #endif