diff options
author | Vlastimil Babka <vbabka@suse.cz> | 2016-07-26 18:24:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-07-26 19:19:19 -0400 |
commit | 8ea1d2a1985a7ae096edf5850a31d844ad1b8e97 (patch) | |
tree | 3ec2c4dc7d51fa1f5f2797e09fd8361a8404b474 /include/linux/frontswap.h | |
parent | fbe84a09da746f781553051bb3dbc63f7b0a5162 (diff) |
mm, frontswap: convert frontswap_enabled to static key
I have noticed that frontswap.h first declares "frontswap_enabled" as
extern bool variable, and then overrides it with "#define
frontswap_enabled (1)" for CONFIG_FRONTSWAP=Y or (0) when disabled. The
bool variable isn't actually instantiated anywhere.
This all looks like an unfinished attempt to make frontswap_enabled
reflect whether a backend is instantiated. But in the current state,
all frontswap hooks call unconditionally into frontswap.c just to check
if frontswap_ops is non-NULL. This should at least be checked inline,
but we can further eliminate the overhead when CONFIG_FRONTSWAP is
enabled and no backend registered, using a static key that is initially
disabled, and gets enabled only upon first backend registration.
Thus, checks for "frontswap_enabled" are replaced with
"frontswap_enabled()" wrapping the static key check. There are two
exceptions:
- xen's selfballoon_process() was testing frontswap_enabled in code guarded
by #ifdef CONFIG_FRONTSWAP, which was effectively always true when reachable.
The patch just removes this check. Using frontswap_enabled() does not sound
correct here, as this can be true even without xen's own backend being
registered.
- in SYSCALL_DEFINE2(swapon), change the check to IS_ENABLED(CONFIG_FRONTSWAP)
as it seems the bitmap allocation cannot currently be postponed until a
backend is registered. This means that frontswap will still have some
memory overhead by being configured, but without a backend.
After the patch, we can expect that some functions in frontswap.c are
called only when frontswap_ops is non-NULL. Change the checks there to
VM_BUG_ONs. While at it, convert other BUG_ONs to VM_BUG_ONs as
frontswap has been stable for some time.
[akpm@linux-foundation.org: coding-style fixes]
Link: http://lkml.kernel.org/r/1463152235-9717-1-git-send-email-vbabka@suse.cz
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/frontswap.h')
-rw-r--r-- | include/linux/frontswap.h | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h index e65ef959546c..c46d2aa16d81 100644 --- a/include/linux/frontswap.h +++ b/include/linux/frontswap.h | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/swap.h> | 4 | #include <linux/swap.h> |
5 | #include <linux/mm.h> | 5 | #include <linux/mm.h> |
6 | #include <linux/bitops.h> | 6 | #include <linux/bitops.h> |
7 | #include <linux/jump_label.h> | ||
7 | 8 | ||
8 | struct frontswap_ops { | 9 | struct frontswap_ops { |
9 | void (*init)(unsigned); /* this swap type was just swapon'ed */ | 10 | void (*init)(unsigned); /* this swap type was just swapon'ed */ |
@@ -14,7 +15,6 @@ struct frontswap_ops { | |||
14 | struct frontswap_ops *next; /* private pointer to next ops */ | 15 | struct frontswap_ops *next; /* private pointer to next ops */ |
15 | }; | 16 | }; |
16 | 17 | ||
17 | extern bool frontswap_enabled; | ||
18 | extern void frontswap_register_ops(struct frontswap_ops *ops); | 18 | extern void frontswap_register_ops(struct frontswap_ops *ops); |
19 | extern void frontswap_shrink(unsigned long); | 19 | extern void frontswap_shrink(unsigned long); |
20 | extern unsigned long frontswap_curr_pages(void); | 20 | extern unsigned long frontswap_curr_pages(void); |
@@ -30,7 +30,12 @@ extern void __frontswap_invalidate_page(unsigned, pgoff_t); | |||
30 | extern void __frontswap_invalidate_area(unsigned); | 30 | extern void __frontswap_invalidate_area(unsigned); |
31 | 31 | ||
32 | #ifdef CONFIG_FRONTSWAP | 32 | #ifdef CONFIG_FRONTSWAP |
33 | #define frontswap_enabled (1) | 33 | extern struct static_key_false frontswap_enabled_key; |
34 | |||
35 | static inline bool frontswap_enabled(void) | ||
36 | { | ||
37 | return static_branch_unlikely(&frontswap_enabled_key); | ||
38 | } | ||
34 | 39 | ||
35 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) | 40 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
36 | { | 41 | { |
@@ -50,7 +55,10 @@ static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) | |||
50 | #else | 55 | #else |
51 | /* all inline routines become no-ops and all externs are ignored */ | 56 | /* all inline routines become no-ops and all externs are ignored */ |
52 | 57 | ||
53 | #define frontswap_enabled (0) | 58 | static inline bool frontswap_enabled(void) |
59 | { | ||
60 | return false; | ||
61 | } | ||
54 | 62 | ||
55 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) | 63 | static inline bool frontswap_test(struct swap_info_struct *sis, pgoff_t offset) |
56 | { | 64 | { |
@@ -70,37 +78,35 @@ static inline unsigned long *frontswap_map_get(struct swap_info_struct *p) | |||
70 | 78 | ||
71 | static inline int frontswap_store(struct page *page) | 79 | static inline int frontswap_store(struct page *page) |
72 | { | 80 | { |
73 | int ret = -1; | 81 | if (frontswap_enabled()) |
82 | return __frontswap_store(page); | ||
74 | 83 | ||
75 | if (frontswap_enabled) | 84 | return -1; |
76 | ret = __frontswap_store(page); | ||
77 | return ret; | ||
78 | } | 85 | } |
79 | 86 | ||
80 | static inline int frontswap_load(struct page *page) | 87 | static inline int frontswap_load(struct page *page) |
81 | { | 88 | { |
82 | int ret = -1; | 89 | if (frontswap_enabled()) |
90 | return __frontswap_load(page); | ||
83 | 91 | ||
84 | if (frontswap_enabled) | 92 | return -1; |
85 | ret = __frontswap_load(page); | ||
86 | return ret; | ||
87 | } | 93 | } |
88 | 94 | ||
89 | static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset) | 95 | static inline void frontswap_invalidate_page(unsigned type, pgoff_t offset) |
90 | { | 96 | { |
91 | if (frontswap_enabled) | 97 | if (frontswap_enabled()) |
92 | __frontswap_invalidate_page(type, offset); | 98 | __frontswap_invalidate_page(type, offset); |
93 | } | 99 | } |
94 | 100 | ||
95 | static inline void frontswap_invalidate_area(unsigned type) | 101 | static inline void frontswap_invalidate_area(unsigned type) |
96 | { | 102 | { |
97 | if (frontswap_enabled) | 103 | if (frontswap_enabled()) |
98 | __frontswap_invalidate_area(type); | 104 | __frontswap_invalidate_area(type); |
99 | } | 105 | } |
100 | 106 | ||
101 | static inline void frontswap_init(unsigned type, unsigned long *map) | 107 | static inline void frontswap_init(unsigned type, unsigned long *map) |
102 | { | 108 | { |
103 | if (frontswap_enabled) | 109 | if (frontswap_enabled()) |
104 | __frontswap_init(type, map); | 110 | __frontswap_init(type, map); |
105 | } | 111 | } |
106 | 112 | ||