From: Vikas Shivappa <vikas.shivappa@linux.intel.com>
To: vikas.shivappa@intel.com
Cc: vikas.shivappa@linux.intel.com, x86@kernel.org,
linux-kernel@vger.kernel.org, hpa@zytor.com, tglx@linutronix.de,
mingo@kernel.org, peterz@infradead.org, tj@kernel.org,
matt.fleming@intel.com, will.auld@intel.com,
kanaka.d.juvva@intel.com, glenn.p.williamson@intel.com,
mtosatti@redhat.com
Subject: [PATCH 1/6] cgroup: Adds cgroup_destroy_children
Date: Sun, 23 Aug 2015 15:46:37 -0700 [thread overview]
Message-ID: <1440370002-30618-2-git-send-email-vikas.shivappa@linux.intel.com> (raw)
In-Reply-To: <1440370002-30618-1-git-send-email-vikas.shivappa@linux.intel.com>
cgroup currently does not support removing a cgroup directory if it has
children.
Adds a api cgroup_destroy_children which destroys all the children in
the cgroup hierarchy starting from the bottom. After each cgroup node is
destroyed we wait till the css is offlined and freed.
Signed-off-by: Vikas Shivappa <vikas.shivappa@linux.intel.com>
---
include/linux/cgroup.h | 4 +++
kernel/cgroup.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index b9cb94c..292ed97 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -609,6 +609,7 @@ char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
int cgroup_rm_cftypes(struct cftype *cfts);
+void cgroup_destroy_children(struct cgroup_subsys_state *css);
bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
@@ -705,6 +706,9 @@ struct cgroup_subsys {
* specifies the mask of subsystems that this one depends on.
*/
unsigned int depends_on;
+
+ /* used to wait for freeing of csses */
+ wait_queue_head_t pending_css_free_waitq;
};
#define SUBSYS(_x) extern struct cgroup_subsys _x ## _cgrp_subsys;
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 469dd54..668f614 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1733,6 +1733,33 @@ out:
return ret;
}
+/*
+ * css_wait_free: Wait till css is freed.
+ * @css: The css that we need to wait for
+ *
+ * Wait for the release_css to call the ss->css_free and goto
+ * quiescent state for a while.
+ * This ensures that stage 4/last stage of css destruction is complete.
+ */
+static void css_wait_free(struct cgroup_subsys_state *css)
+{
+ struct cgroup_subsys *ss;
+ DEFINE_WAIT(wait);
+
+ lockdep_assert_held(&cgroup_mutex);
+
+ if (css && (css->flags & CSS_ONLINE)) {
+ ss = css->ss;
+ prepare_to_wait(&ss->pending_css_free_waitq, &wait,
+ TASK_UNINTERRUPTIBLE);
+ mutex_unlock(&cgroup_mutex);
+ schedule();
+ finish_wait(&ss->pending_css_free_waitq, &wait);
+ msleep(10);
+ mutex_lock(&cgroup_mutex);
+ }
+}
+
static struct dentry *cgroup_mount(struct file_system_type *fs_type,
int flags, const char *unused_dev_name,
void *data)
@@ -4387,6 +4414,7 @@ static void css_free_work_fn(struct work_struct *work)
ss->css_free(css);
cgroup_idr_remove(&ss->css_idr, id);
cgroup_put(cgrp);
+ wake_up_all(&ss->pending_css_free_waitq);
} else {
/* cgroup free path */
atomic_dec(&cgrp->root->nr_cgrps);
@@ -4870,6 +4898,62 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
return 0;
};
+/*
+ * cgroup_destroy_recursive - Destroy the cgroup hierarchy
+ *@css: The css we need to wait for to be freed
+ *
+ * Destroy the cgroup hierarchy bottom-up. After destroying
+ * each directory, and wait for css to be freed before
+ * proceeding to destroy its parent.
+ */
+static void cgroup_destroy_recursive(struct cgroup_subsys_state *css)
+{
+ struct cgroup_subsys_state *prev,*par = css,*tmp;
+
+ lockdep_assert_held(&cgroup_mutex);
+
+ if (!css_has_online_children(css))
+ cgroup_destroy_locked(css->cgroup);
+ else {
+ prev = css_next_child(NULL, par);
+ while(prev) {
+ tmp = css_next_child(prev, par);
+ cgroup_destroy_recursive(prev);
+ prev = tmp;
+ }
+
+ cgroup_destroy_locked(css->cgroup);
+ }
+ css_wait_free(css);
+}
+
+/*
+ * cgroup_destroy_children - Destroy all the children of the cgroup
+ * @css: the css which has the cgroup
+ */
+void cgroup_destroy_children(struct cgroup_subsys_state *css)
+{
+ struct cgroup_subsys_state *tmp,*prev, *par;
+
+ lockdep_assert_held(&cgroup_mutex);
+
+ par = css;
+
+ /*
+ * Since we want to give a chance for the css_release
+ * to call the rcu callback, dont hold a rcu lock here.
+ * We destroy the prev and when destroying prev,
+ * make sure the next one is accessible.
+ */
+ prev = css_next_child(NULL, par);
+
+ while(prev) {
+ tmp = css_next_child(prev, par);
+ cgroup_destroy_recursive(prev);
+ prev = tmp;
+ }
+}
+
static int cgroup_rmdir(struct kernfs_node *kn)
{
struct cgroup *cgrp;
@@ -4910,6 +4994,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
/* We don't handle early failures gracefully */
BUG_ON(IS_ERR(css));
init_and_link_css(css, ss, &cgrp_dfl_root.cgrp);
+ init_waitqueue_head(&ss->pending_css_free_waitq);
/*
* Root csses are never destroyed and we can't initialize
--
1.9.1
next prev parent reply other threads:[~2015-08-23 22:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-23 22:46 [PATCH V1 0/6] cgroup,x86/intel_rdt : *pre h/w* Intel code data prioritization support and cgroup changes Vikas Shivappa
2015-08-23 22:46 ` Vikas Shivappa [this message]
2015-08-23 22:46 ` [PATCH 2/6] cgroup: Add css_mount and css_umount Vikas Shivappa
2015-08-23 22:46 ` [PATCH 3/6] x86/intel_rdt: Intel Code Data Prioritization detection Vikas Shivappa
2015-08-23 22:46 ` [PATCH 4/6] x86/intel_rdt: Adds support to enable CDP Vikas Shivappa
2015-08-23 22:46 ` [PATCH 5/6] x86/intel_rdt: Class of service management for code data prioritization Vikas Shivappa
2015-08-23 22:46 ` [PATCH 6/6] x86/intel_rdt: Support dcache and icache mask for Code " Vikas Shivappa
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=1440370002-30618-2-git-send-email-vikas.shivappa@linux.intel.com \
--to=vikas.shivappa@linux.intel.com \
--cc=glenn.p.williamson@intel.com \
--cc=hpa@zytor.com \
--cc=kanaka.d.juvva@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matt.fleming@intel.com \
--cc=mingo@kernel.org \
--cc=mtosatti@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=vikas.shivappa@intel.com \
--cc=will.auld@intel.com \
--cc=x86@kernel.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