@@ -27,10 +27,7 @@ DEFINE_STATIC_KEY_FALSE(frontswap_enabled_key);
27
27
* may be registered, but implementations can never deregister. This
28
28
* is a simple singly-linked list of all registered implementations.
29
29
*/
30
- static struct frontswap_ops * frontswap_ops __read_mostly ;
31
-
32
- #define for_each_frontswap_ops (ops ) \
33
- for ((ops) = frontswap_ops; (ops); (ops) = (ops)->next)
30
+ static const struct frontswap_ops * frontswap_ops __read_mostly ;
34
31
35
32
#ifdef CONFIG_DEBUG_FS
36
33
/*
@@ -97,18 +94,14 @@ static inline void inc_frontswap_invalidates(void) { }
97
94
/*
98
95
* Register operations for frontswap
99
96
*/
100
- void frontswap_register_ops (struct frontswap_ops * ops )
97
+ int frontswap_register_ops (const struct frontswap_ops * ops )
101
98
{
102
- /*
103
- * Setting frontswap_ops must happen after the ops->init() calls
104
- * above; cmpxchg implies smp_mb() which will ensure the init is
105
- * complete at this point.
106
- */
107
- do {
108
- ops -> next = frontswap_ops ;
109
- } while (cmpxchg (& frontswap_ops , ops -> next , ops ) != ops -> next );
99
+ if (frontswap_ops )
100
+ return - EINVAL ;
110
101
102
+ frontswap_ops = ops ;
111
103
static_branch_inc (& frontswap_enabled_key );
104
+ return 0 ;
112
105
}
113
106
114
107
/*
@@ -117,7 +110,6 @@ void frontswap_register_ops(struct frontswap_ops *ops)
117
110
void frontswap_init (unsigned type , unsigned long * map )
118
111
{
119
112
struct swap_info_struct * sis = swap_info [type ];
120
- struct frontswap_ops * ops ;
121
113
122
114
VM_BUG_ON (sis == NULL );
123
115
@@ -133,9 +125,7 @@ void frontswap_init(unsigned type, unsigned long *map)
133
125
* p->frontswap set to something valid to work properly.
134
126
*/
135
127
frontswap_map_set (sis , map );
136
-
137
- for_each_frontswap_ops (ops )
138
- ops -> init (type );
128
+ frontswap_ops -> init (type );
139
129
}
140
130
141
131
static bool __frontswap_test (struct swap_info_struct * sis ,
@@ -174,7 +164,6 @@ int __frontswap_store(struct page *page)
174
164
int type = swp_type (entry );
175
165
struct swap_info_struct * sis = swap_info [type ];
176
166
pgoff_t offset = swp_offset (entry );
177
- struct frontswap_ops * ops ;
178
167
179
168
VM_BUG_ON (!frontswap_ops );
180
169
VM_BUG_ON (!PageLocked (page ));
@@ -188,16 +177,10 @@ int __frontswap_store(struct page *page)
188
177
*/
189
178
if (__frontswap_test (sis , offset )) {
190
179
__frontswap_clear (sis , offset );
191
- for_each_frontswap_ops (ops )
192
- ops -> invalidate_page (type , offset );
180
+ frontswap_ops -> invalidate_page (type , offset );
193
181
}
194
182
195
- /* Try to store in each implementation, until one succeeds. */
196
- for_each_frontswap_ops (ops ) {
197
- ret = ops -> store (type , offset , page );
198
- if (!ret ) /* successful store */
199
- break ;
200
- }
183
+ ret = frontswap_ops -> store (type , offset , page );
201
184
if (ret == 0 ) {
202
185
__frontswap_set (sis , offset );
203
186
inc_frontswap_succ_stores ();
@@ -220,7 +203,6 @@ int __frontswap_load(struct page *page)
220
203
int type = swp_type (entry );
221
204
struct swap_info_struct * sis = swap_info [type ];
222
205
pgoff_t offset = swp_offset (entry );
223
- struct frontswap_ops * ops ;
224
206
225
207
VM_BUG_ON (!frontswap_ops );
226
208
VM_BUG_ON (!PageLocked (page ));
@@ -230,11 +212,7 @@ int __frontswap_load(struct page *page)
230
212
return -1 ;
231
213
232
214
/* Try loading from each implementation, until one succeeds. */
233
- for_each_frontswap_ops (ops ) {
234
- ret = ops -> load (type , offset , page );
235
- if (!ret ) /* successful load */
236
- break ;
237
- }
215
+ ret = frontswap_ops -> load (type , offset , page );
238
216
if (ret == 0 )
239
217
inc_frontswap_loads ();
240
218
return ret ;
@@ -247,16 +225,14 @@ int __frontswap_load(struct page *page)
247
225
void __frontswap_invalidate_page (unsigned type , pgoff_t offset )
248
226
{
249
227
struct swap_info_struct * sis = swap_info [type ];
250
- struct frontswap_ops * ops ;
251
228
252
229
VM_BUG_ON (!frontswap_ops );
253
230
VM_BUG_ON (sis == NULL );
254
231
255
232
if (!__frontswap_test (sis , offset ))
256
233
return ;
257
234
258
- for_each_frontswap_ops (ops )
259
- ops -> invalidate_page (type , offset );
235
+ frontswap_ops -> invalidate_page (type , offset );
260
236
__frontswap_clear (sis , offset );
261
237
inc_frontswap_invalidates ();
262
238
}
@@ -268,16 +244,14 @@ void __frontswap_invalidate_page(unsigned type, pgoff_t offset)
268
244
void __frontswap_invalidate_area (unsigned type )
269
245
{
270
246
struct swap_info_struct * sis = swap_info [type ];
271
- struct frontswap_ops * ops ;
272
247
273
248
VM_BUG_ON (!frontswap_ops );
274
249
VM_BUG_ON (sis == NULL );
275
250
276
251
if (sis -> frontswap_map == NULL )
277
252
return ;
278
253
279
- for_each_frontswap_ops (ops )
280
- ops -> invalidate_area (type );
254
+ frontswap_ops -> invalidate_area (type );
281
255
atomic_set (& sis -> frontswap_pages , 0 );
282
256
bitmap_zero (sis -> frontswap_map , sis -> max );
283
257
}
0 commit comments