mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
To: Rik van Riel <riel@redhat.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
	akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] take pageout refcount into account for remove_exclusive_swap_page
Date: Tue, 13 May 2008 13:43:55 -0400	[thread overview]
Message-ID: <1210700635.6208.40.camel@lts-notebook> (raw)
In-Reply-To: <20080513120417.0833cec1@cuia.bos.redhat.com>

On Tue, 2008-05-13 at 12:04 -0400, Rik van Riel wrote:
> The pageout code takes a reference count to the page, which means
> that remove_exclusive_swap_page (when called from the pageout code)
> needs to take that extra refcount into account for mapped pages.
> 
> Introduces a remove_exclusive_swap_page_ref function to avoid
> exposing too much magic to the rest of the VM.
> 
> Signed-off-by: Rik van Riel <riel@redhat.com>
> Debugged-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
> 
> ---
> Daisuke: thank you for pointing out the problem.  Does this patch look like
> a reasonable fix to you?
> 
> Andrew: this patch is incremental to my patch
> 	"[PATCH -mm 05/15] free swap space on swap-in/activation"
> 
> 
> Index: linux-2.6.25-mm1/mm/vmscan.c
> ===================================================================
> --- linux-2.6.25-mm1.orig/mm/vmscan.c	2008-05-13 11:59:34.000000000 -0400
> +++ linux-2.6.25-mm1/mm/vmscan.c	2008-05-13 11:54:03.000000000 -0400
> @@ -621,7 +621,7 @@ free_it:
>  activate_locked:
>  		/* Not a candidate for swapping, so reclaim swap space. */
>  		if (PageSwapCache(page) && vm_swap_full())
> -			remove_exclusive_swap_page(page);
> +			remove_exclusive_swap_page_ref(page);
>  		SetPageActive(page);
>  		pgactivate++;
>  keep_locked:
> Index: linux-2.6.25-mm1/mm/swap.c
> ===================================================================
> --- linux-2.6.25-mm1.orig/mm/swap.c	2008-05-13 11:59:34.000000000 -0400
> +++ linux-2.6.25-mm1/mm/swap.c	2008-05-13 11:53:47.000000000 -0400
> @@ -455,7 +455,7 @@ void pagevec_swap_free(struct pagevec *p
>  
>  		if (PageSwapCache(page) && !TestSetPageLocked(page)) {
>  			if (PageSwapCache(page))
> -				remove_exclusive_swap_page(page);
> +				remove_exclusive_swap_page_ref(page);
>  			unlock_page(page);
>  		}
>  	}
> Index: linux-2.6.25-mm1/include/linux/swap.h
> ===================================================================
> --- linux-2.6.25-mm1.orig/include/linux/swap.h	2008-05-13 11:20:46.000000000 -0400
> +++ linux-2.6.25-mm1/include/linux/swap.h	2008-05-13 11:47:31.000000000 -0400
> @@ -266,6 +266,7 @@ extern sector_t swapdev_block(int, pgoff
>  extern struct swap_info_struct *get_swap_info_struct(unsigned);
>  extern int can_share_swap_page(struct page *);
>  extern int remove_exclusive_swap_page(struct page *);
> +extern int remove_exclusive_swap_page_ref(struct page *);
>  struct backing_dev_info;
>  
>  extern spinlock_t swap_lock;
> Index: linux-2.6.25-mm1/mm/swapfile.c
> ===================================================================
> --- linux-2.6.25-mm1.orig/mm/swapfile.c	2008-04-22 10:33:45.000000000 -0400
> +++ linux-2.6.25-mm1/mm/swapfile.c	2008-05-13 11:53:32.000000000 -0400
> @@ -343,7 +343,7 @@ int can_share_swap_page(struct page *pag
>   * Work out if there are any other processes sharing this
>   * swap cache page. Free it if you can. Return success.
>   */
> -int remove_exclusive_swap_page(struct page *page)
> +static int remove_exclusive_swap_page_count(struct page *page, int count)
>  {
>  	int retval;
>  	struct swap_info_struct * p;
> @@ -356,7 +356,7 @@ int remove_exclusive_swap_page(struct pa
>  		return 0;
>  	if (PageWriteback(page))
>  		return 0;
> -	if (page_count(page) != 2) /* 2: us + cache */
> +	if (page_count(page) != count) /* 2: us + cache */

Maybe change comment to "/* count:  us + ptes + cache */" ???

>  		return 0;
>  
>  	entry.val = page_private(page);
> @@ -369,7 +369,7 @@ int remove_exclusive_swap_page(struct pa
>  	if (p->swap_map[swp_offset(entry)] == 1) {
>  		/* Recheck the page count with the swapcache lock held.. */
>  		write_lock_irq(&swapper_space.tree_lock);
> -		if ((page_count(page) == 2) && !PageWriteback(page)) {
> +		if ((page_count(page) == count) && !PageWriteback(page)) {
>  			__delete_from_swap_cache(page);
>  			SetPageDirty(page);
>  			retval = 1;
> @@ -387,6 +387,25 @@ int remove_exclusive_swap_page(struct pa
>  }
>  
>  /*
> + * Most of the time the page should have two references: one for the
> + * process and one for the swap cache.
> + */
> +int remove_exclusive_swap_page(struct page *page)
> +{
> +	return remove_exclusive_swap_page_count(page, 2);
> +}
> +
> +/*
> + * The pageout code holds an extra reference to the page.  That raises
> + * the reference count to test for to 2 for a page that is only in the
> + * swap cache and 3 for a page that is mapped by a process.

Or, more generally, 2 + N, for an anon page that is mapped [must be
read-only, right?] by N processes.  This can happen after, e.g., fork().
Looks like this patch handles the condition just fine, but you might
want to reflect this in the comment.

Now, I think I can use this to try to remove anon pages from the swap
cache when they're mlocked.

> + */
> +int remove_exclusive_swap_page_ref(struct page *page)
> +{
> +	return remove_exclusive_swap_page_count(page, 2 + page_mapped(page));
> +}
> +
> +/*
>   * Free the swap entry like above, but also try to
>   * free the page cache entry if it is the last user.
>   */
> 
> All Rights Reversed


  reply	other threads:[~2008-05-13 17:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-28 18:18 [PATCH -mm 00/15] VM pageout scalability improvements (V6) Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 01/15] FYI: vmstats are "off-by-one" Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 02/15] move isolate_lru_page() to vmscan.c Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 03/15] Use an indexed array for LRU variables Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 04/15] use an array for the LRU pagevecs Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 05/15] free swap space on swap-in/activation Rik van Riel
2008-05-12 11:21   ` Daisuke Nishimura
2008-05-12 13:33     ` Rik van Riel
2008-05-13 13:00       ` Daisuke Nishimura
2008-05-13 13:11         ` Rik van Riel
2008-05-13 16:04         ` [PATCH] take pageout refcount into account for remove_exclusive_swap_page Rik van Riel
2008-05-13 17:43           ` Lee Schermerhorn [this message]
2008-05-13 18:09             ` Rik van Riel
2008-05-13 19:02               ` Lee Schermerhorn
2008-05-15  2:15                 ` Daisuke Nishimura
2008-05-15 17:55                   ` Lee Schermerhorn
     [not found]     ` <1210600296.7300.23.camel@lts-notebook>
2008-05-13 12:39       ` [PATCH -mm 05/15] free swap space on swap-in/activation Daisuke Nishimura
2008-04-28 18:18 ` [PATCH -mm 06/15] define page_file_cache() function Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 07/15] split LRU lists into anon & file sets Rik van Riel
2008-05-10  7:50   ` MinChan Kim
2008-04-28 18:18 ` [PATCH -mm 08/15] SEQ replacement for anonymous pages Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 09/15] add some sanity checks to get_scan_ratio Rik van Riel
2008-05-15  6:34   ` MinChan Kim
2008-05-15 13:12     ` Rik van Riel
2008-05-16  6:42       ` MinChan Kim
2008-05-16 16:47         ` Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 10/15] add newly swapped in pages to the inactive list Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 11/15] more aggressively use lumpy reclaim Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 12/15] No Reclaim LRU Infrastructure Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 13/15] Non-reclaimable page statistics Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 14/15] ramfs pages are non-reclaimable Rik van Riel
2008-04-28 18:18 ` [PATCH -mm 15/15] SHM_LOCKED pages are nonreclaimable Rik van Riel
2008-04-28 19:55 ` [PATCH -mm 00/15] VM pageout scalability improvements (V6) Rik van Riel
2008-05-08  4:54 ` Rik van Riel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1210700635.6208.40.camel@lts-notebook \
    --to=lee.schermerhorn@hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nishimura@mxp.nes.nec.co.jp \
    --cc=riel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome