zram: remove old private project comment
[firefly-linux-kernel-4.4.55.git] / drivers / block / zram / zram_drv.h
1 /*
2  * Compressed RAM block device
3  *
4  * Copyright (C) 2008, 2009, 2010  Nitin Gupta
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  */
13
14 #ifndef _ZRAM_DRV_H_
15 #define _ZRAM_DRV_H_
16
17 #include <linux/spinlock.h>
18 #include <linux/mutex.h>
19 #include <linux/zsmalloc.h>
20
21 /*
22  * Some arbitrary value. This is just to catch
23  * invalid value for num_devices module parameter.
24  */
25 static const unsigned max_num_devices = 32;
26
27 /*-- Configurable parameters */
28
29 /*
30  * Pages that compress to size greater than this are stored
31  * uncompressed in memory.
32  */
33 static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
34
35 /*
36  * NOTE: max_zpage_size must be less than or equal to:
37  *   ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would
38  * always return failure.
39  */
40
41 /*-- End of configurable params */
42
43 #define SECTOR_SHIFT            9
44 #define SECTOR_SIZE             (1 << SECTOR_SHIFT)
45 #define SECTORS_PER_PAGE_SHIFT  (PAGE_SHIFT - SECTOR_SHIFT)
46 #define SECTORS_PER_PAGE        (1 << SECTORS_PER_PAGE_SHIFT)
47 #define ZRAM_LOGICAL_BLOCK_SHIFT 12
48 #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
49 #define ZRAM_SECTOR_PER_LOGICAL_BLOCK   \
50         (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
51
52 /* Flags for zram pages (table[page_no].flags) */
53 enum zram_pageflags {
54         /* Page consists entirely of zeros */
55         ZRAM_ZERO,
56
57         __NR_ZRAM_PAGEFLAGS,
58 };
59
60 /*-- Data structures */
61
62 /* Allocated for each disk page */
63 struct table {
64         unsigned long handle;
65         u16 size;       /* object size (excluding header) */
66         u8 count;       /* object ref count (not yet used) */
67         u8 flags;
68 } __aligned(4);
69
70 /*
71  * All 64bit fields should only be manipulated by 64bit atomic accessors.
72  * All modifications to 32bit counter should be protected by zram->lock.
73  */
74 struct zram_stats {
75         atomic64_t compr_size;  /* compressed size of pages stored */
76         atomic64_t num_reads;   /* failed + successful */
77         atomic64_t num_writes;  /* --do-- */
78         atomic64_t failed_reads;        /* should NEVER! happen */
79         atomic64_t failed_writes;       /* can happen when memory is too low */
80         atomic64_t invalid_io;  /* non-page-aligned I/O requests */
81         atomic64_t notify_free; /* no. of swap slot free notifications */
82         u32 pages_zero;         /* no. of zero filled pages */
83         u32 pages_stored;       /* no. of pages currently stored */
84         u32 good_compress;      /* % of pages with compression ratio<=50% */
85         u32 bad_compress;       /* % of pages with compression ratio>=75% */
86 };
87
88 struct zram_meta {
89         void *compress_workmem;
90         void *compress_buffer;
91         struct table *table;
92         struct zs_pool *mem_pool;
93 };
94
95 struct zram_slot_free {
96         unsigned long index;
97         struct zram_slot_free *next;
98 };
99
100 struct zram {
101         struct zram_meta *meta;
102         struct rw_semaphore lock; /* protect compression buffers, table,
103                                    * 32bit stat counters against concurrent
104                                    * notifications, reads and writes */
105
106         struct work_struct free_work;  /* handle pending free request */
107         struct zram_slot_free *slot_free_rq; /* list head of free request */
108
109         struct request_queue *queue;
110         struct gendisk *disk;
111         int init_done;
112         /* Prevent concurrent execution of device init, reset and R/W request */
113         struct rw_semaphore init_lock;
114         /*
115          * This is the limit on amount of *uncompressed* worth of data
116          * we can store in a disk.
117          */
118         u64 disksize;   /* bytes */
119         spinlock_t slot_free_lock;
120
121         struct zram_stats stats;
122 };
123 #endif