From: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Cgroups <cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 1/3] cgroup: don't destroy the default root
Date: Wed, 4 Jun 2014 16:40:28 +0800 [thread overview]
Message-ID: <538EDB7C.2070405@huawei.com> (raw)
In-Reply-To: <20140603125728.GA26210-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
On 2014/6/3 20:57, Tejun Heo wrote:
> Hello, Li.
>
> On Tue, Jun 03, 2014 at 12:04:38PM +0800, Li Zefan wrote:
>> static void cgroup_get(struct cgroup *cgrp)
>> {
>> WARN_ON_ONCE(cgroup_is_dead(cgrp));
>> - css_get(&cgrp->self);
>> + if (!(cgrp->self.flags & CSS_NO_REF))
>> + css_get(&cgrp->self);
>
> Hmmm? The same condition is tested by css_get(). Why should it be
> tested again here?
>
Oh, I completely ignored that.
>> static void cgroup_put(struct cgroup *cgrp)
>> {
>> - css_put(&cgrp->self);
>> + if (!(cgrp->self.flags & CSS_NO_REF))
>> + css_put(&cgrp->self);
>
> Ditto.
>
>> @@ -1781,10 +1783,12 @@ static void cgroup_kill_sb(struct super_block *sb)
>> * This prevents new mounts by disabling percpu_ref_tryget_live().
>> * cgroup_mount() may wait for @root's release.
>> */
>> - if (css_has_online_children(&root->cgrp.self))
>> + if (css_has_online_children(&root->cgrp.self)) {
>> cgroup_put(&root->cgrp);
>> - else
>> - percpu_ref_kill(&root->cgrp.self.refcnt);
>> + } else {
>> + if (root != &cgrp_dfl_root)
>> + percpu_ref_kill(&root->cgrp.self.refcnt);
>> + }
>
> As conceptually percpu_ref_kill() just puts the base ref and the
> dfl_root's refcnt never reaches zero, it won't actually trigger.
Yes it will, just try mount && umount.
I think it's because cgroup_get() is a no-op for CSS_NO_REF, so it has
only the base ref, so percpu_ref_iill() will actually schedule the
call to css_release().
> Hmmm.... wouldn't the above leak a ref each time the default hierarchy
> is unmounted tho? Shouldn't it be like the following?
>
cgroup_get() is a no-op for root cgroup of the default root, so there's
no leak, but still better to call cgroup_put().
I'll send an updated patch.
> if (root == &cgrp_dfl_root || css_has_online_children(...))
> cgroup_put(&root->cgrp);
> else
> percpu_ref_kill(...);
>
> Thanks.
>
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizefan@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Cgroups <cgroups@vger.kernel.org>
Subject: Re: [PATCH 1/3] cgroup: don't destroy the default root
Date: Wed, 4 Jun 2014 16:40:28 +0800 [thread overview]
Message-ID: <538EDB7C.2070405@huawei.com> (raw)
In-Reply-To: <20140603125728.GA26210@htj.dyndns.org>
On 2014/6/3 20:57, Tejun Heo wrote:
> Hello, Li.
>
> On Tue, Jun 03, 2014 at 12:04:38PM +0800, Li Zefan wrote:
>> static void cgroup_get(struct cgroup *cgrp)
>> {
>> WARN_ON_ONCE(cgroup_is_dead(cgrp));
>> - css_get(&cgrp->self);
>> + if (!(cgrp->self.flags & CSS_NO_REF))
>> + css_get(&cgrp->self);
>
> Hmmm? The same condition is tested by css_get(). Why should it be
> tested again here?
>
Oh, I completely ignored that.
>> static void cgroup_put(struct cgroup *cgrp)
>> {
>> - css_put(&cgrp->self);
>> + if (!(cgrp->self.flags & CSS_NO_REF))
>> + css_put(&cgrp->self);
>
> Ditto.
>
>> @@ -1781,10 +1783,12 @@ static void cgroup_kill_sb(struct super_block *sb)
>> * This prevents new mounts by disabling percpu_ref_tryget_live().
>> * cgroup_mount() may wait for @root's release.
>> */
>> - if (css_has_online_children(&root->cgrp.self))
>> + if (css_has_online_children(&root->cgrp.self)) {
>> cgroup_put(&root->cgrp);
>> - else
>> - percpu_ref_kill(&root->cgrp.self.refcnt);
>> + } else {
>> + if (root != &cgrp_dfl_root)
>> + percpu_ref_kill(&root->cgrp.self.refcnt);
>> + }
>
> As conceptually percpu_ref_kill() just puts the base ref and the
> dfl_root's refcnt never reaches zero, it won't actually trigger.
Yes it will, just try mount && umount.
I think it's because cgroup_get() is a no-op for CSS_NO_REF, so it has
only the base ref, so percpu_ref_iill() will actually schedule the
call to css_release().
> Hmmm.... wouldn't the above leak a ref each time the default hierarchy
> is unmounted tho? Shouldn't it be like the following?
>
cgroup_get() is a no-op for root cgroup of the default root, so there's
no leak, but still better to call cgroup_put().
I'll send an updated patch.
> if (root == &cgrp_dfl_root || css_has_online_children(...))
> cgroup_put(&root->cgrp);
> else
> percpu_ref_kill(...);
>
> Thanks.
>
next prev parent reply other threads:[~2014-06-04 8:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-03 4:04 [PATCH 1/3] cgroup: don't destroy the default root Li Zefan
2014-06-03 4:04 ` Li Zefan
2014-06-03 4:05 ` [PATCH 2/3] cgroup: make the default root invisible when it's umounted Li Zefan
[not found] ` <538D4982.10905-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-06-03 13:01 ` Tejun Heo
2014-06-03 13:01 ` Tejun Heo
[not found] ` <20140603130144.GB26210-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-06-04 8:59 ` Li Zefan
2014-06-04 8:59 ` Li Zefan
[not found] ` <538EE00F.10406-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-06-05 1:20 ` Tejun Heo
2014-06-05 1:20 ` Tejun Heo
2014-06-05 1:49 ` Li Zefan
[not found] ` <538D4956.5050205-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-06-03 4:05 ` [PATCH 3/3] cgroup: set visible flag only after we've mounted the default root Li Zefan
2014-06-03 4:05 ` Li Zefan
[not found] ` <538D49A7.2010403-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-06-03 13:02 ` Tejun Heo
2014-06-03 13:02 ` Tejun Heo
2014-06-03 12:57 ` [PATCH 1/3] cgroup: don't destroy " Tejun Heo
2014-06-03 12:57 ` Tejun Heo
[not found] ` <20140603125728.GA26210-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-06-04 8:40 ` Li Zefan [this message]
2014-06-04 8:40 ` Li Zefan
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=538EDB7C.2070405@huawei.com \
--to=lizefan-hv44wf8li93qt0dzr+alfa@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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.