]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/block/zram/zram_drv.h
zram: add multi stream functionality
[mirror_ubuntu-artful-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
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
6a907728 18#include <linux/spinlock.h>
bcf1647d 19#include <linux/zsmalloc.h>
306b0c95 20
b7ca232e
SS
21#include "zcomp.h"
22
306b0c95
NG
23/*
24 * Some arbitrary value. This is just to catch
25 * invalid value for num_devices module parameter.
26 */
27static const unsigned max_num_devices = 32;
28
306b0c95
NG
29/*-- Configurable parameters */
30
306b0c95 31/*
306b0c95
NG
32 * Pages that compress to size greater than this are stored
33 * uncompressed in memory.
34 */
2ccbec05 35static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
306b0c95
NG
36
37/*
97a06382 38 * NOTE: max_zpage_size must be less than or equal to:
55dcbbb1
MK
39 * ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would
40 * always return failure.
306b0c95
NG
41 */
42
43/*-- End of configurable params */
44
45#define SECTOR_SHIFT 9
46#define SECTOR_SIZE (1 << SECTOR_SHIFT)
47#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
48#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
924bd88d
JM
49#define ZRAM_LOGICAL_BLOCK_SHIFT 12
50#define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
51#define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
52 (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
306b0c95 53
f1e3cfff
NG
54/* Flags for zram pages (table[page_no].flags) */
55enum zram_pageflags {
306b0c95 56 /* Page consists entirely of zeros */
f1e3cfff 57 ZRAM_ZERO,
306b0c95 58
f1e3cfff 59 __NR_ZRAM_PAGEFLAGS,
306b0c95
NG
60};
61
62/*-- Data structures */
63
f1e3cfff 64/* Allocated for each disk page */
306b0c95 65struct table {
c2344348 66 unsigned long handle;
fd1a30de 67 u16 size; /* object size (excluding header) */
306b0c95 68 u8 flags;
80677c25 69} __aligned(4);
306b0c95 70
f1e3cfff 71struct zram_stats {
90a7806e 72 atomic64_t compr_data_size; /* compressed size of pages stored */
da5cc7d3
JL
73 atomic64_t num_reads; /* failed + successful */
74 atomic64_t num_writes; /* --do-- */
75 atomic64_t failed_reads; /* should NEVER! happen */
76 atomic64_t failed_writes; /* can happen when memory is too low */
77 atomic64_t invalid_io; /* non-page-aligned I/O requests */
78 atomic64_t notify_free; /* no. of swap slot free notifications */
90a7806e
SS
79 atomic64_t zero_pages; /* no. of zero filled pages */
80 atomic64_t pages_stored; /* no. of pages currently stored */
306b0c95
NG
81};
82
8b3cc3ed 83struct zram_meta {
92967471 84 rwlock_t tb_lock; /* protect table */
306b0c95 85 struct table *table;
8b3cc3ed
MK
86 struct zs_pool *mem_pool;
87};
88
89struct zram {
90 struct zram_meta *meta;
306b0c95
NG
91 struct request_queue *queue;
92 struct gendisk *disk;
b7ca232e
SS
93 struct zcomp *comp;
94
0900beae
JM
95 /* Prevent concurrent execution of device init, reset and R/W request */
96 struct rw_semaphore init_lock;
306b0c95 97 /*
f1e3cfff
NG
98 * This is the limit on amount of *uncompressed* worth of data
99 * we can store in a disk.
306b0c95 100 */
33863c21 101 u64 disksize; /* bytes */
beca3ec7 102 int max_comp_streams;
f1e3cfff 103 struct zram_stats stats;
306b0c95 104};
6a907728 105#endif