Commit 96253444dbd90c6e9e9cfcb25315da5c412b058a

Authored by Sasha Levin
Committed by Konrad Rzeszutek Wilk
1 parent 4bb3e31ef4

mm: frontswap: split out __frontswap_curr_pages

Code was duplicated in two functions, clean it up.

Also, assert that the deduplicated code runs under the swap spinlock.

Reviewed-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Showing 1 changed file with 17 additions and 11 deletions Side-by-side Diff

... ... @@ -216,6 +216,20 @@
216 216 }
217 217 EXPORT_SYMBOL(__frontswap_invalidate_area);
218 218  
  219 +static unsigned long __frontswap_curr_pages(void)
  220 +{
  221 + int type;
  222 + unsigned long totalpages = 0;
  223 + struct swap_info_struct *si = NULL;
  224 +
  225 + assert_spin_locked(&swap_lock);
  226 + for (type = swap_list.head; type >= 0; type = si->next) {
  227 + si = swap_info[type];
  228 + totalpages += atomic_read(&si->frontswap_pages);
  229 + }
  230 + return totalpages;
  231 +}
  232 +
219 233 /*
220 234 * Frontswap, like a true swap device, may unnecessarily retain pages
221 235 * under certain circumstances; "shrink" frontswap is essentially a
... ... @@ -240,11 +254,7 @@
240 254 */
241 255 spin_lock(&swap_lock);
242 256 locked = true;
243   - total_pages = 0;
244   - for (type = swap_list.head; type >= 0; type = si->next) {
245   - si = swap_info[type];
246   - total_pages += atomic_read(&si->frontswap_pages);
247   - }
  257 + total_pages = __frontswap_curr_pages();
248 258 if (total_pages <= target_pages)
249 259 goto out;
250 260 total_pages_to_unuse = total_pages - target_pages;
251 261  
252 262  
253 263  
... ... @@ -282,16 +292,12 @@
282 292 */
283 293 unsigned long frontswap_curr_pages(void)
284 294 {
285   - int type;
286 295 unsigned long totalpages = 0;
287   - struct swap_info_struct *si = NULL;
288 296  
289 297 spin_lock(&swap_lock);
290   - for (type = swap_list.head; type >= 0; type = si->next) {
291   - si = swap_info[type];
292   - totalpages += atomic_read(&si->frontswap_pages);
293   - }
  298 + totalpages = __frontswap_curr_pages();
294 299 spin_unlock(&swap_lock);
  300 +
295 301 return totalpages;
296 302 }
297 303 EXPORT_SYMBOL(frontswap_curr_pages);