diff options
| -rw-r--r-- | mm/frontswap.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/mm/frontswap.c b/mm/frontswap.c index 7ec53d53c13a..5faf840f8726 100644 --- a/mm/frontswap.c +++ b/mm/frontswap.c | |||
| @@ -216,6 +216,20 @@ void __frontswap_invalidate_area(unsigned type) | |||
| 216 | } | 216 | } |
| 217 | EXPORT_SYMBOL(__frontswap_invalidate_area); | 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 | * Frontswap, like a true swap device, may unnecessarily retain pages | 234 | * Frontswap, like a true swap device, may unnecessarily retain pages |
| 221 | * under certain circumstances; "shrink" frontswap is essentially a | 235 | * under certain circumstances; "shrink" frontswap is essentially a |
| @@ -240,11 +254,7 @@ void frontswap_shrink(unsigned long target_pages) | |||
| 240 | */ | 254 | */ |
| 241 | spin_lock(&swap_lock); | 255 | spin_lock(&swap_lock); |
| 242 | locked = true; | 256 | locked = true; |
| 243 | total_pages = 0; | 257 | total_pages = __frontswap_curr_pages(); |
| 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 | } | ||
| 248 | if (total_pages <= target_pages) | 258 | if (total_pages <= target_pages) |
| 249 | goto out; | 259 | goto out; |
| 250 | total_pages_to_unuse = total_pages - target_pages; | 260 | total_pages_to_unuse = total_pages - target_pages; |
| @@ -282,16 +292,12 @@ EXPORT_SYMBOL(frontswap_shrink); | |||
| 282 | */ | 292 | */ |
| 283 | unsigned long frontswap_curr_pages(void) | 293 | unsigned long frontswap_curr_pages(void) |
| 284 | { | 294 | { |
| 285 | int type; | ||
| 286 | unsigned long totalpages = 0; | 295 | unsigned long totalpages = 0; |
| 287 | struct swap_info_struct *si = NULL; | ||
| 288 | 296 | ||
| 289 | spin_lock(&swap_lock); | 297 | spin_lock(&swap_lock); |
| 290 | for (type = swap_list.head; type >= 0; type = si->next) { | 298 | totalpages = __frontswap_curr_pages(); |
| 291 | si = swap_info[type]; | ||
| 292 | totalpages += atomic_read(&si->frontswap_pages); | ||
| 293 | } | ||
| 294 | spin_unlock(&swap_lock); | 299 | spin_unlock(&swap_lock); |
| 300 | |||
| 295 | return totalpages; | 301 | return totalpages; |
| 296 | } | 302 | } |
| 297 | EXPORT_SYMBOL(frontswap_curr_pages); | 303 | EXPORT_SYMBOL(frontswap_curr_pages); |
