aboutsummaryrefslogtreecommitdiffstats
path: root/mm/frontswap.c
diff options
context:
space:
mode:
authorBob Liu <lliubbo@gmail.com>2013-04-30 18:26:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-30 20:04:00 -0400
commitf066ea230a65f939afc354beae62716ab5f0e645 (patch)
tree1056e57d4b0c9819c74bd929006cf352994230d2 /mm/frontswap.c
parent1e01c968db3d0aebd48e31db15f24516b03128df (diff)
mm: frontswap: cleanup code
After allowing tmem backends to build/run as modules, frontswap_enabled always true if defined CONFIG_FRONTSWAP. But frontswap_test() depends on whether backend is registered, mv it into frontswap.c using fronstswap_ops to make the decision. frontswap_set/clear are not used outside frontswap, so don't export them. Signed-off-by: Bob Liu <lliubbo@gmail.com> Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com> Cc: Andor Daam <andor.daam@googlemail.com> Cc: Dan Magenheimer <dan.magenheimer@oracle.com> Cc: Florian Schmaus <fschmaus@gmail.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Stefan Hengelein <ilendir@googlemail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/frontswap.c')
-rw-r--r--mm/frontswap.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/mm/frontswap.c b/mm/frontswap.c
index e44c9cbd1443..2760b0f98822 100644
--- a/mm/frontswap.c
+++ b/mm/frontswap.c
@@ -27,14 +27,6 @@
27static struct frontswap_ops *frontswap_ops __read_mostly; 27static struct frontswap_ops *frontswap_ops __read_mostly;
28 28
29/* 29/*
30 * This global enablement flag reduces overhead on systems where frontswap_ops
31 * has not been registered, so is preferred to the slower alternative: a
32 * function call that checks a non-global.
33 */
34bool frontswap_enabled __read_mostly;
35EXPORT_SYMBOL(frontswap_enabled);
36
37/*
38 * If enabled, frontswap_store will return failure even on success. As 30 * If enabled, frontswap_store will return failure even on success. As
39 * a result, the swap subsystem will always write the page to swap, in 31 * a result, the swap subsystem will always write the page to swap, in
40 * effect converting frontswap into a writethrough cache. In this mode, 32 * effect converting frontswap into a writethrough cache. In this mode,
@@ -128,8 +120,6 @@ struct frontswap_ops *frontswap_register_ops(struct frontswap_ops *ops)
128 struct frontswap_ops *old = frontswap_ops; 120 struct frontswap_ops *old = frontswap_ops;
129 int i; 121 int i;
130 122
131 frontswap_enabled = true;
132
133 for (i = 0; i < MAX_SWAPFILES; i++) { 123 for (i = 0; i < MAX_SWAPFILES; i++) {
134 if (test_and_clear_bit(i, need_init)) 124 if (test_and_clear_bit(i, need_init))
135 ops->init(i); 125 ops->init(i);
@@ -183,9 +173,21 @@ void __frontswap_init(unsigned type)
183} 173}
184EXPORT_SYMBOL(__frontswap_init); 174EXPORT_SYMBOL(__frontswap_init);
185 175
186static inline void __frontswap_clear(struct swap_info_struct *sis, pgoff_t offset) 176bool __frontswap_test(struct swap_info_struct *sis,
177 pgoff_t offset)
178{
179 bool ret = false;
180
181 if (frontswap_ops && sis->frontswap_map)
182 ret = test_bit(offset, sis->frontswap_map);
183 return ret;
184}
185EXPORT_SYMBOL(__frontswap_test);
186
187static inline void __frontswap_clear(struct swap_info_struct *sis,
188 pgoff_t offset)
187{ 189{
188 frontswap_clear(sis, offset); 190 clear_bit(offset, sis->frontswap_map);
189 atomic_dec(&sis->frontswap_pages); 191 atomic_dec(&sis->frontswap_pages);
190} 192}
191 193
@@ -204,18 +206,20 @@ int __frontswap_store(struct page *page)
204 struct swap_info_struct *sis = swap_info[type]; 206 struct swap_info_struct *sis = swap_info[type];
205 pgoff_t offset = swp_offset(entry); 207 pgoff_t offset = swp_offset(entry);
206 208
207 if (!frontswap_ops) { 209 /*
208 inc_frontswap_failed_stores(); 210 * Return if no backend registed.
211 * Don't need to inc frontswap_failed_stores here.
212 */
213 if (!frontswap_ops)
209 return ret; 214 return ret;
210 }
211 215
212 BUG_ON(!PageLocked(page)); 216 BUG_ON(!PageLocked(page));
213 BUG_ON(sis == NULL); 217 BUG_ON(sis == NULL);
214 if (frontswap_test(sis, offset)) 218 if (__frontswap_test(sis, offset))
215 dup = 1; 219 dup = 1;
216 ret = frontswap_ops->store(type, offset, page); 220 ret = frontswap_ops->store(type, offset, page);
217 if (ret == 0) { 221 if (ret == 0) {
218 frontswap_set(sis, offset); 222 set_bit(offset, sis->frontswap_map);
219 inc_frontswap_succ_stores(); 223 inc_frontswap_succ_stores();
220 if (!dup) 224 if (!dup)
221 atomic_inc(&sis->frontswap_pages); 225 atomic_inc(&sis->frontswap_pages);
@@ -248,18 +252,18 @@ int __frontswap_load(struct page *page)
248 struct swap_info_struct *sis = swap_info[type]; 252 struct swap_info_struct *sis = swap_info[type];
249 pgoff_t offset = swp_offset(entry); 253 pgoff_t offset = swp_offset(entry);
250 254
251 if (!frontswap_ops)
252 return ret;
253
254 BUG_ON(!PageLocked(page)); 255 BUG_ON(!PageLocked(page));
255 BUG_ON(sis == NULL); 256 BUG_ON(sis == NULL);
256 if (frontswap_test(sis, offset)) 257 /*
258 * __frontswap_test() will check whether there is backend registered
259 */
260 if (__frontswap_test(sis, offset))
257 ret = frontswap_ops->load(type, offset, page); 261 ret = frontswap_ops->load(type, offset, page);
258 if (ret == 0) { 262 if (ret == 0) {
259 inc_frontswap_loads(); 263 inc_frontswap_loads();
260 if (frontswap_tmem_exclusive_gets_enabled) { 264 if (frontswap_tmem_exclusive_gets_enabled) {
261 SetPageDirty(page); 265 SetPageDirty(page);
262 frontswap_clear(sis, offset); 266 __frontswap_clear(sis, offset);
263 } 267 }
264 } 268 }
265 return ret; 269 return ret;
@@ -274,11 +278,11 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset)
274{ 278{
275 struct swap_info_struct *sis = swap_info[type]; 279 struct swap_info_struct *sis = swap_info[type];
276 280
277 if (!frontswap_ops)
278 return;
279
280 BUG_ON(sis == NULL); 281 BUG_ON(sis == NULL);
281 if (frontswap_test(sis, offset)) { 282 /*
283 * __frontswap_test() will check whether there is backend registered
284 */
285 if (__frontswap_test(sis, offset)) {
282 frontswap_ops->invalidate_page(type, offset); 286 frontswap_ops->invalidate_page(type, offset);
283 __frontswap_clear(sis, offset); 287 __frontswap_clear(sis, offset);
284 inc_frontswap_invalidates(); 288 inc_frontswap_invalidates();
@@ -435,7 +439,6 @@ static int __init init_frontswap(void)
435 debugfs_create_u64("invalidates", S_IRUGO, 439 debugfs_create_u64("invalidates", S_IRUGO,
436 root, &frontswap_invalidates); 440 root, &frontswap_invalidates);
437#endif 441#endif
438 frontswap_enabled = 1;
439 return 0; 442 return 0;
440} 443}
441 444