drm/radeon: 9800 SE has only one quadpipe
[safe/jmp/linux-2.6] / drivers / staging / ramzswap / ramzswap_drv.h
1 /*
2  * Compressed RAM based swap 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 _RAMZSWAP_DRV_H_
16 #define _RAMZSWAP_DRV_H_
17
18 #include <linux/spinlock.h>
19 #include <linux/mutex.h>
20
21 #include "ramzswap_ioctl.h"
22 #include "xvmalloc.h"
23
24 /*
25  * Some arbitrary value. This is just to catch
26  * invalid value for num_devices module parameter.
27  */
28 static const unsigned max_num_devices = 32;
29
30 /*
31  * Stored at beginning of each compressed object.
32  *
33  * It stores back-reference to table entry which points to this
34  * object. This is required to support memory defragmentation or
35  * migrating compressed pages to backing swap disk.
36  */
37 struct zobj_header {
38 #if 0
39         u32 table_idx;
40 #endif
41 };
42
43 /*-- Configurable parameters */
44
45 /* Default ramzswap disk size: 25% of total RAM */
46 static const unsigned default_disksize_perc_ram = 25;
47 static const unsigned default_memlimit_perc_ram = 15;
48
49 /*
50  * Max compressed page size when backing device is provided.
51  * Pages that compress to size greater than this are sent to
52  * physical swap disk.
53  */
54 static const unsigned max_zpage_size_bdev = PAGE_SIZE / 2;
55
56 /*
57  * Max compressed page size when there is no backing dev.
58  * Pages that compress to size greater than this are stored
59  * uncompressed in memory.
60  */
61 static const unsigned max_zpage_size_nobdev = PAGE_SIZE / 4 * 3;
62
63 /*
64  * NOTE: max_zpage_size_{bdev,nobdev} sizes must be
65  * less than or equal to:
66  *   XV_MAX_ALLOC_SIZE - sizeof(struct zobj_header)
67  * since otherwise xv_malloc would always return failure.
68  */
69
70 /*-- End of configurable params */
71
72 #define SECTOR_SHIFT            9
73 #define SECTOR_SIZE             (1 << SECTOR_SHIFT)
74 #define SECTORS_PER_PAGE_SHIFT  (PAGE_SHIFT - SECTOR_SHIFT)
75 #define SECTORS_PER_PAGE        (1 << SECTORS_PER_PAGE_SHIFT)
76
77 /* Flags for ramzswap pages (table[page_no].flags) */
78 enum rzs_pageflags {
79         /* Page is stored uncompressed */
80         RZS_UNCOMPRESSED,
81
82         /* Page consists entirely of zeros */
83         RZS_ZERO,
84
85         __NR_RZS_PAGEFLAGS,
86 };
87
88 /*-- Data structures */
89
90 /*
91  * Allocated for each swap slot, indexed by page no.
92  * These table entries must fit exactly in a page.
93  */
94 struct table {
95         struct page *page;
96         u16 offset;
97         u8 count;       /* object ref count (not yet used) */
98         u8 flags;
99 } __attribute__((aligned(4)));
100
101 /*
102  * Swap extent information in case backing swap is a regular
103  * file. These extent entries must fit exactly in a page.
104  */
105 struct ramzswap_backing_extent {
106         pgoff_t phy_pagenum;
107         pgoff_t num_pages;
108 } __attribute__((aligned(4)));
109
110 struct ramzswap_stats {
111         /* basic stats */
112         size_t compr_size;      /* compressed size of pages stored -
113                                  * needed to enforce memlimit */
114         /* more stats */
115 #if defined(CONFIG_RAMZSWAP_STATS)
116         u64 num_reads;          /* failed + successful */
117         u64 num_writes;         /* --do-- */
118         u64 failed_reads;       /* should NEVER! happen */
119         u64 failed_writes;      /* can happen when memory is too low */
120         u64 invalid_io;         /* non-swap I/O requests */
121         u64 notify_free;        /* no. of swap slot free notifications */
122         u32 pages_zero;         /* no. of zero filled pages */
123         u32 pages_stored;       /* no. of pages currently stored */
124         u32 good_compress;      /* % of pages with compression ratio<=50% */
125         u32 pages_expand;       /* % of incompressible pages */
126         u64 bdev_num_reads;     /* no. of reads on backing dev */
127         u64 bdev_num_writes;    /* no. of writes on backing dev */
128 #endif
129 };
130
131 struct ramzswap {
132         struct xv_pool *mem_pool;
133         void *compress_workmem;
134         void *compress_buffer;
135         struct table *table;
136         spinlock_t stat64_lock; /* protect 64-bit stats */
137         struct mutex lock;
138         struct request_queue *queue;
139         struct gendisk *disk;
140         int init_done;
141         /*
142          * This is limit on compressed data size (stats.compr_size)
143          * Its applicable only when backing swap device is present.
144          */
145         size_t memlimit;        /* bytes */
146         /*
147          * This is limit on amount of *uncompressed* worth of data
148          * we can hold. When backing swap device is provided, it is
149          * set equal to device size.
150          */
151         size_t disksize;        /* bytes */
152
153         struct ramzswap_stats stats;
154
155         /* backing swap device info */
156         struct ramzswap_backing_extent *curr_extent;
157         struct list_head backing_swap_extent_list;
158         unsigned long num_extents;
159         char backing_swap_name[MAX_SWAP_NAME_LEN];
160         struct block_device *backing_swap;
161         struct file *swap_file;
162 };
163
164 /*-- */
165
166 /* Debugging and Stats */
167 #if defined(CONFIG_RAMZSWAP_STATS)
168 static void rzs_stat_inc(u32 *v)
169 {
170         *v = *v + 1;
171 }
172
173 static void rzs_stat_dec(u32 *v)
174 {
175         *v = *v - 1;
176 }
177
178 static void rzs_stat64_inc(struct ramzswap *rzs, u64 *v)
179 {
180         spin_lock(&rzs->stat64_lock);
181         *v = *v + 1;
182         spin_unlock(&rzs->stat64_lock);
183 }
184
185 static void rzs_stat64_dec(struct ramzswap *rzs, u64 *v)
186 {
187         spin_lock(&rzs->stat64_lock);
188         *v = *v - 1;
189         spin_unlock(&rzs->stat64_lock);
190 }
191
192 static u64 rzs_stat64_read(struct ramzswap *rzs, u64 *v)
193 {
194         u64 val;
195
196         spin_lock(&rzs->stat64_lock);
197         val = *v;
198         spin_unlock(&rzs->stat64_lock);
199
200         return val;
201 }
202 #else
203 #define rzs_stat_inc(v)
204 #define rzs_stat_dec(v)
205 #define rzs_stat64_inc(r, v)
206 #define rzs_stat64_dec(r, v)
207 #define rzs_stat64_read(r, v)
208 #endif /* CONFIG_RAMZSWAP_STATS */
209
210 #endif