linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.cz>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vladimir Davydov <vdavydov@parallels.com>,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [patch 2/2] mm: memcontrol: fix missed end-writeback page accounting
Date: Thu, 23 Oct 2014 17:03:21 +0200	[thread overview]
Message-ID: <20141023150321.GJ23011@dhcp22.suse.cz> (raw)
In-Reply-To: <20141023135729.GB24269@phnom.home.cmpxchg.org>

On Thu 23-10-14 09:57:29, Johannes Weiner wrote:
[...]
> From b518d88254b01be8c6c0c4a496d9f311f0c71b4a Mon Sep 17 00:00:00 2001
> From: Johannes Weiner <hannes@cmpxchg.org>
> Date: Thu, 23 Oct 2014 09:29:06 -0400
> Subject: [patch] mm: rmap: split out page_remove_file_rmap()
> 
> page_remove_rmap() has too many branches on PageAnon() and is hard to
> follow.  Move the file part into a separate function.
> 
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Reviewed-by: Michal Hocko <mhocko@suse.cz>

> ---
>  mm/rmap.c | 78 +++++++++++++++++++++++++++++++++++++--------------------------
>  1 file changed, 46 insertions(+), 32 deletions(-)
> 
> diff --git a/mm/rmap.c b/mm/rmap.c
> index f574046f77d4..19886fb2f13a 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1054,6 +1054,36 @@ void page_add_file_rmap(struct page *page)
>  	mem_cgroup_end_page_stat(memcg, locked, flags);
>  }
>  
> +static void page_remove_file_rmap(struct page *page)
> +{
> +	struct mem_cgroup *memcg;
> +	unsigned long flags;
> +	bool locked;
> +
> +	memcg = mem_cgroup_begin_page_stat(page, &locked, &flags);
> +
> +	/* page still mapped by someone else? */
> +	if (!atomic_add_negative(-1, &page->_mapcount))
> +		goto out;
> +
> +	/* Hugepages are not counted in NR_FILE_MAPPED for now. */
> +	if (unlikely(PageHuge(page)))
> +		goto out;
> +
> +	/*
> +	 * We use the irq-unsafe __{inc|mod}_zone_page_stat because
> +	 * these counters are not modified in interrupt context, and
> +	 * pte lock(a spinlock) is held, which implies preemption disabled.
> +	 */
> +	__dec_zone_page_state(page, NR_FILE_MAPPED);
> +	mem_cgroup_dec_page_stat(memcg, MEM_CGROUP_STAT_FILE_MAPPED);
> +
> +	if (unlikely(PageMlocked(page)))
> +		clear_page_mlock(page);
> +out:
> +	mem_cgroup_end_page_stat(memcg, locked, flags);
> +}
> +
>  /**
>   * page_remove_rmap - take down pte mapping from a page
>   * @page: page to remove mapping from
> @@ -1062,46 +1092,33 @@ void page_add_file_rmap(struct page *page)
>   */
>  void page_remove_rmap(struct page *page)
>  {
> -	struct mem_cgroup *uninitialized_var(memcg);
> -	bool anon = PageAnon(page);
> -	unsigned long flags;
> -	bool locked;
> -
> -	/*
> -	 * The anon case has no mem_cgroup page_stat to update; but may
> -	 * uncharge_page() below, where the lock ordering can deadlock if
> -	 * we hold the lock against page_stat move: so avoid it on anon.
> -	 */
> -	if (!anon)
> -		memcg = mem_cgroup_begin_page_stat(page, &locked, &flags);
> +	if (!PageAnon(page)) {
> +		page_remove_file_rmap(page);
> +		return;
> +	}
>  
>  	/* page still mapped by someone else? */
>  	if (!atomic_add_negative(-1, &page->_mapcount))
> -		goto out;
> +		return;
> +
> +	/* Hugepages are not counted in NR_ANON_PAGES for now. */
> +	if (unlikely(PageHuge(page)))
> +		return;
>  
>  	/*
> -	 * Hugepages are not counted in NR_ANON_PAGES nor NR_FILE_MAPPED
> -	 * and not charged by memcg for now.
> -	 *
>  	 * We use the irq-unsafe __{inc|mod}_zone_page_stat because
>  	 * these counters are not modified in interrupt context, and
> -	 * these counters are not modified in interrupt context, and
>  	 * pte lock(a spinlock) is held, which implies preemption disabled.
>  	 */
> -	if (unlikely(PageHuge(page)))
> -		goto out;
> -	if (anon) {
> -		if (PageTransHuge(page))
> -			__dec_zone_page_state(page,
> -					      NR_ANON_TRANSPARENT_HUGEPAGES);
> -		__mod_zone_page_state(page_zone(page), NR_ANON_PAGES,
> -				-hpage_nr_pages(page));
> -	} else {
> -		__dec_zone_page_state(page, NR_FILE_MAPPED);
> -		mem_cgroup_dec_page_stat(memcg, MEM_CGROUP_STAT_FILE_MAPPED);
> -	}
> +	if (PageTransHuge(page))
> +		__dec_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES);
> +
> +	__mod_zone_page_state(page_zone(page), NR_ANON_PAGES,
> +			      -hpage_nr_pages(page));
> +
>  	if (unlikely(PageMlocked(page)))
>  		clear_page_mlock(page);
> +
>  	/*
>  	 * It would be tidy to reset the PageAnon mapping here,
>  	 * but that might overwrite a racing page_add_anon_rmap
> @@ -1111,9 +1128,6 @@ void page_remove_rmap(struct page *page)
>  	 * Leaving it set also helps swapoff to reinstate ptes
>  	 * faster for those pages still in swapcache.
>  	 */
> -out:
> -	if (!anon)
> -		mem_cgroup_end_page_stat(memcg, locked, flags);
>  }
>  
>  /*
> -- 
> 2.1.2
> 

-- 
Michal Hocko
SUSE Labs

--
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:[~2014-10-23 15:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 18:29 [patch 0/2] mm: memcontrol: fix race between migration and writeback Johannes Weiner
2014-10-22 18:29 ` [patch 1/2] mm: page-writeback: inline account_page_dirtied() into single caller Johannes Weiner
2014-10-23 12:21   ` Michal Hocko
2014-10-22 18:29 ` [patch 2/2] mm: memcontrol: fix missed end-writeback page accounting Johannes Weiner
2014-10-22 20:39   ` Andrew Morton
2014-10-23 13:54     ` Johannes Weiner
2014-10-23 15:00       ` Michal Hocko
2014-10-23 13:57     ` Johannes Weiner
2014-10-23 15:03       ` Michal Hocko [this message]
2014-10-23 13:03   ` Michal Hocko
2014-10-23 14:14     ` Johannes Weiner
2014-10-23 14:51       ` Michal Hocko

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=20141023150321.GJ23011@dhcp22.suse.cz \
    --to=mhocko@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vdavydov@parallels.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