linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: balbir@linux.vnet.ibm.com
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
	"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH] Reduce size of swap_cgroup by CSS ID v2
Date: Tue, 10 Feb 2009 17:50:19 +0900	[thread overview]
Message-ID: <20090210175019.b100b279.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20090210080700.GC16317@balbir.in.ibm.com>

On Tue, 10 Feb 2009 13:37:00 +0530
Balbir Singh <balbir@linux.vnet.ibm.com> wrote:

> * KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> [2009-02-09 14:55:57]:
> 
> > From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> >  static struct mem_cgroup *try_get_mem_cgroup_from_swapcache(struct page *page)
> >  {
> > -	struct mem_cgroup *mem;
> > +	unsigned short id;
> > +	struct mem_cgroup *mem = NULL;
> >  	swp_entry_t ent;
> > 
> >  	if (!PageSwapCache(page))
> >  		return NULL;
> > 
> >  	ent.val = page_private(page);
> > -	mem = lookup_swap_cgroup(ent);
> > -	if (!mem)
> > -		return NULL;
> > +	id = lookup_swap_cgroup(ent);
> > +	rcu_read_lock();
> > +	mem = mem_cgroup_lookup(id);
> >  	if (!css_tryget(&mem->css))
> > -		return NULL;
> > +		mem = NULL;
> 
> This part is a bit confusing. If the page got swapped out and the CSS
> it belonged to got swapped out, we set mem to NULL. Is this so that it
> can be charged to root cgroup?
IIUC, this charge will go to "current" process's cgroup.

> If so, could you please add a comment indicating the same.
> 
Ah yes, I'll add some comments.


> > +	rcu_read_unlock();
> >  	return mem;
> >  }
> > 
> > @@ -1275,12 +1296,20 @@ int mem_cgroup_cache_charge(struct page 
> > 
> >  	if (do_swap_account && !ret && PageSwapCache(page)) {
> >  		swp_entry_t ent = {.val = page_private(page)};
> > +		unsigned short id;
> >  		/* avoid double counting */
> > -		mem = swap_cgroup_record(ent, NULL);
> > +		id = swap_cgroup_record(ent, 0);
> > +		rcu_read_lock();
> > +		mem = mem_cgroup_lookup(id);
> >  		if (mem) {
> > +			/*
> > +			 * Recorded ID can be obsolete. We avoid calling
> > +			 * css_tryget()
> > +			 */
> >  			res_counter_uncharge(&mem->memsw, PAGE_SIZE);
> >  			mem_cgroup_put(mem);
> >  		}
> 
> If !mem, do we leak charge?
No, it just means some other thread removed the ID before us.

> BTW, We no longer hold css references if the page is swapped out?
> 
The situation is a bit complicated.
When cgroup is obsolete but its mem_cgroup is alive (because of reference
from swap), css_tryget() always fails. swap_cgroup_record() is atomic
compare-and-exchange, so I think we can trust mem_cgroup_put/get refcnt
management and doesn't need to rely on css's refcnt at swap management.


Thanks,
-Kame

--
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-02-10  8:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-05  9:59 [RFC][PATCH] Reduce size of swap_cgroup by CSS ID KAMEZAWA Hiroyuki
2009-02-05 13:17 ` Paul E. McKenney
2009-02-05 13:27   ` KAMEZAWA Hiroyuki
2009-02-06  2:07 ` Li Zefan
2009-02-06  2:18   ` KAMEZAWA Hiroyuki
2009-02-09  5:55 ` [RFC][PATCH] Reduce size of swap_cgroup by CSS ID v2 KAMEZAWA Hiroyuki
2009-02-10  8:07   ` Balbir Singh
2009-02-10  8:50     ` KAMEZAWA Hiroyuki [this message]
2009-02-23  5:58   ` Daisuke Nishimura
2009-02-24  0:10     ` KAMEZAWA Hiroyuki

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=20090210175019.b100b279.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=nishimura@mxp.nes.nec.co.jp \
    /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