Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zram_drv.h
Go to the documentation of this file.
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  * Project home: http://compcache.googlecode.com
13  */
14 
15 #ifndef _ZRAM_DRV_H_
16 #define _ZRAM_DRV_H_
17 
18 #include <linux/spinlock.h>
19 #include <linux/mutex.h>
20 
21 #include "../zsmalloc/zsmalloc.h"
22 
23 /*
24  * Some arbitrary value. This is just to catch
25  * invalid value for num_devices module parameter.
26  */
27 static const unsigned max_num_devices = 32;
28 
29 /*-- Configurable parameters */
30 
31 /* Default zram disk size: 25% of total RAM */
32 static const unsigned default_disksize_perc_ram = 25;
33 
34 /*
35  * Pages that compress to size greater than this are stored
36  * uncompressed in memory.
37  */
38 static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
39 
40 /*
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.
44  */
45 
46 /*-- End of configurable params */
47 
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))
56 
57 /* Flags for zram pages (table[page_no].flags) */
59  /* Page consists entirely of zeros */
61 
63 };
64 
65 /*-- Data structures */
66 
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) */
73 } __aligned(4);
74 
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% */
87 };
88 
89 struct zram {
90  struct zs_pool *mem_pool;
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 */
98  struct gendisk *disk;
99  int init_done;
100  /* Prevent concurrent execution of device init, reset and R/W request */
102  /*
103  * This is the limit on amount of *uncompressed* worth of data
104  * we can store in a disk.
105  */
106  u64 disksize; /* bytes */
107 
109 };
110 
111 extern struct zram *zram_devices;
112 unsigned int zram_get_num_devices(void);
113 #ifdef CONFIG_SYSFS
115 #endif
116 
117 extern int zram_init_device(struct zram *zram);
118 extern void __zram_reset_device(struct zram *zram);
119 
120 #endif