aboutsummaryrefslogtreecommitdiffstats
path: root/mm/swapfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r--mm/swapfile.c70
1 files changed, 12 insertions, 58 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index bfd4ee59cb88..f43601827607 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -348,68 +348,23 @@ int reuse_swap_page(struct page *page)
348} 348}
349 349
350/* 350/*
351 * Work out if there are any other processes sharing this 351 * If swap is getting full, or if there are no more mappings of this page,
352 * swap cache page. Free it if you can. Return success. 352 * then try_to_free_swap is called to free its swap space.
353 */ 353 */
354static int remove_exclusive_swap_page_count(struct page *page, int count) 354int try_to_free_swap(struct page *page)
355{ 355{
356 int retval;
357 struct swap_info_struct * p;
358 swp_entry_t entry;
359
360 VM_BUG_ON(!PageLocked(page)); 356 VM_BUG_ON(!PageLocked(page));
361 357
362 if (!PageSwapCache(page)) 358 if (!PageSwapCache(page))
363 return 0; 359 return 0;
364 if (PageWriteback(page)) 360 if (PageWriteback(page))
365 return 0; 361 return 0;
366 if (page_count(page) != count) /* us + cache + ptes */ 362 if (page_swapcount(page))
367 return 0;
368
369 entry.val = page_private(page);
370 p = swap_info_get(entry);
371 if (!p)
372 return 0; 363 return 0;
373 364
374 /* Is the only swap cache user the cache itself? */ 365 delete_from_swap_cache(page);
375 retval = 0; 366 SetPageDirty(page);
376 if (p->swap_map[swp_offset(entry)] == 1) { 367 return 1;
377 /* Recheck the page count with the swapcache lock held.. */
378 spin_lock_irq(&swapper_space.tree_lock);
379 if ((page_count(page) == count) && !PageWriteback(page)) {
380 __delete_from_swap_cache(page);
381 SetPageDirty(page);
382 retval = 1;
383 }
384 spin_unlock_irq(&swapper_space.tree_lock);
385 }
386 spin_unlock(&swap_lock);
387
388 if (retval) {
389 swap_free(entry);
390 page_cache_release(page);
391 }
392
393 return retval;
394}
395
396/*
397 * Most of the time the page should have two references: one for the
398 * process and one for the swap cache.
399 */
400int remove_exclusive_swap_page(struct page *page)
401{
402 return remove_exclusive_swap_page_count(page, 2);
403}
404
405/*
406 * The pageout code holds an extra reference to the page. That raises
407 * the reference count to test for to 2 for a page that is only in the
408 * swap cache plus 1 for each process that maps the page.
409 */
410int remove_exclusive_swap_page_ref(struct page *page)
411{
412 return remove_exclusive_swap_page_count(page, 2 + page_mapcount(page));
413} 368}
414 369
415/* 370/*
@@ -436,13 +391,12 @@ void free_swap_and_cache(swp_entry_t entry)
436 spin_unlock(&swap_lock); 391 spin_unlock(&swap_lock);
437 } 392 }
438 if (page) { 393 if (page) {
439 int one_user; 394 /*
440 395 * Not mapped elsewhere, or swap space full? Free it!
441 one_user = (page_count(page) == 2); 396 * Also recheck PageSwapCache now page is locked (above).
442 /* Only cache user (+us), or swap space full? Free it! */ 397 */
443 /* Also recheck PageSwapCache after page is locked (above) */
444 if (PageSwapCache(page) && !PageWriteback(page) && 398 if (PageSwapCache(page) && !PageWriteback(page) &&
445 (one_user || vm_swap_full())) { 399 (!page_mapped(page) || vm_swap_full())) {
446 delete_from_swap_cache(page); 400 delete_from_swap_cache(page);
447 SetPageDirty(page); 401 SetPageDirty(page);
448 } 402 }