Commit 1da0d94a authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

frontswap: remove support for multiple ops

There is only a single instance of frontswap ops in the kernel, so
simplify the frontswap code by removing support for multiple operations.

Link: https://lkml.kernel.org/r/20211224062246.1258487-13-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Cc: Dan Streetman <ddstreet@ieee.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Konrad Rzeszutek Wilk <Konrad.wilk@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 633423a0
...@@ -13,10 +13,9 @@ struct frontswap_ops { ...@@ -13,10 +13,9 @@ struct frontswap_ops {
int (*load)(unsigned, pgoff_t, struct page *); /* load a page */ int (*load)(unsigned, pgoff_t, struct page *); /* load a page */
void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */ void (*invalidate_page)(unsigned, pgoff_t); /* page no longer needed */
void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */ void (*invalidate_area)(unsigned); /* swap type just swapoff'ed */
struct frontswap_ops *next; /* private pointer to next ops */
}; };
extern void frontswap_register_ops(struct frontswap_ops *ops); int frontswap_register_ops(const struct frontswap_ops *ops);
extern void frontswap_init(unsigned type, unsigned long *map); extern void frontswap_init(unsigned type, unsigned long *map);
extern int __frontswap_store(struct page *page); extern int __frontswap_store(struct page *page);
......
...@@ -27,10 +27,7 @@ DEFINE_STATIC_KEY_FALSE(frontswap_enabled_key); ...@@ -27,10 +27,7 @@ DEFINE_STATIC_KEY_FALSE(frontswap_enabled_key);
* may be registered, but implementations can never deregister. This * may be registered, but implementations can never deregister. This
* is a simple singly-linked list of all registered implementations. * is a simple singly-linked list of all registered implementations.
*/ */
static struct frontswap_ops *frontswap_ops __read_mostly; static const struct frontswap_ops *frontswap_ops __read_mostly;
#define for_each_frontswap_ops(ops) \
for ((ops) = frontswap_ops; (ops); (ops) = (ops)->next)
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
/* /*
...@@ -97,18 +94,14 @@ static inline void inc_frontswap_invalidates(void) { } ...@@ -97,18 +94,14 @@ static inline void inc_frontswap_invalidates(void) { }
/* /*
* Register operations for frontswap * Register operations for frontswap
*/ */
void frontswap_register_ops(struct frontswap_ops *ops) int frontswap_register_ops(const struct frontswap_ops *ops)
{ {
/* if (frontswap_ops)
* Setting frontswap_ops must happen after the ops->init() calls return -EINVAL;
* above; cmpxchg implies smp_mb() which will ensure the init is
* complete at this point.
*/
do {
ops->next = frontswap_ops;
} while (cmpxchg(&frontswap_ops, ops->next, ops) != ops->next);
frontswap_ops = ops;
static_branch_inc(&frontswap_enabled_key); static_branch_inc(&frontswap_enabled_key);
return 0;
} }
/* /*
...@@ -117,7 +110,6 @@ void frontswap_register_ops(struct frontswap_ops *ops) ...@@ -117,7 +110,6 @@ void frontswap_register_ops(struct frontswap_ops *ops)
void frontswap_init(unsigned type, unsigned long *map) void frontswap_init(unsigned type, unsigned long *map)
{ {
struct swap_info_struct *sis = swap_info[type]; struct swap_info_struct *sis = swap_info[type];
struct frontswap_ops *ops;
VM_BUG_ON(sis == NULL); VM_BUG_ON(sis == NULL);
...@@ -133,9 +125,7 @@ void frontswap_init(unsigned type, unsigned long *map) ...@@ -133,9 +125,7 @@ void frontswap_init(unsigned type, unsigned long *map)
* p->frontswap set to something valid to work properly. * p->frontswap set to something valid to work properly.
*/ */
frontswap_map_set(sis, map); frontswap_map_set(sis, map);
frontswap_ops->init(type);
for_each_frontswap_ops(ops)
ops->init(type);
} }
static bool __frontswap_test(struct swap_info_struct *sis, static bool __frontswap_test(struct swap_info_struct *sis,
...@@ -174,7 +164,6 @@ int __frontswap_store(struct page *page) ...@@ -174,7 +164,6 @@ int __frontswap_store(struct page *page)
int type = swp_type(entry); int type = swp_type(entry);
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);
struct frontswap_ops *ops;
VM_BUG_ON(!frontswap_ops); VM_BUG_ON(!frontswap_ops);
VM_BUG_ON(!PageLocked(page)); VM_BUG_ON(!PageLocked(page));
...@@ -188,16 +177,10 @@ int __frontswap_store(struct page *page) ...@@ -188,16 +177,10 @@ int __frontswap_store(struct page *page)
*/ */
if (__frontswap_test(sis, offset)) { if (__frontswap_test(sis, offset)) {
__frontswap_clear(sis, offset); __frontswap_clear(sis, offset);
for_each_frontswap_ops(ops) frontswap_ops->invalidate_page(type, offset);
ops->invalidate_page(type, offset);
} }
/* Try to store in each implementation, until one succeeds. */ ret = frontswap_ops->store(type, offset, page);
for_each_frontswap_ops(ops) {
ret = ops->store(type, offset, page);
if (!ret) /* successful store */
break;
}
if (ret == 0) { if (ret == 0) {
__frontswap_set(sis, offset); __frontswap_set(sis, offset);
inc_frontswap_succ_stores(); inc_frontswap_succ_stores();
...@@ -220,7 +203,6 @@ int __frontswap_load(struct page *page) ...@@ -220,7 +203,6 @@ int __frontswap_load(struct page *page)
int type = swp_type(entry); int type = swp_type(entry);
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);
struct frontswap_ops *ops;
VM_BUG_ON(!frontswap_ops); VM_BUG_ON(!frontswap_ops);
VM_BUG_ON(!PageLocked(page)); VM_BUG_ON(!PageLocked(page));
...@@ -230,11 +212,7 @@ int __frontswap_load(struct page *page) ...@@ -230,11 +212,7 @@ int __frontswap_load(struct page *page)
return -1; return -1;
/* Try loading from each implementation, until one succeeds. */ /* Try loading from each implementation, until one succeeds. */
for_each_frontswap_ops(ops) { ret = frontswap_ops->load(type, offset, page);
ret = ops->load(type, offset, page);
if (!ret) /* successful load */
break;
}
if (ret == 0) if (ret == 0)
inc_frontswap_loads(); inc_frontswap_loads();
return ret; return ret;
...@@ -247,7 +225,6 @@ int __frontswap_load(struct page *page) ...@@ -247,7 +225,6 @@ int __frontswap_load(struct page *page)
void __frontswap_invalidate_page(unsigned type, pgoff_t offset) 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];
struct frontswap_ops *ops;
VM_BUG_ON(!frontswap_ops); VM_BUG_ON(!frontswap_ops);
VM_BUG_ON(sis == NULL); VM_BUG_ON(sis == NULL);
...@@ -255,8 +232,7 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset) ...@@ -255,8 +232,7 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset)
if (!__frontswap_test(sis, offset)) if (!__frontswap_test(sis, offset))
return; return;
for_each_frontswap_ops(ops) frontswap_ops->invalidate_page(type, offset);
ops->invalidate_page(type, offset);
__frontswap_clear(sis, offset); __frontswap_clear(sis, offset);
inc_frontswap_invalidates(); inc_frontswap_invalidates();
} }
...@@ -268,7 +244,6 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset) ...@@ -268,7 +244,6 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset)
void __frontswap_invalidate_area(unsigned type) void __frontswap_invalidate_area(unsigned type)
{ {
struct swap_info_struct *sis = swap_info[type]; struct swap_info_struct *sis = swap_info[type];
struct frontswap_ops *ops;
VM_BUG_ON(!frontswap_ops); VM_BUG_ON(!frontswap_ops);
VM_BUG_ON(sis == NULL); VM_BUG_ON(sis == NULL);
...@@ -276,8 +251,7 @@ void __frontswap_invalidate_area(unsigned type) ...@@ -276,8 +251,7 @@ void __frontswap_invalidate_area(unsigned type)
if (sis->frontswap_map == NULL) if (sis->frontswap_map == NULL)
return; return;
for_each_frontswap_ops(ops) frontswap_ops->invalidate_area(type);
ops->invalidate_area(type);
atomic_set(&sis->frontswap_pages, 0); atomic_set(&sis->frontswap_pages, 0);
bitmap_zero(sis->frontswap_map, sis->max); bitmap_zero(sis->frontswap_map, sis->max);
} }
......
...@@ -1378,7 +1378,7 @@ static void zswap_frontswap_init(unsigned type) ...@@ -1378,7 +1378,7 @@ static void zswap_frontswap_init(unsigned type)
zswap_trees[type] = tree; zswap_trees[type] = tree;
} }
static struct frontswap_ops zswap_frontswap_ops = { static const struct frontswap_ops zswap_frontswap_ops = {
.store = zswap_frontswap_store, .store = zswap_frontswap_store,
.load = zswap_frontswap_load, .load = zswap_frontswap_load,
.invalidate_page = zswap_frontswap_invalidate_page, .invalidate_page = zswap_frontswap_invalidate_page,
...@@ -1475,11 +1475,15 @@ static int __init init_zswap(void) ...@@ -1475,11 +1475,15 @@ static int __init init_zswap(void)
if (!shrink_wq) if (!shrink_wq)
goto fallback_fail; goto fallback_fail;
frontswap_register_ops(&zswap_frontswap_ops); ret = frontswap_register_ops(&zswap_frontswap_ops);
if (ret)
goto destroy_wq;
if (zswap_debugfs_init()) if (zswap_debugfs_init())
pr_warn("debugfs initialization failed\n"); pr_warn("debugfs initialization failed\n");
return 0; return 0;
destroy_wq:
destroy_workqueue(shrink_wq);
fallback_fail: fallback_fail:
if (pool) if (pool)
zswap_pool_destroy(pool); zswap_pool_destroy(pool);
......
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