linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vladimir Davydov <vdavydov@virtuozzo.com>,
	linux-mm@kvack.org, cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH] mm: memcontrol: do not uncharge old page in page cache replacement
Date: Thu, 28 Jan 2016 17:04:29 +0100	[thread overview]
Message-ID: <20160128160429.GF15948@dhcp22.suse.cz> (raw)
In-Reply-To: <1452721917-24614-1-git-send-email-hannes@cmpxchg.org>

[Ups this one somehow fall through cracks]

On Wed 13-01-16 16:51:57, Johannes Weiner wrote:
> Changing page->mem_cgroup of a live page is tricky and fragile. In
> particular, the memcg writeback code relies on that mapping being
> stable and users of mem_cgroup_replace_page() not overlapping with
> dirtyable inodes.
> 
> Page cache replacement doesn't have to do that, though. Instead of
> being clever and transfering the charge from the old page to the new,
> force-charge the new page and leave the old page alone. A temporary
> overcharge won't matter in practice, and the old page is going to be
> freed shortly after this anyway. And this is not performance critical.

OK, this makes sense to me.
 
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/memcontrol.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index d75028d..c26ffac 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -366,13 +366,6 @@ mem_cgroup_zone_zoneinfo(struct mem_cgroup *memcg, struct zone *zone)
>   *
>   * If memcg is bound to a traditional hierarchy, the css of root_mem_cgroup
>   * is returned.
> - *
> - * XXX: The above description of behavior on the default hierarchy isn't
> - * strictly true yet as replace_page_cache_page() can modify the
> - * association before @page is released even on the default hierarchy;
> - * however, the current and planned usages don't mix the the two functions
> - * and replace_page_cache_page() will soon be updated to make the invariant
> - * actually true.
>   */
>  struct cgroup_subsys_state *mem_cgroup_css_from_page(struct page *page)
>  {
> @@ -5463,7 +5456,8 @@ void mem_cgroup_uncharge_list(struct list_head *page_list)
>  void mem_cgroup_replace_page(struct page *oldpage, struct page *newpage)
>  {
>  	struct mem_cgroup *memcg;
> -	int isolated;
> +	unsigned int nr_pages;
> +	bool compound;
>  
>  	VM_BUG_ON_PAGE(!PageLocked(oldpage), oldpage);
>  	VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
> @@ -5483,11 +5477,21 @@ void mem_cgroup_replace_page(struct page *oldpage, struct page *newpage)
>  	if (!memcg)
>  		return;
>  
> -	lock_page_lru(oldpage, &isolated);
> -	oldpage->mem_cgroup = NULL;
> -	unlock_page_lru(oldpage, isolated);
> +	/* Force-charge the new page. The old one will be freed soon */
> +	compound = PageTransHuge(newpage);
> +	nr_pages = compound ? hpage_nr_pages(newpage) : 1;
> +
> +	page_counter_charge(&memcg->memory, nr_pages);
> +	if (do_memsw_account())
> +		page_counter_charge(&memcg->memsw, nr_pages);
> +	css_get_many(&memcg->css, nr_pages);
>  
>  	commit_charge(newpage, memcg, true);
> +
> +	local_irq_disable();
> +	mem_cgroup_charge_statistics(memcg, newpage, compound, nr_pages);
> +	memcg_check_events(memcg, newpage);
> +	local_irq_enable();
>  }
>  
>  DEFINE_STATIC_KEY_FALSE(memcg_sockets_enabled_key);
> -- 
> 2.7.0

-- 
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:[~2016-01-28 16:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-13 21:51 Johannes Weiner
2016-01-28 16:04 ` Michal Hocko [this message]

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=20160128160429.GF15948@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vdavydov@virtuozzo.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