The old try_to_unuse() implementation was driven by find_next_to_unuse(), which terminated as soon as all the swap had been freed. Add inuse_pages checks now (alongside signal_pending()) to stop scanning mms and swap_map once finished. The same ought to be done in shmem_unuse() too, but never was before, and needs a different interface: so leave it as is for now.
Unified · Split
| @@ -2051,11 +2051,9 @@ retry: · 2050 unmodified lines | |||
| 2051 | 2051 | ||
| 2052 | spin_lock(&mmlist_lock); | 2052 | spin_lock(&mmlist_lock); |
| 2053 | p = &init_mm.mmlist; | 2053 | p = &init_mm.mmlist; |
| 2054 | while ((p = p->next) != &init_mm.mmlist) { | 2054 | while (si->inuse_pages && |
| 2055 | if (signal_pending(current)) { | 2055 | !signal_pending(current) && |
| 2056 | retval = -EINTR; | 2056 | (p = p->next) != &init_mm.mmlist) { |
| 2057 | break; | ||
| 2058 | } | ||
| 2059 | 2057 | ||
| 2060 | mm = list_entry(p, struct mm_struct, mmlist); | 2058 | mm = list_entry(p, struct mm_struct, mmlist); |
| 2061 | if (!mmget_not_zero(mm)) | 2059 | if (!mmget_not_zero(mm)) |
| @@ -2082,7 +2080,9 @@ retry: · 20 unmodified lines | |||
| 2082 | mmput(prev_mm); | 2080 | mmput(prev_mm); |
| 2083 | 2081 | ||
| 2084 | i = 0; | 2082 | i = 0; |
| 2085 | while ((i = find_next_to_unuse(si, i, frontswap)) != 0) { | 2083 | while (si->inuse_pages && |
| 2084 | !signal_pending(current) && | ||
| 2085 | (i = find_next_to_unuse(si, i, frontswap)) != 0) { | ||
| 2086 | 2086 | ||
| 2087 | entry = swp_entry(type, i); | 2087 | entry = swp_entry(type, i); |
| 2088 | page = find_get_page(swap_address_space(entry), i); | 2088 | page = find_get_page(swap_address_space(entry), i); |
| @@ -2123,8 +2123,11 @@ retry: · 34 unmodified lines | |||
| 2123 | * separate lists, and wait for those lists to be emptied; but it's | 2123 | * separate lists, and wait for those lists to be emptied; but it's |
| 2124 | * easier and more robust (though cpu-intensive) just to keep retrying. | 2124 | * easier and more robust (though cpu-intensive) just to keep retrying. |
| 2125 | */ | 2125 | */ |
| 2126 | if (si->inuse_pages) | 2126 | if (si->inuse_pages) { |
| 2127 | goto retry; | 2127 | if (!signal_pending(current)) |
| 2128 | goto retry; | ||
| 2129 | retval = -EINTR; | ||
| 2130 | } | ||
| 2128 | out: | 2131 | out: |
| 2129 | return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; | 2132 | return (retval == FRONTSWAP_PAGES_UNUSED) ? 0 : retval; |
| 2130 | } | 2133 | } |