initial commit with v3.6.7
[linux-3.6.7-moxart.git] / drivers / staging / zram / zram_drv.h
blob572c0b1551d4bb2dd6c0cb9940988a57ed40ebce
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;
29 /*-- Configurable parameters */
31 /* Default zram disk size: 25% of total RAM */
32 static const unsigned default_disksize_perc_ram = 25;
35 * Pages that compress to size greater than this are stored
36 * uncompressed in memory.
38 static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
41 * NOTE: max_zpage_size must be less than or equal to:
42 * ZS_MAX_ALLOC_SIZE - sizeof(struct zobj_header)
43 * otherwise, xv_malloc() would always return failure.
46 /*-- End of configurable params */
48 #define SECTOR_SHIFT 9
49 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
50 #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
51 #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
52 #define ZRAM_LOGICAL_BLOCK_SHIFT 12
53 #define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
54 #define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
55 (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
57 /* Flags for zram pages (table[page_no].flags) */
58 enum zram_pageflags {
59 /* Page consists entirely of zeros */
60 ZRAM_ZERO,
62 __NR_ZRAM_PAGEFLAGS,
65 /*-- Data structures */
67 /* Allocated for each disk page */
68 struct table {
69 unsigned long handle;
70 u16 size; /* object size (excluding header) */
71 u8 count; /* object ref count (not yet used) */
72 u8 flags;
73 } __aligned(4);
75 struct zram_stats {
76 u64 compr_size; /* compressed size of pages stored */
77 u64 num_reads; /* failed + successful */
78 u64 num_writes; /* --do-- */
79 u64 failed_reads; /* should NEVER! happen */
80 u64 failed_writes; /* can happen when memory is too low */
81 u64 invalid_io; /* non-page-aligned I/O requests */
82 u64 notify_free; /* no. of swap slot free notifications */
83 u32 pages_zero; /* no. of zero filled pages */
84 u32 pages_stored; /* no. of pages currently stored */
85 u32 good_compress; /* % of pages with compression ratio<=50% */
86 u32 bad_compress; /* % of pages with compression ratio>=75% */
89 struct zram {
90 struct zs_pool *mem_pool;
91 void *compress_workmem;
92 void *compress_buffer;
93 struct table *table;
94 spinlock_t stat64_lock; /* protect 64-bit stats */
95 struct rw_semaphore lock; /* protect compression buffers and table
96 * against concurrent read and writes */
97 struct request_queue *queue;
98 struct gendisk *disk;
99 int init_done;
100 /* Prevent concurrent execution of device init, reset and R/W request */
101 struct rw_semaphore init_lock;
103 * This is the limit on amount of *uncompressed* worth of data
104 * we can store in a disk.
106 u64 disksize; /* bytes */
108 struct zram_stats stats;
111 extern struct zram *zram_devices;
112 unsigned int zram_get_num_devices(void);
113 #ifdef CONFIG_SYSFS
114 extern struct attribute_group zram_disk_attr_group;
115 #endif
117 extern int zram_init_device(struct zram *zram);
118 extern void __zram_reset_device(struct zram *zram);
120 #endif