Re: new swap cache regime

Andrea Arcangeli (andrea@e-mind.com)
Mon, 28 Sep 1998 15:46:08 +0200 (CEST)


On Mon, 28 Sep 1998, Stephen C. Tweedie wrote:

>----------------------------------------------------------------
>--- mm/swap_state.c.~1~ Mon Sep 21 15:52:34 1998
>+++ mm/swap_state.c Mon Sep 28 11:45:44 1998
>@@ -208,6 +208,18 @@
> delete_from_swap_cache(page);
> }
>
>+ /* Special case: if we have still got other references to this
>+ * page, but all such references are to the swap entry rather
>+ * than to the physical page, then we are only keeping this page
>+ * for caching purposes. If the remaining process references
>+ * are killed, we will be left with an orphaned swap entry from
>+ * the cache. Make sure that such pages are easily cleaned out
>+ * of the page cache. */
>+ if (atomic_read(&page->count) == 1) {
>+ clear_bit(PG_referenced, &page->flags);
>+ page->age = 0;
>+ }
>+

This work should be done only if PageSwapCache(page) == 1 and when
is_page_shared() is true, I think. There' s no reason to change the
behavior of pages that can' t be orphaned.

--- linux/mm/swap_state.c.orig Sun Sep 27 23:25:52 1998
+++ linux/mm/swap_state.c Mon Sep 28 15:28:01 1998
@@ -250,8 +250,27 @@
/*
* If we are the only user, then free up the swap cache.
*/
- if (PageSwapCache(page) && !is_page_shared(page)) {
- delete_from_swap_cache(page);
+ if (PageSwapCache(page))
+ {
+ if (!is_page_shared(page))
+ delete_from_swap_cache(page);
+ else
+ /*
+ * Special case: if we have still got other
+ * references to this page, but all such references
+ * are to the swap entry rather than to the physical
+ * page, then we are only keeping this page for
+ * caching purposes. If the remaining process
+ * references are killed, we will be left with an
+ * orphaned swap entry from the cache. Make sure
+ * that such pages are easily cleaned out of the page
+ * cache.
+ */
+ if (atomic_read(&page->count) == 1)
+ {
+ clear_bit(PG_referenced, &page->flags);
+ page->age = 0;
+ }
}

free_page(addr);

This patch is completly untested but I think that it' s right in all cases
(also if we will avoid the garbage in the swap cache using my swap_free()
hack or other ways..).

>This doesn't eliminate the orphaned swap entries, but does make sure
>they are reaped rapidly by shrink_mmap once we get short of memory again

Note also that there are two kind of orphaned swap entries. The useful
ones and the garbage/orphaned ones. shrink_mmap() is not aware of that
right now.

BTW, I am still running the patch with the swap_free() changed and it' s
running fine here. I can' t see any performance degradation under swapping
and the patch is very simple and totally avoid the garbage in the swap
cache. I should produce some number before speak though ;-)... (if
somebody would have a swap benchmark it' s welcome...).

>The "clean" solution is to prevent the swap cache from acting as a
>reference to the swap entry underneath, but that becomes nasty. The
>only way we can make that work is to change the swap entry accounting so
>that read-only COW mappings of swap pages count both against the swap
>entry and the physical page. In that case, the last exit() of a cached
>swap entry will instantly free the swap entry (but will not free the
>swap cache: we still need shrink_mmap for that). It may be that the
>per-swap-entry cache flag is the way to go, for the reason that it tells
>us precisely when to bother cleaning up both the page cache and the swap
>entry reference in the case of final exit of a swapped page.

I am pretty sure that we don' t want garbage in the swap cache so
something should be done first or before to avoid that (to allow
shrink_mmap() do to its work right). To be rasonable mm efficient we need
to _avoid_ the case where shrink_mmap() could free an useful cache page
instead of removing an garbage/orphaned entry from the swap cache.

Andrea[s] Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/