linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"menage@google.com" <menage@google.com>,
	"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/4] cgroup: add CSS ID
Date: Thu, 22 Jan 2009 11:59:08 +0900	[thread overview]
Message-ID: <20090122115908.262f2440.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20090122113729.878e96cf.nishimura@mxp.nes.nec.co.jp>

On Thu, 22 Jan 2009 11:37:29 +0900
Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> wrote:

> Hi.
> 
> Sorry for very late reply.
> 
> It looks good in general.
> Just a few comments.
> 
> > +/**
> > + * css_lookup - lookup css by id
> > + * @ss: cgroup subsys to be looked into.
> > + * @id: the id
> > + *
> > + * Returns pointer to cgroup_subsys_state if there is valid one with id.
> > + * NULL if not. Should be called under rcu_read_lock()
> > + */
> > +struct cgroup_subsys_state *css_lookup(struct cgroup_subsys *ss, int id)
> > +{
> > +	struct css_id *cssid = NULL;
> > +
> > +	BUG_ON(!ss->use_id);
> > +	cssid = idr_find(&ss->idr, id);
> > +
> > +	if (unlikely(!cssid))
> > +		return NULL;
> > +
> > +	return rcu_dereference(cssid->css);
> > +}
> > +
> Just for clarification, is there any user of this function ?
> (I agree it's natulal to define 'lookup' function, though.)
> 
A user in my plan is swap_cgroup.



> > +/**
> > + * css_get_next - lookup next cgroup under specified hierarchy.
> > + * @ss: pointer to subsystem
> > + * @id: current position of iteration.
> > + * @root: pointer to css. search tree under this.
> > + * @foundid: position of found object.
> > + *
> > + * Search next css under the specified hierarchy of rootid. Calling under
> > + * rcu_read_lock() is necessary. Returns NULL if it reaches the end.
> > + */
> > +struct cgroup_subsys_state *
> > +css_get_next(struct cgroup_subsys *ss, int id,
> > +	     struct cgroup_subsys_state *root, int *foundid)
> > +{
> > +	struct cgroup_subsys_state *ret = NULL;
> > +	struct css_id *tmp;
> > +	int tmpid;
> > +	int rootid = css_id(root);
> > +	int depth = css_depth(root);
> > +
> I think it's safe here, but isn't it better to call css_id/css_depth
> under rcu_read_lock(they call rcu_dereference) ?
> 
As commented, this css_get_next() call should be called under rcu_read_lock().


> > +	if (!rootid)
> > +		return NULL;
> > +
> > +	BUG_ON(!ss->use_id);
> > +	rcu_read_lock();
> > +	/* fill start point for scan */
> > +	tmpid = id;
> > +	while (1) {
> > +		/*
> > +		 * scan next entry from bitmap(tree), tmpid is updated after
> > +		 * idr_get_next().
> > +		 */
> > +		spin_lock(&ss->id_lock);
> > +		tmp = idr_get_next(&ss->idr, &tmpid);
> > +		spin_unlock(&ss->id_lock);
> > +
> > +		if (!tmp)
> > +			break;
> > +		if (tmp->depth >= depth && tmp->stack[depth] == rootid) {
> Can't be css_is_ancestor used here ?
> I think it would be more easy to understand.
> 
Hmm, it requires 

	css_is_ancestor(tmp->css, root);

and adds memory barriers to acsess tmp->css and tmp->css->id, root->id
(compiler will not optimize these accesses because of memory barrier.)

So, I think bare code is better here.

Thank you for review.

-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-01-22  3:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-15 10:21 [PATCH 0/4] cgroup/memcg : updates related to CSS KAMEZAWA Hiroyuki
2009-01-15 10:25 ` [PATCH 1/4] cgroup: add CSS ID KAMEZAWA Hiroyuki
2009-01-16  1:18   ` Li Zefan
2009-01-20  1:57   ` Paul Menage
2009-01-22  2:37   ` Daisuke Nishimura
2009-01-22  2:59     ` KAMEZAWA Hiroyuki [this message]
2009-01-15 10:27 ` [PATCH 2/4] cgroup:add css_is_populated KAMEZAWA Hiroyuki
2009-01-16  3:00   ` KAMEZAWA Hiroyuki
2009-01-20  1:41     ` Paul Menage
2009-01-20  1:51       ` Li Zefan
2009-01-20  1:55         ` Paul Menage
2009-01-20  1:39   ` Paul Menage
2009-01-20  2:02     ` KAMEZAWA Hiroyuki
2009-01-20  2:23       ` Paul Menage
2009-01-20  2:58         ` KAMEZAWA Hiroyuki
2009-01-20  5:43           ` [PATCH 1.5/4] cgroup: delay populate css id KAMEZAWA Hiroyuki
2009-01-21  9:36             ` Paul Menage
2009-01-21 10:34               ` KAMEZAWA Hiroyuki
2009-01-22  2:06                 ` KAMEZAWA Hiroyuki
2009-01-22  2:13                   ` Paul Menage
2009-01-15 10:29 ` [PATCH 3/4] memcg: hierarchical reclaim by CSS ID KAMEZAWA Hiroyuki
2009-01-16  1:29   ` Li Zefan
2009-01-16  1:38     ` KAMEZAWA Hiroyuki
2009-01-16  1:49       ` Li Zefan
2009-01-16  1:58         ` KAMEZAWA Hiroyuki
2009-01-16  2:22         ` KAMEZAWA Hiroyuki
2009-01-16  7:35           ` Li Zefan
2009-01-16  7:49             ` KAMEZAWA Hiroyuki
2009-01-15 10:32 ` [PATCH 4/4] memcg : read_statistics update to show total score KAMEZAWA Hiroyuki
2009-01-15 10:51 ` [PATCH 0/4] cgroup/memcg : updates related to CSS Balbir Singh
2009-01-15 10:58   ` 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=20090122115908.262f2440.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.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