Reclaim orphaned swap pages
Subsystems (3)
PATCH 1/1 Reclaim orphaned swap pages
Hi,
Rik, the patch below tries to reclaim orphaned swap pages after swapped processes exit. I've only given it basic testing but I want to get feedback on it sooner rather than later --- we need to do _something_ about this problem!
The patch works completely differently to the release-on-exit diffs:
this one works in refill_inactive(), so has zero impact on the hot paths. It also works by looking for such orphaned pages in the swap cache, not by examining swap entries --- it is much cheaper to find a swap entry for a given page than to find the swap cache page for a given swap entry.
The patch should be fairly non-intrusive --- all it does is to clear the age, referenced bit and dirty bit on pages which are swap cached and which have page count and swap count == 1. The normal reclaim path will then recycle these pages rapidly.
We can also extend this to do the swap reclaim that we want. Currently the recycling only happens if the page count is one, but in theory we can also do this for pages with higher refcounts if we are low on swap --- as long as the swap ref is one on a swap cached page, we know that the swap cache is the only reference to the swap entry and no ptes can possibly point to that location on disk, so it's safe to reclaim the swap cache at that point.
Cheers,
Stephen
mm/vmscan.c renamed from mm/vmscan.c.~1~ +32 -0
@@ -704,6 +704,32 @@return freed_pages + flushed_pages; } +/* Check to see if a given page is a swap cache page with no further +* references to the swap entry nor to the page in memory. Clear all of +* the aging information for such pages to force them immediately onto +* the inactive_clean list for page reclamation. */ + +static void check_orphaned_swap (struct page *page) +{ +spinlock_t *pg_lock =PAGECACHE_LOCK (page); + +if (spin_trylock (pg_lock)) { +/* Re-test the page state under protection of the proper +* spinlock */ +if (PageSwapCache (page) &&atomic_read (&page->count) ==1 ) { +if (!TryLockPage (page)) { +if (swap_count (page) ==1 ) { +ClearPageDirty (page); +ClearPageReferenced (page); + page->age =0 ; + } +UnlockPage (page); + } + } +spin_unlock (pg_lock); + } +} +/** * refill_inactive_scan - scan the active list and find pages to deactivate * @priority: the priority at which to scan
@@ -728,6 +754,12 @@/* Wrong page on list?! (list corruption, should not happen) */ if (!PageActive (page))BUG (); + +/* Special case: orphaned swap cache pages should be +* reclaimed as quickly as possible, regardless of their +* age or whether they are dirty or not. */ +if (PageSwapCache (page) &&atomic_read (&page->count) ==1 ) +check_orphaned_swap (page);/* Do aging on the pages. */ if (PageTestandClearReferenced (page)) {
Quoted 6 lines · Stephen Tweedie
The patch works completely differently to the release-on-exit diffs:
this one works inrefill_inactive(), so has zero impact on the hot paths. It also works by looking for such orphaned pages in the swap cache, not by examining swap entries --- it is much cheaper to find a swap entry for a given page than to find the swap cache page for a given swap entry.
It seems we would still have the situation whereby a process will be unable to allocate memory because vm_enough_memory() fails, even though there is sufficient orphaned swap pages available to satisfy the request. Isn't it possible there may be enough free memory such that refill_inactive_scan() isn't running, but still not enough to satisfy vm_enough_memory()?
Pat
Signature · 8 lines
Patrick O'Rourke 978.606.0236 [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux.eu.org/Linux-MM/
Quoted 6 lines · Stephen Tweedie
Rik, the patch below tries to reclaim orphaned swap pages after swapped processes exit. I've only given it basic testing but I want to get feedback on it sooner rather than later --- we need to do _something_ about this problem!
The patch works completely differently to the release-on-exit diffs:
It looks good and simple enough to just plug into the kernel. I cannot see any problem with this patch, except that the PAGECACHE_LOCK macro doesn't seem to exist (yet) in my kernel tree ;))
cheers,
Rik
--
Virtual memory is like a game you can't win; However, without VM there's truly nothing to lose...
http://www.surriel.com/
http://www.conectiva.com/ http://distro.conectiva.com.br/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/
Hi,
Quoted 5 lines · Rik van Riel
It looks good and simple enough to just plug into the kernel. I cannot see any problem with this patch, except that the
PAGECACHE_LOCKmacro doesn't seem to exist (yet) in my kernel tree ;))
Yep, I built this on a tree which had Ingo's Tux patches applied and I'd forgotten that he had added a fine-grained page cache lock to his code. Will fix.
Cheers,
Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/