0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _ZRAM_DRV_H_
0016 #define _ZRAM_DRV_H_
0017
0018 #include <linux/rwsem.h>
0019 #include <linux/zsmalloc.h>
0020 #include <linux/crypto.h>
0021
0022 #include "zcomp.h"
0023
0024 #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
0025 #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
0026 #define ZRAM_LOGICAL_BLOCK_SHIFT 12
0027 #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
0028 #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
0029 (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #define ZRAM_FLAG_SHIFT 24
0043
0044
0045 enum zram_pageflags {
0046
0047 ZRAM_LOCK = ZRAM_FLAG_SHIFT,
0048 ZRAM_SAME,
0049 ZRAM_WB,
0050 ZRAM_UNDER_WB,
0051 ZRAM_HUGE,
0052 ZRAM_IDLE,
0053
0054 __NR_ZRAM_PAGEFLAGS,
0055 };
0056
0057
0058
0059
0060 struct zram_table_entry {
0061 union {
0062 unsigned long handle;
0063 unsigned long element;
0064 };
0065 unsigned long flags;
0066 #ifdef CONFIG_ZRAM_MEMORY_TRACKING
0067 ktime_t ac_time;
0068 #endif
0069 };
0070
0071 struct zram_stats {
0072 atomic64_t compr_data_size;
0073 atomic64_t num_reads;
0074 atomic64_t num_writes;
0075 atomic64_t failed_reads;
0076 atomic64_t failed_writes;
0077 atomic64_t invalid_io;
0078 atomic64_t notify_free;
0079 atomic64_t same_pages;
0080 atomic64_t huge_pages;
0081 atomic64_t huge_pages_since;
0082 atomic64_t pages_stored;
0083 atomic_long_t max_used_pages;
0084 atomic64_t writestall;
0085 atomic64_t miss_free;
0086 #ifdef CONFIG_ZRAM_WRITEBACK
0087 atomic64_t bd_count;
0088 atomic64_t bd_reads;
0089 atomic64_t bd_writes;
0090 #endif
0091 };
0092
0093 struct zram {
0094 struct zram_table_entry *table;
0095 struct zs_pool *mem_pool;
0096 struct zcomp *comp;
0097 struct gendisk *disk;
0098
0099 struct rw_semaphore init_lock;
0100
0101
0102
0103 unsigned long limit_pages;
0104
0105 struct zram_stats stats;
0106
0107
0108
0109
0110 u64 disksize;
0111 char compressor[CRYPTO_MAX_ALG_NAME];
0112
0113
0114
0115 bool claim;
0116 #ifdef CONFIG_ZRAM_WRITEBACK
0117 struct file *backing_dev;
0118 spinlock_t wb_limit_lock;
0119 bool wb_limit_enable;
0120 u64 bd_wb_limit;
0121 struct block_device *bdev;
0122 unsigned long *bitmap;
0123 unsigned long nr_pages;
0124 #endif
0125 #ifdef CONFIG_ZRAM_MEMORY_TRACKING
0126 struct dentry *debugfs_dir;
0127 #endif
0128 };
0129 #endif