Re: [PATCH -mm 04/25] free swap space on swap-in/activation

From: Andrew Morton
Date: Fri Jun 06 2008 - 21:06:21 EST


On Fri, 06 Jun 2008 16:28:42 -0400
Rik van Riel <riel@xxxxxxxxxx> wrote:

> From: Rik van Riel <riel@xxxxxxxxxx>
>
> Free swap cache entries when swapping in pages if vm_swap_full()
> [swap space > 1/2 used]. Uses new pagevec to reduce pressure
> on locks.
>
> Signed-off-by: Rik van Riel <riel@xxxxxxxxxx>
> Signed-off-by: Lee Schermerhorn <Lee.Schermerhorn@xxxxxx>
> Signed-off-by: MinChan Kim <minchan.kim@xxxxxxxxx>
>
> ---
> include/linux/pagevec.h | 1 +
> include/linux/swap.h | 6 ++++++
> mm/swap.c | 18 ++++++++++++++++++
> mm/swapfile.c | 25 ++++++++++++++++++++++---
> mm/vmscan.c | 7 +++++++
> 5 files changed, 54 insertions(+), 3 deletions(-)
>
> Index: linux-2.6.26-rc2-mm1/mm/vmscan.c
> ===================================================================
> --- linux-2.6.26-rc2-mm1.orig/mm/vmscan.c 2008-05-23 14:21:33.000000000 -0400
> +++ linux-2.6.26-rc2-mm1/mm/vmscan.c 2008-05-23 14:21:33.000000000 -0400
> @@ -619,6 +619,9 @@ free_it:
> continue;
>
> activate_locked:
> + /* Not a candidate for swapping, so reclaim swap space. */
> + if (PageSwapCache(page) && vm_swap_full())

The patch puts rather a lot of pressure onto vm_swap_full(). We might
want to look into optimising that.

- Is the 50% thing optimum? Could go higher and perhaps should be
based on amount-of-memory.

- Can precalculate the fraction rather than doing it inline all the time.

- Can make total_swap_pages __read_mostly and have a think about
nr_swap_pages too.

- Can completely optimise the thing away if !CONFIG_SWAP.


Has all this code been tested with CONFIG_SWAP=n?

> Index: linux-2.6.26-rc2-mm1/mm/swap.c
> ===================================================================
> --- linux-2.6.26-rc2-mm1.orig/mm/swap.c 2008-05-23 14:21:33.000000000 -0400
> +++ linux-2.6.26-rc2-mm1/mm/swap.c 2008-05-23 14:21:33.000000000 -0400
> @@ -443,6 +443,24 @@ void pagevec_strip(struct pagevec *pvec)
> }
> }
>
> +/*
> + * Try to free swap space from the pages in a pagevec
> + */
> +void pagevec_swap_free(struct pagevec *pvec)
> +{
> + int i;
> +
> + for (i = 0; i < pagevec_count(pvec); i++) {
> + struct page *page = pvec->pages[i];
> +
> + if (PageSwapCache(page) && !TestSetPageLocked(page)) {
> + if (PageSwapCache(page))
> + remove_exclusive_swap_page_ref(page);
> + unlock_page(page);
> + }
> + }
> +}

What's going on here.

Normally we'll bump a page's refcount to account for its presence in a
pagevec. This code doesn't do that.

Is it safe? If so, how come?

Suitable code comments should be added which explain this unusual and
dangerous optimisation. Or fix the bug :)


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