aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-06-18 14:14:22 -0400
committerTejun Heo <tj@kernel.org>2013-06-18 14:17:32 -0400
commit00356bd5f0f5e04183fb15805eb29e97c2fc20ac (patch)
tree3f69886071f6ca9062723325f319b205a68fa89e /kernel/cgroup.c
parente8c82d20a9f729cf4b9f73043f7fd4e0872bebfd (diff)
cgroup: clean up cgroup_serial_nr_cursor
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@kernel.org> Cc: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0ed7d8db6508..65f333ebb572 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -203,9 +203,10 @@ static struct cgroup_name root_cgroup_name = { .name = "/" };
203 * guarantees cgroups with bigger numbers are newer than those with smaller 203 * guarantees cgroups with bigger numbers are newer than those with smaller
204 * numbers. Also, as cgroups are always appended to the parent's 204 * numbers. Also, as cgroups are always appended to the parent's
205 * ->children list, it guarantees that sibling cgroups are always sorted in 205 * ->children list, it guarantees that sibling cgroups are always sorted in
206 * the ascending serial number order on the list. 206 * the ascending serial number order on the list. Protected by
207 * cgroup_mutex.
207 */ 208 */
208static atomic64_t cgroup_serial_nr_cursor = ATOMIC64_INIT(0); 209static u64 cgroup_serial_nr_next = 1;
209 210
210/* This flag indicates whether tasks in the fork and exit paths should 211/* This flag indicates whether tasks in the fork and exit paths should
211 * check for fork/exit handlers to call. This avoids us having to do 212 * 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,
2803 struct super_block *sb = ss->root->sb; 2804 struct super_block *sb = ss->root->sb;
2804 struct dentry *prev = NULL; 2805 struct dentry *prev = NULL;
2805 struct inode *inode; 2806 struct inode *inode;
2806 u64 update_upto; 2807 u64 update_before;
2807 2808
2808 /* %NULL @cfts indicates abort and don't bother if @ss isn't attached */ 2809 /* %NULL @cfts indicates abort and don't bother if @ss isn't attached */
2809 if (!cfts || ss->root == &rootnode || 2810 if (!cfts || ss->root == &rootnode ||
@@ -2815,9 +2816,9 @@ static void cgroup_cfts_commit(struct cgroup_subsys *ss,
2815 /* 2816 /*
2816 * All cgroups which are created after we drop cgroup_mutex will 2817 * All cgroups which are created after we drop cgroup_mutex will
2817 * have the updated set of files, so we only need to update the 2818 * have the updated set of files, so we only need to update the
2818 * cgroups created before the current @cgroup_serial_nr_cursor. 2819 * cgroups created before the current @cgroup_serial_nr_next.
2819 */ 2820 */
2820 update_upto = atomic64_read(&cgroup_serial_nr_cursor); 2821 update_before = cgroup_serial_nr_next;
2821 2822
2822 mutex_unlock(&cgroup_mutex); 2823 mutex_unlock(&cgroup_mutex);
2823 2824
@@ -2844,7 +2845,7 @@ static void cgroup_cfts_commit(struct cgroup_subsys *ss,
2844 2845
2845 mutex_lock(&inode->i_mutex); 2846 mutex_lock(&inode->i_mutex);
2846 mutex_lock(&cgroup_mutex); 2847 mutex_lock(&cgroup_mutex);
2847 if (cgrp->serial_nr <= update_upto && !cgroup_is_dead(cgrp)) 2848 if (cgrp->serial_nr < update_before && !cgroup_is_dead(cgrp))
2848 cgroup_addrm_files(cgrp, ss, cfts, is_add); 2849 cgroup_addrm_files(cgrp, ss, cfts, is_add);
2849 mutex_unlock(&cgroup_mutex); 2850 mutex_unlock(&cgroup_mutex);
2850 mutex_unlock(&inode->i_mutex); 2851 mutex_unlock(&inode->i_mutex);
@@ -4327,7 +4328,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
4327 goto err_free_all; 4328 goto err_free_all;
4328 lockdep_assert_held(&dentry->d_inode->i_mutex); 4329 lockdep_assert_held(&dentry->d_inode->i_mutex);
4329 4330
4330 cgrp->serial_nr = atomic64_inc_return(&cgroup_serial_nr_cursor); 4331 cgrp->serial_nr = cgroup_serial_nr_next++;
4331 4332
4332 /* allocation complete, commit to creation */ 4333 /* allocation complete, commit to creation */
4333 list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children); 4334 list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children);