All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mel Gorman <mel@csn.ul.ie>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH for mmotm 1/5] cleanp page_remove_rmap()
Date: Thu, 11 Jun 2009 12:01:54 +0100	[thread overview]
Message-ID: <20090611110154.GD7302@csn.ul.ie> (raw)
In-Reply-To: <20090611192514.6D4D.A69D9226@jp.fujitsu.com>

On Thu, Jun 11, 2009 at 07:26:04PM +0900, KOSAKI Motohiro wrote:
> Subject: [PATCH] cleanp page_remove_rmap()
> 
> page_remove_rmap() has multiple PageAnon() test and it has
> a bit deeply nesting.
> 
> cleanup here.
> 
> note: this patch doesn't have behavior change.
> 
> 
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Cc: Mel Gorman <mel@csn.ul.ie>
> Cc: Wu Fengguang <fengguang.wu@intel.com> 
> ---
>  mm/rmap.c |   59 ++++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 32 insertions(+), 27 deletions(-)
> 
> Index: b/mm/rmap.c
> ===================================================================
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -862,34 +862,39 @@ void page_dup_rmap(struct page *page, st
>   */
>  void page_remove_rmap(struct page *page)
>  {
> -	if (atomic_add_negative(-1, &page->_mapcount)) {
> -		/*
> -		 * Now that the last pte has gone, s390 must transfer dirty
> -		 * flag from storage key to struct page.  We can usually skip
> -		 * this if the page is anon, so about to be freed; but perhaps
> -		 * not if it's in swapcache - there might be another pte slot
> -		 * containing the swap entry, but page not yet written to swap.
> -		 */
> -		if ((!PageAnon(page) || PageSwapCache(page)) &&
> -		    page_test_dirty(page)) {
> -			page_clear_dirty(page);
> -			set_page_dirty(page);
> -		}
> -		if (PageAnon(page))
> -			mem_cgroup_uncharge_page(page);
> -		__dec_zone_page_state(page,
> -			PageAnon(page) ? NR_ANON_PAGES : NR_FILE_MAPPED);
> -		mem_cgroup_update_mapped_file_stat(page, -1);
> -		/*
> -		 * It would be tidy to reset the PageAnon mapping here,
> -		 * but that might overwrite a racing page_add_anon_rmap
> -		 * which increments mapcount after us but sets mapping
> -		 * before us: so leave the reset to free_hot_cold_page,
> -		 * and remember that it's only reliable while mapped.
> -		 * Leaving it set also helps swapoff to reinstate ptes
> -		 * faster for those pages still in swapcache.
> -		 */
> +	if (!atomic_add_negative(-1, &page->_mapcount)) {
> +		/* the page is still mapped another one */
> +		return;
>  	}
> +
> +	/*
> +	 * Now that the last pte has gone, s390 must transfer dirty
> +	 * flag from storage key to struct page.  We can usually skip
> +	 * this if the page is anon, so about to be freed; but perhaps
> +	 * not if it's in swapcache - there might be another pte slot
> +	 * containing the swap entry, but page not yet written to swap.
> +	 */
> +	if ((!PageAnon(page) || PageSwapCache(page)) &&
> +		page_test_dirty(page)) {
> +		page_clear_dirty(page);
> +		set_page_dirty(page);
> +	}

Pure nitpick. It looks like page_test_dirty() can merge with the line
above it now. Then the condition won't be at the same indentation as the
statements.


> +	if (PageAnon(page)) {
> +		mem_cgroup_uncharge_page(page);
> +		__dec_zone_page_state(page, NR_ANON_PAGES);
> +	} else {
> +		__dec_zone_page_state(page, NR_FILE_MAPPED);
> +	}

Ok, first actual change and it looks functionally equivalent and avoids a
second PageAnon test. I suspect it fractionally increases text size but as
PageAnon is an atomic bit opreation, we want to avoid calling that twice too.

> +	mem_cgroup_update_mapped_file_stat(page, -1);
> +	/*
> +	 * It would be tidy to reset the PageAnon mapping here,
> +	 * but that might overwrite a racing page_add_anon_rmap
> +	 * which increments mapcount after us but sets mapping
> +	 * before us: so leave the reset to free_hot_cold_page,
> +	 * and remember that it's only reliable while mapped.
> +	 * Leaving it set also helps swapoff to reinstate ptes
> +	 * faster for those pages still in swapcache.
> +	 */
>  }
>  

Ok, patch looks good to me. I'm not seeing what it has to do with the
zone_reclaim() problem though so you might want to send it separate from
the set for clarity.

Acked-by: Mel Gorman <mel@csn.ul.ie>

-- 
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

WARNING: multiple messages have this Message-ID (diff)
From: Mel Gorman <mel@csn.ul.ie>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH for mmotm 1/5] cleanp page_remove_rmap()
Date: Thu, 11 Jun 2009 12:01:54 +0100	[thread overview]
Message-ID: <20090611110154.GD7302@csn.ul.ie> (raw)
In-Reply-To: <20090611192514.6D4D.A69D9226@jp.fujitsu.com>

On Thu, Jun 11, 2009 at 07:26:04PM +0900, KOSAKI Motohiro wrote:
> Subject: [PATCH] cleanp page_remove_rmap()
> 
> page_remove_rmap() has multiple PageAnon() test and it has
> a bit deeply nesting.
> 
> cleanup here.
> 
> note: this patch doesn't have behavior change.
> 
> 
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Cc: Mel Gorman <mel@csn.ul.ie>
> Cc: Wu Fengguang <fengguang.wu@intel.com> 
> ---
>  mm/rmap.c |   59 ++++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 32 insertions(+), 27 deletions(-)
> 
> Index: b/mm/rmap.c
> ===================================================================
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -862,34 +862,39 @@ void page_dup_rmap(struct page *page, st
>   */
>  void page_remove_rmap(struct page *page)
>  {
> -	if (atomic_add_negative(-1, &page->_mapcount)) {
> -		/*
> -		 * Now that the last pte has gone, s390 must transfer dirty
> -		 * flag from storage key to struct page.  We can usually skip
> -		 * this if the page is anon, so about to be freed; but perhaps
> -		 * not if it's in swapcache - there might be another pte slot
> -		 * containing the swap entry, but page not yet written to swap.
> -		 */
> -		if ((!PageAnon(page) || PageSwapCache(page)) &&
> -		    page_test_dirty(page)) {
> -			page_clear_dirty(page);
> -			set_page_dirty(page);
> -		}
> -		if (PageAnon(page))
> -			mem_cgroup_uncharge_page(page);
> -		__dec_zone_page_state(page,
> -			PageAnon(page) ? NR_ANON_PAGES : NR_FILE_MAPPED);
> -		mem_cgroup_update_mapped_file_stat(page, -1);
> -		/*
> -		 * It would be tidy to reset the PageAnon mapping here,
> -		 * but that might overwrite a racing page_add_anon_rmap
> -		 * which increments mapcount after us but sets mapping
> -		 * before us: so leave the reset to free_hot_cold_page,
> -		 * and remember that it's only reliable while mapped.
> -		 * Leaving it set also helps swapoff to reinstate ptes
> -		 * faster for those pages still in swapcache.
> -		 */
> +	if (!atomic_add_negative(-1, &page->_mapcount)) {
> +		/* the page is still mapped another one */
> +		return;
>  	}
> +
> +	/*
> +	 * Now that the last pte has gone, s390 must transfer dirty
> +	 * flag from storage key to struct page.  We can usually skip
> +	 * this if the page is anon, so about to be freed; but perhaps
> +	 * not if it's in swapcache - there might be another pte slot
> +	 * containing the swap entry, but page not yet written to swap.
> +	 */
> +	if ((!PageAnon(page) || PageSwapCache(page)) &&
> +		page_test_dirty(page)) {
> +		page_clear_dirty(page);
> +		set_page_dirty(page);
> +	}

Pure nitpick. It looks like page_test_dirty() can merge with the line
above it now. Then the condition won't be at the same indentation as the
statements.


> +	if (PageAnon(page)) {
> +		mem_cgroup_uncharge_page(page);
> +		__dec_zone_page_state(page, NR_ANON_PAGES);
> +	} else {
> +		__dec_zone_page_state(page, NR_FILE_MAPPED);
> +	}

Ok, first actual change and it looks functionally equivalent and avoids a
second PageAnon test. I suspect it fractionally increases text size but as
PageAnon is an atomic bit opreation, we want to avoid calling that twice too.

> +	mem_cgroup_update_mapped_file_stat(page, -1);
> +	/*
> +	 * It would be tidy to reset the PageAnon mapping here,
> +	 * but that might overwrite a racing page_add_anon_rmap
> +	 * which increments mapcount after us but sets mapping
> +	 * before us: so leave the reset to free_hot_cold_page,
> +	 * and remember that it's only reliable while mapped.
> +	 * Leaving it set also helps swapoff to reinstate ptes
> +	 * faster for those pages still in swapcache.
> +	 */
>  }
>  

Ok, patch looks good to me. I'm not seeing what it has to do with the
zone_reclaim() problem though so you might want to send it separate from
the set for clarity.

Acked-by: Mel Gorman <mel@csn.ul.ie>

-- 
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2009-06-11 11:02 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-11 10:25 [PATCH for mmotm 0/5] introduce swap-backed-file-mapped count and fix vmscan-change-the-number-of-the-unmapped-files-in-zone-reclaim.patch KOSAKI Motohiro
2009-06-11 10:25 ` KOSAKI Motohiro
2009-06-11 10:26 ` [PATCH for mmotm 1/5] cleanp page_remove_rmap() KOSAKI Motohiro
2009-06-11 10:26   ` KOSAKI Motohiro
2009-06-11 11:01   ` Mel Gorman [this message]
2009-06-11 11:01     ` Mel Gorman
2009-06-11 23:21   ` Wu Fengguang
2009-06-11 23:21     ` Wu Fengguang
2009-06-11 10:26 ` [PATCH for mmotm 2/5] KOSAKI Motohiro
2009-06-11 10:26   ` KOSAKI Motohiro
2009-06-11 11:13   ` Mel Gorman
2009-06-11 11:13     ` Mel Gorman
2009-06-11 11:50     ` KOSAKI Motohiro
2009-06-11 11:50       ` KOSAKI Motohiro
2009-06-12 10:22       ` Mel Gorman
2009-06-12 10:22         ` Mel Gorman
2009-06-11 23:29   ` Wu Fengguang
2009-06-11 23:29     ` Wu Fengguang
2009-06-11 10:27 ` [PATCH for mmotm 3/5] add Mapped(SwapBacked) field to /proc/meminfo KOSAKI Motohiro
2009-06-11 10:27   ` KOSAKI Motohiro
2009-06-11 10:27 ` [PATCH for mmotm 4/5] adjust fields length of /proc/meminfo KOSAKI Motohiro
2009-06-11 10:27   ` KOSAKI Motohiro
2009-06-11 10:28 ` [PATCH for mmotm 5/5] fix vmscan-change-the-number-of-the-unmapped-files-in-zone-reclaim.patch KOSAKI Motohiro
2009-06-11 10:28   ` KOSAKI Motohiro
2009-06-11 11:15   ` Mel Gorman
2009-06-11 11:15     ` Mel Gorman
2009-06-11 10:38 ` [PATCH for mmotm 0/5] introduce swap-backed-file-mapped count and " Mel Gorman
2009-06-11 10:38   ` Mel Gorman
2009-06-11 10:42   ` KOSAKI Motohiro
2009-06-11 10:42     ` KOSAKI Motohiro
2009-06-11 10:53     ` Mel Gorman
2009-06-11 10:53       ` Mel Gorman
2009-06-11 11:32       ` KOSAKI Motohiro
2009-06-11 11:32         ` KOSAKI Motohiro

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=20090611110154.GD7302@csn.ul.ie \
    --to=mel@csn.ul.ie \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.