]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/block/zram/zram_drv.h
zram: remove old private project comment
[mirror_ubuntu-bionic-kernel.git] / drivers / block / zram / zram_drv.h
CommitLineData
306b0c95 1/*
f1e3cfff 2 * Compressed RAM block device
306b0c95 3 *
1130ebba 4 * Copyright (C) 2008, 2009, 2010 Nitin Gupta
306b0c95
NG
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 *
306b0c95
NG
12 */
13
f1e3cfff
NG
14#ifndef _ZRAM_DRV_H_
15#define _ZRAM_DRV_H_
306b0c95 16
6a907728
NG
17#include <linux/spinlock.h>
18#include <linux/mutex.h>
bcf1647d 19#include <linux/zsmalloc.h>
306b0c95
NG
20
21/*
22 * Some arbitrary value. This is just to catch
23 * invalid value for num_devices module parameter.
24 */
25static const unsigned max_num_devices = 32;
26
306b0c95
NG
27/*-- Configurable parameters */
28
306b0c95 29/*
306b0c95
NG
30 * Pages that compress to size greater than this are stored
31 * uncompressed in memory.
32 */
2ccbec05 33static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
306b0c95
NG
34
35/*
97a06382 36 * NOTE: max_zpage_size must be less than or equal to:
55dcbbb1
MK
37 * ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would
38 * always return failure.
306b0c95
NG
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)
924bd88d
JM
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))
306b0c95 51
f1e3cfff
NG
52/* Flags for zram pages (table[page_no].flags) */
53enum zram_pageflags {
306b0c95 54 /* Page consists entirely of zeros */
f1e3cfff 55 ZRAM_ZERO,
306b0c95 56
f1e3cfff 57 __NR_ZRAM_PAGEFLAGS,
306b0c95
NG
58};
59
60/*-- Data structures */
61
f1e3cfff 62/* Allocated for each disk page */
306b0c95 63struct table {
c2344348 64 unsigned long handle;
fd1a30de 65 u16 size; /* object size (excluding header) */
306b0c95
NG
66 u8 count; /* object ref count (not yet used) */
67 u8 flags;
80677c25 68} __aligned(4);
306b0c95 69
da5cc7d3
JL
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 */
f1e3cfff 74struct zram_stats {
da5cc7d3
JL
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 */
306b0c95
NG
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% */
130f315a 85 u32 bad_compress; /* % of pages with compression ratio>=75% */
306b0c95
NG
86};
87
8b3cc3ed 88struct zram_meta {
306b0c95
NG
89 void *compress_workmem;
90 void *compress_buffer;
91 struct table *table;
8b3cc3ed
MK
92 struct zs_pool *mem_pool;
93};
94
a0c516cb
MK
95struct zram_slot_free {
96 unsigned long index;
97 struct zram_slot_free *next;
98};
99
8b3cc3ed
MK
100struct zram {
101 struct zram_meta *meta;
57ab0485
JL
102 struct rw_semaphore lock; /* protect compression buffers, table,
103 * 32bit stat counters against concurrent
104 * notifications, reads and writes */
a0c516cb
MK
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
306b0c95
NG
109 struct request_queue *queue;
110 struct gendisk *disk;
111 int init_done;
0900beae
JM
112 /* Prevent concurrent execution of device init, reset and R/W request */
113 struct rw_semaphore init_lock;
306b0c95 114 /*
f1e3cfff
NG
115 * This is the limit on amount of *uncompressed* worth of data
116 * we can store in a disk.
306b0c95 117 */
33863c21 118 u64 disksize; /* bytes */
a0c516cb 119 spinlock_t slot_free_lock;
306b0c95 120
f1e3cfff 121 struct zram_stats stats;
306b0c95 122};
6a907728 123#endif