Commit f066ea23 authored by Bob Liu's avatar Bob Liu Committed by Linus Torvalds

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: default avatarBob 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1e01c968
...@@ -22,6 +22,7 @@ extern void frontswap_writethrough(bool); ...@@ -22,6 +22,7 @@ extern void frontswap_writethrough(bool);
#define FRONTSWAP_HAS_EXCLUSIVE_GETS #define FRONTSWAP_HAS_EXCLUSIVE_GETS
extern void frontswap_tmem_exclusive_gets(bool); extern void frontswap_tmem_exclusive_gets(bool);
extern bool __frontswap_test(struct swap_info_struct *, pgoff_t);
extern void __frontswap_init(unsigned type); extern void __frontswap_init(unsigned type);
extern int __frontswap_store(struct page *page); extern int __frontswap_store(struct page *page);
extern int __frontswap_load(struct page *page); extern int __frontswap_load(struct page *page);
...@@ -29,26 +30,11 @@ extern void __frontswap_invalidate_page(unsigned, pgoff_t); ...@@ -29,26 +30,11 @@ extern void __frontswap_invalidate_page(unsigned, pgoff_t);
extern void __frontswap_invalidate_area(unsigned); extern void __frontswap_invalidate_area(unsigned);
#ifdef CONFIG_FRONTSWAP #ifdef CONFIG_FRONTSWAP
#define frontswap_enabled (1)
static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
{ {
bool ret = false; return __frontswap_test(sis, offset);
if (frontswap_enabled && sis->frontswap_map)
ret = test_bit(offset, sis->frontswap_map);
return ret;
}
static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
{
if (frontswap_enabled && sis->frontswap_map)
set_bit(offset, sis->frontswap_map);
}
static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
{
if (frontswap_enabled && sis->frontswap_map)
clear_bit(offset, sis->frontswap_map);
} }
static inline void frontswap_map_set(struct swap_info_struct *p, static inline void frontswap_map_set(struct swap_info_struct *p,
...@@ -71,14 +57,6 @@ static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) ...@@ -71,14 +57,6 @@ static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset)
return false; return false;
} }
static inline void frontswap_set(struct swap_info_struct *sis, pgoff_t offset)
{
}
static inline void frontswap_clear(struct swap_info_struct *sis, pgoff_t offset)
{
}
static inline void frontswap_map_set(struct swap_info_struct *p, static inline void frontswap_map_set(struct swap_info_struct *p,
unsigned long *map) unsigned long *map)
{ {
......
...@@ -26,14 +26,6 @@ ...@@ -26,14 +26,6 @@
*/ */
static struct frontswap_ops *frontswap_ops __read_mostly; static struct frontswap_ops *frontswap_ops __read_mostly;
/*
* This global enablement flag reduces overhead on systems where frontswap_ops
* has not been registered, so is preferred to the slower alternative: a
* function call that checks a non-global.
*/
bool frontswap_enabled __read_mostly;
EXPORT_SYMBOL(frontswap_enabled);
/* /*
* If enabled, frontswap_store will return failure even on success. As * If enabled, frontswap_store will return failure even on success. As
* a result, the swap subsystem will always write the page to swap, in * a result, the swap subsystem will always write the page to swap, in
...@@ -128,8 +120,6 @@ struct frontswap_ops *frontswap_register_ops(struct frontswap_ops *ops) ...@@ -128,8 +120,6 @@ struct frontswap_ops *frontswap_register_ops(struct frontswap_ops *ops)
struct frontswap_ops *old = frontswap_ops; struct frontswap_ops *old = frontswap_ops;
int i; int i;
frontswap_enabled = true;
for (i = 0; i < MAX_SWAPFILES; i++) { for (i = 0; i < MAX_SWAPFILES; i++) {
if (test_and_clear_bit(i, need_init)) if (test_and_clear_bit(i, need_init))
ops->init(i); ops->init(i);
...@@ -183,9 +173,21 @@ void __frontswap_init(unsigned type) ...@@ -183,9 +173,21 @@ void __frontswap_init(unsigned type)
} }
EXPORT_SYMBOL(__frontswap_init); EXPORT_SYMBOL(__frontswap_init);
static inline void __frontswap_clear(struct swap_info_struct *sis, pgoff_t offset) bool __frontswap_test(struct swap_info_struct *sis,
pgoff_t offset)
{
bool ret = false;
if (frontswap_ops && sis->frontswap_map)
ret = test_bit(offset, sis->frontswap_map);
return ret;
}
EXPORT_SYMBOL(__frontswap_test);
static inline void __frontswap_clear(struct swap_info_struct *sis,
pgoff_t offset)
{ {
frontswap_clear(sis, offset); clear_bit(offset, sis->frontswap_map);
atomic_dec(&sis->frontswap_pages); atomic_dec(&sis->frontswap_pages);
} }
...@@ -204,18 +206,20 @@ int __frontswap_store(struct page *page) ...@@ -204,18 +206,20 @@ int __frontswap_store(struct page *page)
struct swap_info_struct *sis = swap_info[type]; struct swap_info_struct *sis = swap_info[type];
pgoff_t offset = swp_offset(entry); pgoff_t offset = swp_offset(entry);
if (!frontswap_ops) { /*
inc_frontswap_failed_stores(); * Return if no backend registed.
* Don't need to inc frontswap_failed_stores here.
*/
if (!frontswap_ops)
return ret; return ret;
}
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
BUG_ON(sis == NULL); BUG_ON(sis == NULL);
if (frontswap_test(sis, offset)) if (__frontswap_test(sis, offset))
dup = 1; dup = 1;
ret = frontswap_ops->store(type, offset, page); ret = frontswap_ops->store(type, offset, page);
if (ret == 0) { if (ret == 0) {
frontswap_set(sis, offset); set_bit(offset, sis->frontswap_map);
inc_frontswap_succ_stores(); inc_frontswap_succ_stores();
if (!dup) if (!dup)
atomic_inc(&sis->frontswap_pages); atomic_inc(&sis->frontswap_pages);
...@@ -248,18 +252,18 @@ int __frontswap_load(struct page *page) ...@@ -248,18 +252,18 @@ int __frontswap_load(struct page *page)
struct swap_info_struct *sis = swap_info[type]; struct swap_info_struct *sis = swap_info[type];
pgoff_t offset = swp_offset(entry); pgoff_t offset = swp_offset(entry);
if (!frontswap_ops)
return ret;
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
BUG_ON(sis == NULL); BUG_ON(sis == NULL);
if (frontswap_test(sis, offset)) /*
* __frontswap_test() will check whether there is backend registered
*/
if (__frontswap_test(sis, offset))
ret = frontswap_ops->load(type, offset, page); ret = frontswap_ops->load(type, offset, page);
if (ret == 0) { if (ret == 0) {
inc_frontswap_loads(); inc_frontswap_loads();
if (frontswap_tmem_exclusive_gets_enabled) { if (frontswap_tmem_exclusive_gets_enabled) {
SetPageDirty(page); SetPageDirty(page);
frontswap_clear(sis, offset); __frontswap_clear(sis, offset);
} }
} }
return ret; return ret;
...@@ -274,11 +278,11 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset) ...@@ -274,11 +278,11 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset)
{ {
struct swap_info_struct *sis = swap_info[type]; struct swap_info_struct *sis = swap_info[type];
if (!frontswap_ops)
return;
BUG_ON(sis == NULL); BUG_ON(sis == NULL);
if (frontswap_test(sis, offset)) { /*
* __frontswap_test() will check whether there is backend registered
*/
if (__frontswap_test(sis, offset)) {
frontswap_ops->invalidate_page(type, offset); frontswap_ops->invalidate_page(type, offset);
__frontswap_clear(sis, offset); __frontswap_clear(sis, offset);
inc_frontswap_invalidates(); inc_frontswap_invalidates();
...@@ -435,7 +439,6 @@ static int __init init_frontswap(void) ...@@ -435,7 +439,6 @@ static int __init init_frontswap(void)
debugfs_create_u64("invalidates", S_IRUGO, debugfs_create_u64("invalidates", S_IRUGO,
root, &frontswap_invalidates); root, &frontswap_invalidates);
#endif #endif
frontswap_enabled = 1;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment