Commit dd862deb authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

mm: swapoff: remove too limiting SWAP_UNUSE_MAX_TRIES

SWAP_UNUSE_MAX_TRIES 3 appeared to work well in earlier testing, but
further testing has proved it to be a source of unnecessary swapoff
EBUSY failures (which can then be followed by unmount EBUSY failures).

When mmget_not_zero() or shmem's igrab() fails, there is an mm exiting
or inode being evicted, freeing up swap independent of try_to_unuse().
Those typically completed much sooner than the old quadratic swapoff,
but now it's more common that swapoff may need to wait for them.

It's possible to move those cases from init_mm.mmlist and shmem_swaplist
to separate "exiting" swaplists, and try_to_unuse() then wait for those
lists to be emptied; but we've not bothered with that in the past, and
don't want to risk missing some other forgotten case.  So just revert to
cycling around until the swap is gone, without any retries limit.

Link: http://lkml.kernel.org/r/alpine.LSU.2.11.1904081256170.1523@eggly.anvils
Fixes: b56a2d8a ("mm: rid swapoff of quadratic complexity")
Signed-off-by: default avatarHugh Dickins <hughd@google.com>
Cc: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Kelley Nielsen <kelleynnn@gmail.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Cc: Rik van Riel <riel@surriel.com>
Cc: Vineeth Pillai <vpillai@digitalocean.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 87039546
...@@ -2023,7 +2023,6 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si, ...@@ -2023,7 +2023,6 @@ static unsigned int find_next_to_unuse(struct swap_info_struct *si,
* If the boolean frontswap is true, only unuse pages_to_unuse pages; * If the boolean frontswap is true, only unuse pages_to_unuse pages;
* pages_to_unuse==0 means all pages; ignored if frontswap is false * pages_to_unuse==0 means all pages; ignored if frontswap is false
*/ */
#define SWAP_UNUSE_MAX_TRIES 3
int try_to_unuse(unsigned int type, bool frontswap, int try_to_unuse(unsigned int type, bool frontswap,
unsigned long pages_to_unuse) unsigned long pages_to_unuse)
{ {
...@@ -2035,7 +2034,6 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2035,7 +2034,6 @@ int try_to_unuse(unsigned int type, bool frontswap,
struct page *page; struct page *page;
swp_entry_t entry; swp_entry_t entry;
unsigned int i; unsigned int i;
int retries = 0;
if (!si->inuse_pages) if (!si->inuse_pages)
return 0; return 0;
...@@ -2117,14 +2115,16 @@ int try_to_unuse(unsigned int type, bool frontswap, ...@@ -2117,14 +2115,16 @@ int try_to_unuse(unsigned int type, bool frontswap,
* If yes, we would need to do retry the unuse logic again. * If yes, we would need to do retry the unuse logic again.
* Under global memory pressure, swap entries can be reinserted back * Under global memory pressure, swap entries can be reinserted back
* into process space after the mmlist loop above passes over them. * into process space after the mmlist loop above passes over them.
* Its not worth continuosuly retrying to unuse the swap in this case. *
* So we try SWAP_UNUSE_MAX_TRIES times. * Limit the number of retries? No: when shmem_unuse()'s igrab() fails,
* a shmem inode using swap is being evicted; and when mmget_not_zero()
* above fails, that mm is likely to be freeing swap from exit_mmap().
* Both proceed at their own independent pace: we could move them to
* separate lists, and wait for those lists to be emptied; but it's
* easier and more robust (though cpu-intensive) just to keep retrying.
*/ */
if (++retries >= SWAP_UNUSE_MAX_TRIES) if (si->inuse_pages)
retval = -EBUSY;
else if (si->inuse_pages)
goto retry; goto retry;
out: out:
return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment