On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / drivers / staging / ramzswap / ramzswap_drv.h
bloba6ea240935b66eb9459fb3e1d5f86d88dcced46e
1 /*
2 * Compressed RAM based swap device
4 * Copyright (C) 2008, 2009 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 _RAMZSWAP_DRV_H_
16 #define _RAMZSWAP_DRV_H_
18 #include "ramzswap_ioctl.h"
19 #include "xvmalloc.h"
22 * Some arbitrary value. This is just to catch
23 * invalid value for num_devices module parameter.
25 static const unsigned max_num_devices = 32;
28 * Stored at beginning of each compressed object.
30 * It stores back-reference to table entry which points to this
31 * object. This is required to support memory defragmentation or
32 * migrating compressed pages to backing swap disk.
34 struct zobj_header {
35 #if 0
36 u32 table_idx;
37 #endif
40 /*-- Configurable parameters */
42 /* Default ramzswap disk size: 25% of total RAM */
43 static const unsigned default_disksize_perc_ram = 25;
44 static const unsigned default_memlimit_perc_ram = 15;
47 * Max compressed page size when backing device is provided.
48 * Pages that compress to size greater than this are sent to
49 * physical swap disk.
51 static const unsigned max_zpage_size_bdev = PAGE_SIZE / 2;
54 * Max compressed page size when there is no backing dev.
55 * Pages that compress to size greater than this are stored
56 * uncompressed in memory.
58 static const unsigned max_zpage_size_nobdev = PAGE_SIZE / 4 * 3;
61 * NOTE: max_zpage_size_{bdev,nobdev} sizes must be
62 * less than or equal to:
63 * XV_MAX_ALLOC_SIZE - sizeof(struct zobj_header)
64 * since otherwise xv_malloc would always return failure.
67 /*-- End of configurable params */
69 #define SECTOR_SHIFT 9
70 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
71 #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
72 #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
74 /* Debugging and Stats */
75 #if defined(CONFIG_RAMZSWAP_STATS)
76 #define stat_inc(stat) ((stat)++)
77 #define stat_dec(stat) ((stat)--)
78 #else
79 #define stat_inc(x)
80 #define stat_dec(x)
81 #endif
83 /* Flags for ramzswap pages (table[page_no].flags) */
84 enum rzs_pageflags {
85 /* Page is stored uncompressed */
86 RZS_UNCOMPRESSED,
88 /* Page consists entirely of zeros */
89 RZS_ZERO,
91 __NR_RZS_PAGEFLAGS,
94 /*-- Data structures */
97 * Allocated for each swap slot, indexed by page no.
98 * These table entries must fit exactly in a page.
100 struct table {
101 struct page *page;
102 u16 offset;
103 u8 count; /* object ref count (not yet used) */
104 u8 flags;
105 } __attribute__((aligned(4)));;
108 * Swap extent information in case backing swap is a regular
109 * file. These extent entries must fit exactly in a page.
111 struct ramzswap_backing_extent {
112 pgoff_t phy_pagenum;
113 pgoff_t num_pages;
114 } __attribute__((aligned(4)));
116 struct ramzswap_stats {
117 /* basic stats */
118 size_t compr_size; /* compressed size of pages stored -
119 * needed to enforce memlimit */
120 /* more stats */
121 #if defined(CONFIG_RAMZSWAP_STATS)
122 u64 num_reads; /* failed + successful */
123 u64 num_writes; /* --do-- */
124 u64 failed_reads; /* can happen when memory is too low */
125 u64 failed_writes; /* should NEVER! happen */
126 u64 invalid_io; /* non-swap I/O requests */
127 u32 pages_zero; /* no. of zero filled pages */
128 u32 pages_stored; /* no. of pages currently stored */
129 u32 good_compress; /* % of pages with compression ratio<=50% */
130 u32 pages_expand; /* % of incompressible pages */
131 u64 bdev_num_reads; /* no. of reads on backing dev */
132 u64 bdev_num_writes; /* no. of writes on backing dev */
133 #endif
136 struct ramzswap {
137 struct xv_pool *mem_pool;
138 void *compress_workmem;
139 void *compress_buffer;
140 struct table *table;
141 struct mutex lock;
142 struct request_queue *queue;
143 struct gendisk *disk;
144 int init_done;
146 * This is limit on compressed data size (stats.compr_size)
147 * Its applicable only when backing swap device is present.
149 size_t memlimit; /* bytes */
151 * This is limit on amount of *uncompressed* worth of data
152 * we can hold. When backing swap device is provided, it is
153 * set equal to device size.
155 size_t disksize; /* bytes */
157 struct ramzswap_stats stats;
159 /* backing swap device info */
160 struct ramzswap_backing_extent *curr_extent;
161 struct list_head backing_swap_extent_list;
162 unsigned long num_extents;
163 char backing_swap_name[MAX_SWAP_NAME_LEN];
164 struct block_device *backing_swap;
165 struct file *swap_file;
168 /*-- */
170 #endif