From: Kamezawa Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
john.r.fastabend-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
srivatsa.bhat-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/8] cgroup: add cgroup->id
Date: Tue, 20 Nov 2012 13:34:54 +0900 [thread overview]
Message-ID: <50AB086E.70901@jp.fujitsu.com> (raw)
In-Reply-To: <1353093624-22608-2-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
(2012/11/17 4:20), Tejun Heo wrote:
> With the introduction of generic cgroup hierarchy iterators, css_id is
> being phased out. It was unnecessarily complex, id'ing the wrong
> thing (cgroups need IDs, not CSSes) and has other oddities like not
> being available at ->css_alloc().
>
> This patch adds cgroup->id, which is a simple per-hierarchy
> ida-allocated ID which is assigned before ->css_alloc() and released
> after ->css_free().
>
> Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
I'm sorry if I misunderstand ... current usage of css-id in memory/swap cgroup
is for recording information of memory cgroup which may be destroyed. In some case,
a memcg's cgroup is freed but a struct memcgroup and its css are available, swap_cgroup
may contain id ot if.
This patch puts cgroup's id at diput(), so, the id used in swap_cgroup can be
reused while it's in use. Right ?
Thanks,
-Kame
> ---
> include/linux/cgroup.h | 2 ++
> kernel/cgroup.c | 15 ++++++++++++++-
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
> index d5fc8a7..b512469 100644
> --- a/include/linux/cgroup.h
> +++ b/include/linux/cgroup.h
> @@ -159,6 +159,8 @@ struct cgroup {
> */
> atomic_t count;
>
> + int id; /* ida allocated in-hierarchy ID */
> +
> /*
> * We link our 'sibling' struct into our parent's 'children'.
> * Our children link their 'sibling' into our 'children'.
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 99d5e69..0b25dcb 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -138,6 +138,9 @@ struct cgroupfs_root {
> /* Hierarchy-specific flags */
> unsigned long flags;
>
> + /* IDs for cgroups in this hierarchy */
> + struct ida cgroup_ida;
> +
> /* The path to use for release notifications. */
> char release_agent_path[PATH_MAX];
>
> @@ -890,6 +893,7 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
>
> simple_xattrs_free(&cgrp->xattrs);
>
> + ida_simple_remove(&cgrp->root->cgroup_ida, cgrp->id);
> kfree(cgrp);
> } else {
> struct cfent *cfe = __d_cfe(dentry);
> @@ -1465,6 +1469,7 @@ static struct cgroupfs_root *cgroup_root_from_opts(struct cgroup_sb_opts *opts)
>
> root->subsys_mask = opts->subsys_mask;
> root->flags = opts->flags;
> + ida_init(&root->cgroup_ida);
> if (opts->release_agent)
> strcpy(root->release_agent_path, opts->release_agent);
> if (opts->name)
> @@ -1483,6 +1488,7 @@ static void cgroup_drop_root(struct cgroupfs_root *root)
> spin_lock(&hierarchy_id_lock);
> ida_remove(&hierarchy_ida, root->hierarchy_id);
> spin_unlock(&hierarchy_id_lock);
> + ida_destroy(&root->cgroup_ida);
> kfree(root);
> }
>
> @@ -4093,10 +4099,15 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
> struct cgroup_subsys *ss;
> struct super_block *sb = root->sb;
>
> + /* allocate the cgroup and its ID, 0 is reserved for the root */
> cgrp = kzalloc(sizeof(*cgrp), GFP_KERNEL);
> if (!cgrp)
> return -ENOMEM;
>
> + cgrp->id = ida_simple_get(&root->cgroup_ida, 1, 0, GFP_KERNEL);
> + if (cgrp->id < 0)
> + goto err_free_cgrp;
> +
> /*
> * Only live parents can have children. Note that the liveliness
> * check isn't strictly necessary because cgroup_mkdir() and
> @@ -4106,7 +4117,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
> */
> if (!cgroup_lock_live_group(parent)) {
> err = -ENODEV;
> - goto err_free_cgrp;
> + goto err_free_id;
> }
>
> /* Grab a reference on the superblock so the hierarchy doesn't
> @@ -4198,6 +4209,8 @@ err_free_all:
> mutex_unlock(&cgroup_mutex);
> /* Release the reference count that we took on the superblock */
> deactivate_super(sb);
> +err_free_id:
> + ida_simple_remove(&root->cgroup_ida, cgrp->id);
> err_free_cgrp:
> kfree(cgrp);
> return err;
>
next prev parent reply other threads:[~2012-11-20 4:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-16 19:20 [PATCHSET cgroup/for-3.8] netprio_cgroup: implement hierarchy support Tejun Heo
[not found] ` <1353093624-22608-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-11-16 19:20 ` [PATCH 1/8] cgroup: add cgroup->id Tejun Heo
[not found] ` <1353093624-22608-2-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-11-19 9:03 ` Li Zefan
[not found] ` <50A9F5F3.3050907-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-11-19 17:05 ` Tejun Heo
2012-11-20 4:34 ` Kamezawa Hiroyuki [this message]
[not found] ` <50AB086E.70901-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-11-20 5:31 ` Tejun Heo
[not found] ` <20121120053112.GE25790-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2012-11-20 7:05 ` Kamezawa Hiroyuki
[not found] ` <50AB2BCF.2050204-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-11-20 7:08 ` Tejun Heo
[not found] ` <20121120070851.GG25790-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2012-11-20 7:11 ` Kamezawa Hiroyuki
2012-11-20 8:20 ` Glauber Costa
2012-11-16 19:20 ` [PATCH 2/8] netprio: simplify write_priomap() Tejun Heo
2012-11-16 19:20 ` [PATCH 3/8] netprio_cgroup: shorten variable names in extend_netdev_table() Tejun Heo
2012-11-16 19:20 ` [PATCH 4/8] netprio_cgroup: reimplement priomap expansion Tejun Heo
2012-11-16 19:20 ` [PATCH 5/8] netprio_cgroup: use cgroup->id instead of cgroup_netprio_state->prioidx Tejun Heo
2012-11-16 19:20 ` [PATCH 6/8] netprio_cgroup: implement netprio[_set]_prio() helpers Tejun Heo
2012-11-16 19:20 ` [PATCH 8/8] netprio_cgroup: implement hierarchy support Tejun Heo
2012-11-19 13:25 ` [PATCHSET cgroup/for-3.8] " Neil Horman
2012-11-19 19:25 ` Daniel Wagner
[not found] ` <50AA87BD.1040106-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-11-19 19:54 ` Daniel Wagner
2012-11-16 19:20 ` [PATCH 7/8] netprio_cgroup: keep track of whether prio is set or not Tejun Heo
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=50AB086E.70901@jp.fujitsu.com \
--to=kamezawa.hiroyu-+cum20s59erqfuhtdcdx3a@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org \
--cc=john.r.fastabend-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org \
--cc=srivatsa.bhat-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).