Root/
Source at commit 6141d61bc7a710a2867192deb1d0eaac8d182cb8 created 13 years 10 months ago. By Nitin Gupta, Rename ramzswap files to zram | |
---|---|
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 "zram_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. |
35 | */ |
36 | struct zobj_header { |
37 | #if 0 |
38 | u32 table_idx; |
39 | #endif |
40 | }; |
41 | |
42 | /*-- Configurable parameters */ |
43 | |
44 | /* Default ramzswap disk size: 25% of total RAM */ |
45 | static const unsigned default_disksize_perc_ram = 25; |
46 | |
47 | /* |
48 | * Pages that compress to size greater than this are stored |
49 | * uncompressed in memory. |
50 | */ |
51 | static const unsigned max_zpage_size = PAGE_SIZE / 4 * 3; |
52 | |
53 | /* |
54 | * NOTE: max_zpage_size must be less than or equal to: |
55 | * XV_MAX_ALLOC_SIZE - sizeof(struct zobj_header) |
56 | * otherwise, xv_malloc() would always return failure. |
57 | */ |
58 | |
59 | /*-- End of configurable params */ |
60 | |
61 | #define SECTOR_SHIFT 9 |
62 | #define SECTOR_SIZE (1 << SECTOR_SHIFT) |
63 | #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) |
64 | #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT) |
65 | |
66 | /* Flags for ramzswap pages (table[page_no].flags) */ |
67 | enum rzs_pageflags { |
68 | /* Page is stored uncompressed */ |
69 | RZS_UNCOMPRESSED, |
70 | |
71 | /* Page consists entirely of zeros */ |
72 | RZS_ZERO, |
73 | |
74 | __NR_RZS_PAGEFLAGS, |
75 | }; |
76 | |
77 | /*-- Data structures */ |
78 | |
79 | /* |
80 | * Allocated for each swap slot, indexed by page no. |
81 | * These table entries must fit exactly in a page. |
82 | */ |
83 | struct table { |
84 | struct page *page; |
85 | u16 offset; |
86 | u8 count; /* object ref count (not yet used) */ |
87 | u8 flags; |
88 | } __attribute__((aligned(4))); |
89 | |
90 | struct ramzswap_stats { |
91 | /* basic stats */ |
92 | size_t compr_size; /* compressed size of pages stored - |
93 | * needed to enforce memlimit */ |
94 | /* more stats */ |
95 | #if defined(CONFIG_RAMZSWAP_STATS) |
96 | u64 num_reads; /* failed + successful */ |
97 | u64 num_writes; /* --do-- */ |
98 | u64 failed_reads; /* should NEVER! happen */ |
99 | u64 failed_writes; /* can happen when memory is too low */ |
100 | u64 invalid_io; /* non-swap I/O requests */ |
101 | u64 notify_free; /* no. of swap slot free notifications */ |
102 | u32 pages_zero; /* no. of zero filled pages */ |
103 | u32 pages_stored; /* no. of pages currently stored */ |
104 | u32 good_compress; /* % of pages with compression ratio<=50% */ |
105 | u32 pages_expand; /* % of incompressible pages */ |
106 | #endif |
107 | }; |
108 | |
109 | struct ramzswap { |
110 | struct xv_pool *mem_pool; |
111 | void *compress_workmem; |
112 | void *compress_buffer; |
113 | struct table *table; |
114 | spinlock_t stat64_lock; /* protect 64-bit stats */ |
115 | struct mutex lock; /* protect compression buffers against |
116 | * concurrent writes */ |
117 | struct request_queue *queue; |
118 | struct gendisk *disk; |
119 | int init_done; |
120 | /* |
121 | * This is limit on amount of *uncompressed* worth of data |
122 | * we can hold. When backing swap device is provided, it is |
123 | * set equal to device size. |
124 | */ |
125 | size_t disksize; /* bytes */ |
126 | |
127 | struct ramzswap_stats stats; |
128 | }; |
129 | |
130 | /*-- */ |
131 | |
132 | /* Debugging and Stats */ |
133 | #if defined(CONFIG_RAMZSWAP_STATS) |
134 | static void rzs_stat_inc(u32 *v) |
135 | { |
136 | *v = *v + 1; |
137 | } |
138 | |
139 | static void rzs_stat_dec(u32 *v) |
140 | { |
141 | *v = *v - 1; |
142 | } |
143 | |
144 | static void rzs_stat64_inc(struct ramzswap *rzs, u64 *v) |
145 | { |
146 | spin_lock(&rzs->stat64_lock); |
147 | *v = *v + 1; |
148 | spin_unlock(&rzs->stat64_lock); |
149 | } |
150 | |
151 | static u64 rzs_stat64_read(struct ramzswap *rzs, u64 *v) |
152 | { |
153 | u64 val; |
154 | |
155 | spin_lock(&rzs->stat64_lock); |
156 | val = *v; |
157 | spin_unlock(&rzs->stat64_lock); |
158 | |
159 | return val; |
160 | } |
161 | #else |
162 | #define rzs_stat_inc(v) |
163 | #define rzs_stat_dec(v) |
164 | #define rzs_stat64_inc(r, v) |
165 | #define rzs_stat64_read(r, v) |
166 | #endif /* CONFIG_RAMZSWAP_STATS */ |
167 | |
168 | #endif |
169 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9