staging: zram: replace xvmalloc with zsmalloc
[linux-2.6.git] / drivers / staging / zram / zram_drv.h
blob572faa8762bb1d4b384d86e9c97c6a20cd7ff2bc
1 /*
2 * Compressed RAM block device
4 * Copyright (C) 2008, 2009, 2010 Nitin Gupta
6 * This code is released using a dual license strategy: BSD/GPL
7 * You can choose the licence that better fits your requirements.
9 * Released under the terms of 3-clause BSD License
10 * Released under the terms of GNU General Public License Version 2.0
12 * Project home: http://compcache.googlecode.com
15 #ifndef _ZRAM_DRV_H_
16 #define _ZRAM_DRV_H_
18 #include <linux/spinlock.h>
19 #include <linux/mutex.h>
21 #include "../zsmalloc/zsmalloc.h"
24 * Some arbitrary value. This is just to catch
25 * invalid value for num_devices module parameter.
27 static const unsigned max_num_devices = 32;
30 * Stored at beginning of each compressed object.
32 * It stores back-reference to table entry which points to this
33 * object. This is required to support memory defragmentation.
35 struct zobj_header {
36 #if 0
37 u32 table_idx;
38 #endif
41 /*-- Configurable parameters */
43 /* Default zram disk size: 25% of total RAM */
44 static const unsigned default_disksize_perc_ram = 25;
47 * Pages that compress to size greater than this are stored
48 * uncompressed in memory.
50 static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
53 * NOTE: max_zpage_size must be less than or equal to:
54 * ZS_MAX_ALLOC_SIZE - sizeof(struct zobj_header)
55 * otherwise, xv_malloc() would always return failure.
58 /*-- End of configurable params */
60 #define SECTOR_SHIFT 9
61 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
62 #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
63 #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
64 #define ZRAM_LOGICAL_BLOCK_SHIFT 12
65 #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
66 #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
67 (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
69 /* Flags for zram pages (table[page_no].flags) */
70 enum zram_pageflags {
71 /* Page is stored uncompressed */
72 ZRAM_UNCOMPRESSED,
74 /* Page consists entirely of zeros */
75 ZRAM_ZERO,
77 __NR_ZRAM_PAGEFLAGS,
80 /*-- Data structures */
82 /* Allocated for each disk page */
83 struct table {
84 void *handle;
85 u16 size; /* object size (excluding header) */
86 u8 count; /* object ref count (not yet used) */
87 u8 flags;
88 } __attribute__((aligned(4)));
90 struct zram_stats {
91 u64 compr_size; /* compressed size of pages stored */
92 u64 num_reads; /* failed + successful */
93 u64 num_writes; /* --do-- */
94 u64 failed_reads; /* should NEVER! happen */
95 u64 failed_writes; /* can happen when memory is too low */
96 u64 invalid_io; /* non-page-aligned I/O requests */
97 u64 notify_free; /* no. of swap slot free notifications */
98 u32 pages_zero; /* no. of zero filled pages */
99 u32 pages_stored; /* no. of pages currently stored */
100 u32 good_compress; /* % of pages with compression ratio<=50% */
101 u32 pages_expand; /* % of incompressible pages */
104 struct zram {
105 struct zs_pool *mem_pool;
106 void *compress_workmem;
107 void *compress_buffer;
108 struct table *table;
109 spinlock_t stat64_lock; /* protect 64-bit stats */
110 struct rw_semaphore lock; /* protect compression buffers and table
111 * against concurrent read and writes */
112 struct request_queue *queue;
113 struct gendisk *disk;
114 int init_done;
115 /* Prevent concurrent execution of device init, reset and R/W request */
116 struct rw_semaphore init_lock;
118 * This is the limit on amount of *uncompressed* worth of data
119 * we can store in a disk.
121 u64 disksize; /* bytes */
123 struct zram_stats stats;
126 extern struct zram *zram_devices;
127 extern unsigned int zram_num_devices;
128 #ifdef CONFIG_SYSFS
129 extern struct attribute_group zram_disk_attr_group;
130 #endif
132 extern int zram_init_device(struct zram *zram);
133 extern void __zram_reset_device(struct zram *zram);
135 #endif