From: Frederic Weisbecker <fweisbec@gmail.com>
To: Paul Menage <menage@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Li Zefan <lizf@cn.fujitsu.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Aditya Kali <adityakali@google.com>
Subject: Re: [PATCH 6/7] cgroups: Add res counter common ancestor searching
Date: Thu, 28 Jul 2011 16:54:10 +0200 [thread overview]
Message-ID: <20110728145406.GI11820@somewhere.redhat.com> (raw)
In-Reply-To: <CAJniumUGC5-KS5Rbg0SkHv5xD4XtAifYAaEM1-X-W7zbgCwCcg@mail.gmail.com>
On Mon, Jul 25, 2011 at 06:05:00PM -0700, Paul Menage wrote:
> On Mon, Jul 11, 2011 at 7:15 AM, Frederic Weisbecker <fweisbec@gmail.com> wrote:
> > Add a new API to find the common ancestor between two resource
> > counters. This includes the passed resource counter themselves.
> >
> > Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
>
> Acked-by: Paul Menage <menage@google.com>
>
> There's something distasteful about doing an O(N^2) search on every
> charge/uncharge operation, but I guess in general N isn't going to be
> more than 2 or 3 so it's not worth optimizing.
>
> If you wanted to avoid the N^2 search then you could add a "depth"
> field in struct res_counter, which would be initialized to
> parent->depth+1, and then easily get both r1 and r2 to the same depth
> before proceeding up the tree in lock step, but that would bloat all
> instances of res_counter, which might work out as more expensive in
> the long run.
Yeah it only happens on slow paths and probably cgroups hierarchies don't
tend to be so deep.
But if that's a problem we can still optimize the way you said, and perhaps
move that depth field into the struct task_counter instead.
Thanks.
>
> Paul
>
> > Cc: Paul Menage <menage@google.com>
> > Cc: Li Zefan <lizf@cn.fujitsu.com>
> > Cc: Johannes Weiner <hannes@cmpxchg.org>
> > Cc: Aditya Kali <adityakali@google.com>
> > ---
> > include/linux/res_counter.h | 2 ++
> > kernel/res_counter.c | 19 +++++++++++++++++++
> > 2 files changed, 21 insertions(+), 0 deletions(-)
> >
> > diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
> > index 8c421ac..354ed30 100644
> > --- a/include/linux/res_counter.h
> > +++ b/include/linux/res_counter.h
> > @@ -139,6 +139,8 @@ void res_counter_uncharge_until(struct res_counter *counter, struct res_counter
> > unsigned long val);
> > void res_counter_uncharge(struct res_counter *counter, unsigned long val);
> >
> > +struct res_counter *res_counter_common_ancestor(struct res_counter *l, struct res_counter *r);
> > +
> > /**
> > * res_counter_margin - calculate chargeable space of a counter
> > * @cnt: the counter
> > diff --git a/kernel/res_counter.c b/kernel/res_counter.c
> > index 39f2513..1b2efd6 100644
> > --- a/kernel/res_counter.c
> > +++ b/kernel/res_counter.c
> > @@ -102,6 +102,25 @@ void res_counter_uncharge(struct res_counter *counter, unsigned long val)
> > res_counter_uncharge_until(counter, NULL, val);
> > }
> >
> > +struct res_counter *
> > +res_counter_common_ancestor(struct res_counter *r1, struct res_counter *r2)
> > +{
> > + struct res_counter *iter;
> > +
> > + while (r1) {
> > + iter = r2;
> > + while (iter) {
> > + if (iter == r1)
> > + return iter;
> > + iter = iter->parent;
> > + }
> > +
> > + r1 = r1->parent;
> > + }
> > +
> > + return NULL;
> > +}
> > +
> > static inline unsigned long long *
> > res_counter_member(struct res_counter *counter, int member)
> > {
> > --
> > 1.7.5.4
> >
> >
next prev parent reply other threads:[~2011-07-28 14:54 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-11 14:14 [PATCH 0/7] cgroups: New max number of tasks subsystem (was: cgroups rlim subsystem) Frederic Weisbecker
2011-07-11 14:15 ` [PATCH 1/7] cgroups: Add res_counter_write_u64() API Frederic Weisbecker
2011-07-11 20:30 ` Paul Menage
2011-07-11 14:15 ` [PATCH 2/7] cgroups: New resource counter inheritance API Frederic Weisbecker
2011-07-11 20:41 ` Paul Menage
2011-07-13 12:34 ` Frederic Weisbecker
2011-07-11 14:15 ` [PATCH 3/7] cgroups: Add previous cgroup in can_attach_task/attach_task callbacks Frederic Weisbecker
2011-07-11 20:42 ` Paul Menage
2011-07-11 14:15 ` [PATCH 4/7] cgroups: New cancel_attach_task subsystem callback Frederic Weisbecker
2011-07-26 0:57 ` Paul Menage
2011-07-11 14:15 ` [PATCH 5/7] cgroups: Ability to stop res charge propagation on bounded ancestor Frederic Weisbecker
2011-07-12 0:11 ` KAMEZAWA Hiroyuki
2011-07-13 13:50 ` Frederic Weisbecker
2011-07-26 0:50 ` Paul Menage
2011-07-11 14:15 ` [PATCH 6/7] cgroups: Add res counter common ancestor searching Frederic Weisbecker
2011-07-26 1:05 ` Paul Menage
2011-07-28 14:54 ` Frederic Weisbecker [this message]
2011-07-11 14:15 ` [PATCH 7/7] cgroups: Add a max number of tasks subsystem Frederic Weisbecker
2011-07-26 1:17 ` Paul Menage
2011-07-26 1:25 ` Li Zefan
2011-07-28 15:06 ` Frederic Weisbecker
2011-07-11 14:26 ` [PATCH 0/7] cgroups: New max number of tasks subsystem (was: cgroups rlim subsystem) Frederic Weisbecker
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=20110728145406.GI11820@somewhere.redhat.com \
--to=fweisbec@gmail.com \
--cc=adityakali@google.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizf@cn.fujitsu.com \
--cc=menage@google.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 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.