* [PATCH 1/2] cgroup: make serial_nr_cursor available throughout cgroup.c
@ 2013-06-18 10:48 Li Zefan
[not found] ` <51C03AF2.7050702-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Li Zefan @ 2013-06-18 10:48 UTC (permalink / raw)
To: Tejun Heo, LKML, cgroups
The next patch will use it to determine if a cgroup is newly created
while we're iterating the cgroup hierarchy.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
These two patches are based on the fixes I just sent.
---
kernel/cgroup.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index e8a40e3..b1d98f2 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -198,6 +198,15 @@ static DEFINE_IDR(cgroup_hierarchy_idr);
static struct cgroup_name root_cgroup_name = { .name = "/" };
+/*
+ * Assign a monotonically increasing serial number. It guarantees
+ * cgroups with bigger numbers are newer than those with smaller
+ * numbers. Also with the list appending, it guarantees that sibling
+ * cgroups are always sorted in the ascending serial number order on
+ * the parent's ->children.
+ */
+static atomic64_t cgroup_serial_nr_cursor = ATOMIC64_INIT(0);
+
/* This flag indicates whether tasks in the fork and exit paths should
* check for fork/exit handlers to call. This avoids us having to do
* extra work in the fork/exit path if none of the subsystems need to
@@ -4212,7 +4221,6 @@ static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp)
static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
umode_t mode)
{
- static atomic64_t serial_nr_cursor = ATOMIC64_INIT(0);
struct cgroup *cgrp;
struct cgroup_name *name;
struct cgroupfs_root *root = parent->root;
@@ -4305,7 +4313,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
* sorted in the ascending serial number order on the parent's
* ->children.
*/
- cgrp->serial_nr = atomic64_inc_return(&serial_nr_cursor);
+ cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor);
/* allocation complete, commit to creation */
list_add_tail(&cgrp->allcg_node, &root->allcg_list);
--
1.8.0.2
^ permalink raw reply related [flat|nested] 6+ messages in thread[parent not found: <51C03AF2.7050702-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* [PATCH 2/2] cgroup: convert cgroup_cft_commit() to use cgroup_for_each_descendant_pre() [not found] ` <51C03AF2.7050702-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> @ 2013-06-18 10:48 ` Li Zefan [not found] ` <51C03B05.4080504-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-06-18 10:53 ` [PATCH 1/2][UPDATED] cgroup: make serial_nr_cursor available throughout cgroup.c Li Zefan 1 sibling, 1 reply; 6+ messages in thread From: Li Zefan @ 2013-06-18 10:48 UTC (permalink / raw) To: Tejun Heo; +Cc: LKML, cgroups We used root->allcg_list to iterate cgroup hierarchy because at that time cgroup_for_each_descendant_pre() hasn't been invented. Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> --- include/linux/cgroup.h | 6 ----- kernel/cgroup.c | 62 +++++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 835918c..f70b116 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -206,9 +206,6 @@ struct cgroup { */ struct list_head cset_links; - struct list_head allcg_node; /* cgroupfs_root->allcg_list */ - struct list_head cft_q_node; /* used during cftype add/rm */ - /* * Linked list running through all cgroups that can * potentially be reaped by the release agent. Protected by @@ -317,9 +314,6 @@ struct cgroupfs_root { /* A list running through the active hierarchies */ struct list_head root_list; - /* All cgroups on this root, cgroup_mutex protected */ - struct list_head allcg_list; - /* Hierarchy-specific flags */ unsigned long flags; diff --git a/kernel/cgroup.c b/kernel/cgroup.c index b1d98f2..bc46c28 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -1399,7 +1399,6 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) INIT_LIST_HEAD(&cgrp->children); INIT_LIST_HEAD(&cgrp->files); INIT_LIST_HEAD(&cgrp->cset_links); - INIT_LIST_HEAD(&cgrp->allcg_node); INIT_LIST_HEAD(&cgrp->release_list); INIT_LIST_HEAD(&cgrp->pidlists); mutex_init(&cgrp->pidlist_mutex); @@ -1414,12 +1413,10 @@ static void init_cgroup_root(struct cgroupfs_root *root) INIT_LIST_HEAD(&root->subsys_list); INIT_LIST_HEAD(&root->root_list); - INIT_LIST_HEAD(&root->allcg_list); root->number_of_cgroups = 1; cgrp->root = root; cgrp->name = &root_cgroup_name; init_cgroup_housekeeping(cgrp); - list_add_tail(&cgrp->allcg_node, &root->allcg_list); } static int cgroup_init_root_id(struct cgroupfs_root *root) @@ -2775,65 +2772,74 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys, return ret; } -static DEFINE_MUTEX(cgroup_cft_mutex); - static void cgroup_cfts_prepare(void) - __acquires(&cgroup_cft_mutex) __acquires(&cgroup_mutex) + __acquires(&cgroup_mutex) { /* * Thanks to the entanglement with vfs inode locking, we can't walk * the existing cgroups under cgroup_mutex and create files. - * Instead, we increment reference on all cgroups and build list of - * them using @cgrp->cft_q_node. Grab cgroup_cft_mutex to ensure - * exclusive access to the field. + * Instead, we use cgroup_for_each_descendant_pre() and drop RCU + * read lock before calling cgroup_addrm_files(). */ - mutex_lock(&cgroup_cft_mutex); mutex_lock(&cgroup_mutex); } static void cgroup_cfts_commit(struct cgroup_subsys *ss, struct cftype *cfts, bool is_add) - __releases(&cgroup_mutex) __releases(&cgroup_cft_mutex) + __releases(&cgroup_mutex) { LIST_HEAD(pending); - struct cgroup *cgrp, *n; + struct cgroup *cgrp, *root = &ss->root->top_cgroup; struct super_block *sb = ss->root->sb; + struct inode *inode; + struct dentry *prev = NULL; + u64 serial_nr = atomic64_read(&cgroup_serial_nr_cursor); /* %NULL @cfts indicates abort and don't bother if @ss isn't attached */ - if (cfts && ss->root != &rootnode && - atomic_inc_not_zero(&sb->s_active)) { - list_for_each_entry(cgrp, &ss->root->allcg_list, allcg_node) { - dget(cgrp->dentry); - list_add_tail(&cgrp->cft_q_node, &pending); - } - } else { - sb = NULL; + if (!cfts || ss->root == &rootnode || + !atomic_inc_not_zero(&sb->s_active)) { + mutex_unlock(&cgroup_mutex); + return; } + mutex_unlock(&cgroup_mutex); + inode = root->dentry->d_inode; + mutex_lock(&inode->i_mutex); + mutex_lock(&cgroup_mutex); + cgroup_addrm_files(root, ss, cfts, is_add); mutex_unlock(&cgroup_mutex); + mutex_unlock(&inode->i_mutex); /* * All new cgroups will see @cfts update on @ss->cftsets. Add/rm * files for all cgroups which were created before. */ - list_for_each_entry_safe(cgrp, n, &pending, cft_q_node) { - struct inode *inode = cgrp->dentry->d_inode; + rcu_read_lock(); + cgroup_for_each_descendant_pre(cgrp, root) { + if (cgroup_is_dead(cgrp)) + continue; + + inode = cgrp->dentry->d_inode; + dget(cgrp->dentry); + rcu_read_unlock(); + + dput(prev); + prev = cgrp->dentry; mutex_lock(&inode->i_mutex); mutex_lock(&cgroup_mutex); - if (!cgroup_is_dead(cgrp)) + if (cgrp->serial_nr <= serial_nr && !cgroup_is_dead(cgrp)) cgroup_addrm_files(cgrp, ss, cfts, is_add); mutex_unlock(&cgroup_mutex); mutex_unlock(&inode->i_mutex); - list_del_init(&cgrp->cft_q_node); - dput(cgrp->dentry); + rcu_read_lock(); } + rcu_read_unlock(); + dput(prev); if (sb) deactivate_super(sb); - - mutex_unlock(&cgroup_cft_mutex); } /** @@ -4316,7 +4322,6 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor); /* allocation complete, commit to creation */ - list_add_tail(&cgrp->allcg_node, &root->allcg_list); list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children); root->number_of_cgroups++; @@ -4555,7 +4560,6 @@ static void cgroup_offline_fn(struct work_struct *work) /* delete this cgroup from parent->children */ list_del_rcu(&cgrp->sibling); - list_del_init(&cgrp->allcg_node); dput(d); -- 1.8.0.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
[parent not found: <51C03B05.4080504-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* [PATCH 2/2] cgroup: convert cgroup_cft_commit() to use cgroup_for_each_descendant_pre() [not found] ` <51C03B05.4080504-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> @ 2013-06-18 18:16 ` Tejun Heo 2013-06-18 18:18 ` [PATCH 3/3] cgroup: clean up cgroup_serial_nr_cursor Tejun Heo 1 sibling, 0 replies; 6+ messages in thread From: Tejun Heo @ 2013-06-18 18:16 UTC (permalink / raw) To: Li Zefan; +Cc: LKML, cgroups From e8c82d20a9f729cf4b9f73043f7fd4e0872bebfd Mon Sep 17 00:00:00 2001 From: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> Date: Tue, 18 Jun 2013 18:48:37 +0800 We used root->allcg_list to iterate cgroup hierarchy because at that time cgroup_for_each_descendant_pre() hasn't been invented. tj: In cgroup_cfts_commit(), s/@serial_nr/@update_upto/, move the assignment right above releasing cgroup_mutex and explain what's going on there. Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- Applied to cgroup/for-3.11 with some minor updates. Thanks. include/linux/cgroup.h | 6 ---- kernel/cgroup.c | 80 +++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index f975227..b283658 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -206,9 +206,6 @@ struct cgroup { */ struct list_head cset_links; - struct list_head allcg_node; /* cgroupfs_root->allcg_list */ - struct list_head cft_q_node; /* used during cftype add/rm */ - /* * Linked list running through all cgroups that can * potentially be reaped by the release agent. Protected by @@ -313,9 +310,6 @@ struct cgroupfs_root { /* A list running through the active hierarchies */ struct list_head root_list; - /* All cgroups on this root, cgroup_mutex protected */ - struct list_head allcg_list; - /* Hierarchy-specific flags */ unsigned long flags; diff --git a/kernel/cgroup.c b/kernel/cgroup.c index e6571ca..0ed7d8d 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -1399,7 +1399,6 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp) INIT_LIST_HEAD(&cgrp->children); INIT_LIST_HEAD(&cgrp->files); INIT_LIST_HEAD(&cgrp->cset_links); - INIT_LIST_HEAD(&cgrp->allcg_node); INIT_LIST_HEAD(&cgrp->release_list); INIT_LIST_HEAD(&cgrp->pidlists); mutex_init(&cgrp->pidlist_mutex); @@ -1414,12 +1413,10 @@ static void init_cgroup_root(struct cgroupfs_root *root) INIT_LIST_HEAD(&root->subsys_list); INIT_LIST_HEAD(&root->root_list); - INIT_LIST_HEAD(&root->allcg_list); root->number_of_cgroups = 1; cgrp->root = root; cgrp->name = &root_cgroup_name; init_cgroup_housekeeping(cgrp); - list_add_tail(&cgrp->allcg_node, &root->allcg_list); } static int cgroup_init_root_id(struct cgroupfs_root *root) @@ -2785,65 +2782,78 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cgroup_subsys *subsys, return ret; } -static DEFINE_MUTEX(cgroup_cft_mutex); - static void cgroup_cfts_prepare(void) - __acquires(&cgroup_cft_mutex) __acquires(&cgroup_mutex) + __acquires(&cgroup_mutex) { /* * Thanks to the entanglement with vfs inode locking, we can't walk * the existing cgroups under cgroup_mutex and create files. - * Instead, we increment reference on all cgroups and build list of - * them using @cgrp->cft_q_node. Grab cgroup_cft_mutex to ensure - * exclusive access to the field. + * Instead, we use cgroup_for_each_descendant_pre() and drop RCU + * read lock before calling cgroup_addrm_files(). */ - mutex_lock(&cgroup_cft_mutex); mutex_lock(&cgroup_mutex); } static void cgroup_cfts_commit(struct cgroup_subsys *ss, struct cftype *cfts, bool is_add) - __releases(&cgroup_mutex) __releases(&cgroup_cft_mutex) + __releases(&cgroup_mutex) { LIST_HEAD(pending); - struct cgroup *cgrp, *n; + struct cgroup *cgrp, *root = &ss->root->top_cgroup; struct super_block *sb = ss->root->sb; + struct dentry *prev = NULL; + struct inode *inode; + u64 update_upto; /* %NULL @cfts indicates abort and don't bother if @ss isn't attached */ - if (cfts && ss->root != &rootnode && - atomic_inc_not_zero(sb->s_active)) { - list_for_each_entry(cgrp, &ss->root->allcg_list, allcg_node) { - dget(cgrp->dentry); - list_add_tail(&cgrp->cft_q_node, &pending); - } - } else { - sb = NULL; + if (!cfts || ss->root == &rootnode || + !atomic_inc_not_zero(&sb->s_active)) { + mutex_unlock(&cgroup_mutex); + return; } - mutex_unlock(&cgroup_mutex); - /* - * All new cgroups will see @cfts update on @ss->cftsets. Add/rm - * files for all cgroups which were created before. + * All cgroups which are created after we drop cgroup_mutex will + * have the updated set of files, so we only need to update the + * cgroups created before the current @cgroup_serial_nr_cursor. */ - list_for_each_entry_safe(cgrp, n, &pending, cft_q_node) { - struct inode *inode = cgrp->dentry->d_inode; + update_upto = atomic64_read(&cgroup_serial_nr_cursor); + + mutex_unlock(&cgroup_mutex); + + /* @root always needs to be updated */ + inode = root->dentry->d_inode; + mutex_lock(&inode->i_mutex); + mutex_lock(&cgroup_mutex); + cgroup_addrm_files(root, ss, cfts, is_add); + mutex_unlock(&cgroup_mutex); + mutex_unlock(&inode->i_mutex); + + /* add/rm files for all cgroups created before */ + rcu_read_lock(); + cgroup_for_each_descendant_pre(cgrp, root) { + if (cgroup_is_dead(cgrp)) + continue; + + inode = cgrp->dentry->d_inode; + dget(cgrp->dentry); + rcu_read_unlock(); + + dput(prev); + prev = cgrp->dentry; mutex_lock(&inode->i_mutex); mutex_lock(&cgroup_mutex); - if (!cgroup_is_dead(cgrp)) + if (cgrp->serial_nr <= update_upto && !cgroup_is_dead(cgrp)) cgroup_addrm_files(cgrp, ss, cfts, is_add); mutex_unlock(&cgroup_mutex); mutex_unlock(&inode->i_mutex); - list_del_init(&cgrp->cft_q_node); - dput(cgrp->dentry); + rcu_read_lock(); } - - if (sb) - deactivate_super(sb); - - mutex_unlock(&cgroup_cft_mutex); + rcu_read_unlock(); + dput(prev); + deactivate_super(sb); } /** @@ -4320,7 +4330,6 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor); /* allocation complete, commit to creation */ - list_add_tail(&cgrp->allcg_node, &root->allcg_list); list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children); root->number_of_cgroups++; @@ -4559,7 +4568,6 @@ static void cgroup_offline_fn(struct work_struct *work) /* delete this cgroup from parent->children */ list_del_rcu(&cgrp->sibling); - list_del_init(&cgrp->allcg_node); dput(d); -- 1.8.2.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] cgroup: clean up cgroup_serial_nr_cursor [not found] ` <51C03B05.4080504-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-06-18 18:16 ` Tejun Heo @ 2013-06-18 18:18 ` Tejun Heo 1 sibling, 0 replies; 6+ messages in thread From: Tejun Heo @ 2013-06-18 18:18 UTC (permalink / raw) To: Li Zefan; +Cc: LKML, cgroups From 00356bd5f0f5e04183fb15805eb29e97c2fc20ac Mon Sep 17 00:00:00 2001 From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Date: Tue, 18 Jun 2013 11:14:22 -0700 cgroup_serial_nr_cursor was created atomic64_t because I thought it was never gonna used for anything other than assigning unique numbers to cgroups and didn't want to worry about synchronization; however, now we're using it as an event-stamp to distinguish cgroups created before and after certain point which assumes that it's protected by cgroup_mutex. Let's make it clear by making it a u64. Also, rename it to cgroup_serial_nr_next and make it point to the next nr to allocate so that where it's pointing to is clear and more conventional. Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Cc: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> --- Applied to cgroup/for-3.11 as a follow-up. Thanks. kernel/cgroup.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 0ed7d8d..65f333e 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -203,9 +203,10 @@ static struct cgroup_name root_cgroup_name = { .name = "/" }; * guarantees cgroups with bigger numbers are newer than those with smaller * numbers. Also, as cgroups are always appended to the parent's * ->children list, it guarantees that sibling cgroups are always sorted in - * the ascending serial number order on the list. + * the ascending serial number order on the list. Protected by + * cgroup_mutex. */ -static atomic64_t cgroup_serial_nr_cursor = ATOMIC64_INIT(0); +static u64 cgroup_serial_nr_next = 1; /* This flag indicates whether tasks in the fork and exit paths should * check for fork/exit handlers to call. This avoids us having to do @@ -2803,7 +2804,7 @@ static void cgroup_cfts_commit(struct cgroup_subsys *ss, struct super_block *sb = ss->root->sb; struct dentry *prev = NULL; struct inode *inode; - u64 update_upto; + u64 update_before; /* %NULL @cfts indicates abort and don't bother if @ss isn't attached */ if (!cfts || ss->root == &rootnode || @@ -2815,9 +2816,9 @@ static void cgroup_cfts_commit(struct cgroup_subsys *ss, /* * All cgroups which are created after we drop cgroup_mutex will * have the updated set of files, so we only need to update the - * cgroups created before the current @cgroup_serial_nr_cursor. + * cgroups created before the current @cgroup_serial_nr_next. */ - update_upto = atomic64_read(&cgroup_serial_nr_cursor); + update_before = cgroup_serial_nr_next; mutex_unlock(&cgroup_mutex); @@ -2844,7 +2845,7 @@ static void cgroup_cfts_commit(struct cgroup_subsys *ss, mutex_lock(&inode->i_mutex); mutex_lock(&cgroup_mutex); - if (cgrp->serial_nr <= update_upto && !cgroup_is_dead(cgrp)) + if (cgrp->serial_nr < update_before && !cgroup_is_dead(cgrp)) cgroup_addrm_files(cgrp, ss, cfts, is_add); mutex_unlock(&cgroup_mutex); mutex_unlock(&inode->i_mutex); @@ -4327,7 +4328,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, goto err_free_all; lockdep_assert_held(&dentry->d_inode->i_mutex); - cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor); + cgrp->serial_nr = cgroup_serial_nr_next++; /* allocation complete, commit to creation */ list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children); -- 1.8.2.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/2][UPDATED] cgroup: make serial_nr_cursor available throughout cgroup.c [not found] ` <51C03AF2.7050702-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 2013-06-18 10:48 ` [PATCH 2/2] cgroup: convert cgroup_cft_commit() to use cgroup_for_each_descendant_pre() Li Zefan @ 2013-06-18 10:53 ` Li Zefan [not found] ` <51C03C41.2040704-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> 1 sibling, 1 reply; 6+ messages in thread From: Li Zefan @ 2013-06-18 10:53 UTC (permalink / raw) To: Tejun Heo; +Cc: LKML, cgroups The next patch will use it to determine if a cgroup is newly created while we're iterating the cgroup hierarchy. Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> --- forgot to remove the old comment in cgroup_create(). --- kernel/cgroup.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index e8a40e3..60383e8 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -198,6 +198,15 @@ static DEFINE_IDR(cgroup_hierarchy_idr); static struct cgroup_name root_cgroup_name = { .name = "/" }; +/* + * Assign a monotonically increasing serial number. It guarantees + * cgroups with bigger numbers are newer than those with smaller + * numbers. Also with the list appending, it guarantees that sibling + * cgroups are always sorted in the ascending serial number order on + * the parent's ->children. + */ +static atomic64_t cgroup_serial_nr_cursor = ATOMIC64_INIT(0); + /* This flag indicates whether tasks in the fork and exit paths should * check for fork/exit handlers to call. This avoids us having to do * extra work in the fork/exit path if none of the subsystems need to @@ -4212,7 +4221,6 @@ static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp) static long cgroup_create(struct cgroup *parent, struct dentry *dentry, umode_t mode) { - static atomic64_t serial_nr_cursor = ATOMIC64_INIT(0); struct cgroup *cgrp; struct cgroup_name *name; struct cgroupfs_root *root = parent->root; @@ -4299,13 +4307,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, goto err_free_all; lockdep_assert_held(&dentry->d_inode->i_mutex); - /* - * Assign a monotonically increasing serial number. With the list - * appending below, it guarantees that sibling cgroups are always - * sorted in the ascending serial number order on the parent's - * ->children. - */ - cgrp->serial_nr = atomic64_inc_return(&serial_nr_cursor); + cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor); /* allocation complete, commit to creation */ list_add_tail(&cgrp->allcg_node, &root->allcg_list); -- 1.8.0.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
[parent not found: <51C03C41.2040704-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH 1/2][UPDATED] cgroup: make serial_nr_cursor available throughout cgroup.c [not found] ` <51C03C41.2040704-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> @ 2013-06-18 18:16 ` Tejun Heo 0 siblings, 0 replies; 6+ messages in thread From: Tejun Heo @ 2013-06-18 18:16 UTC (permalink / raw) To: Li Zefan; +Cc: LKML, cgroups From 794611a1dfcb055d7d41ce133378dd8197d73e38 Mon Sep 17 00:00:00 2001 From: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> Date: Tue, 18 Jun 2013 18:53:53 +0800 The next patch will use it to determine if a cgroup is newly created while we're iterating the cgroup hierarchy. tj: Rephrased the comment on top of cgroup_serial_nr_cursor. Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- Applied to cgroup/for-3.11 with minor update. Thanks. kernel/cgroup.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 1d4f471..e6571ca 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -198,6 +198,15 @@ static DEFINE_IDR(cgroup_hierarchy_idr); static struct cgroup_name root_cgroup_name = { .name = "/" }; +/* + * Assign a monotonically increasing serial number to cgroups. It + * guarantees cgroups with bigger numbers are newer than those with smaller + * numbers. Also, as cgroups are always appended to the parent's + * ->children list, it guarantees that sibling cgroups are always sorted in + * the ascending serial number order on the list. + */ +static atomic64_t cgroup_serial_nr_cursor = ATOMIC64_INIT(0); + /* This flag indicates whether tasks in the fork and exit paths should * check for fork/exit handlers to call. This avoids us having to do * extra work in the fork/exit path if none of the subsystems need to @@ -4222,7 +4231,6 @@ static void offline_css(struct cgroup_subsys *ss, struct cgroup *cgrp) static long cgroup_create(struct cgroup *parent, struct dentry *dentry, umode_t mode) { - static atomic64_t serial_nr_cursor = ATOMIC64_INIT(0); struct cgroup *cgrp; struct cgroup_name *name; struct cgroupfs_root *root = parent->root; @@ -4309,13 +4317,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, goto err_free_all; lockdep_assert_held(&dentry->d_inode->i_mutex); - /* - * Assign a monotonically increasing serial number. With the list - * appending below, it guarantees that sibling cgroups are always - * sorted in the ascending serial number order on the parent's - * ->children. - */ - cgrp->serial_nr = atomic64_inc_return(&serial_nr_cursor); + cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor); /* allocation complete, commit to creation */ list_add_tail(&cgrp->allcg_node, &root->allcg_list); -- 1.8.2.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-06-18 18:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-18 10:48 [PATCH 1/2] cgroup: make serial_nr_cursor available throughout cgroup.c Li Zefan
[not found] ` <51C03AF2.7050702-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-18 10:48 ` [PATCH 2/2] cgroup: convert cgroup_cft_commit() to use cgroup_for_each_descendant_pre() Li Zefan
[not found] ` <51C03B05.4080504-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-18 18:16 ` Tejun Heo
2013-06-18 18:18 ` [PATCH 3/3] cgroup: clean up cgroup_serial_nr_cursor Tejun Heo
2013-06-18 10:53 ` [PATCH 1/2][UPDATED] cgroup: make serial_nr_cursor available throughout cgroup.c Li Zefan
[not found] ` <51C03C41.2040704-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-06-18 18:16 ` Tejun Heo
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).