From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: daniel.wagner-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org,
serge.hallyn-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org,
ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org,
nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org,
tgraf-G/eBtMaohhA@public.gmane.org
Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: [PATCH 3/3] netcls_cgroup: implement proper hierarchy support
Date: Fri, 16 Nov 2012 19:31:02 -0800 [thread overview]
Message-ID: <1353123062-23193-4-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1353123062-23193-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
netcls_cgroup implemented rather weird hierarchy behavior. A new
cgroup would inherit configuration from its parent but once created it
operates independently from its parent - updates to a parent doesn't
affect its children.
Proper hierarchy behavior can easily be implemented using cgroup
descendant iterator and the is_local flag. Writing a positive value
to "net_cls.classid" updates the cgroup's classid and propagates the
classid downwards. Writing a negative value removes the local config
and makes it inherit the parent's classid, and the inherited classid
is propagated downwards.
This makes netcls_cgroup properly hierarchical and behave the same way
as netprio_cgroup.
Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
net/sched/cls_cgroup.c | 62 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 51 insertions(+), 11 deletions(-)
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 6e3ef64..e9e24ac 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -70,6 +70,44 @@ static u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
return cgrp_cls_state(cgrp)->classid;
}
+/**
+ * propagate_classid - proapgate classid configuration downwards
+ * @root: cgroup to propagate classid down from
+ *
+ * Propagate @root's classid to descendants of @root. Each descendant of
+ * @root re-inherits from its parent in pre-order tree walk. This should
+ * be called after the classid of @root is changed to keep the descendants
+ * up-to-date.
+ *
+ * This may race with a new cgroup coming online and propagation may happen
+ * before finishing ->css_online() or while being taken offline. As a
+ * cgroup_cls_state is ready after ->css_alloc() and propagation doesn't
+ * affect the parent, this is safe.
+ *
+ * Should be called with netcls_mutex held.
+ */
+static void propagate_classid(struct cgroup *root)
+{
+ struct cgroup *pos;
+
+ lockdep_assert_held(&netcls_mutex);
+ rcu_read_lock();
+
+ cgroup_for_each_descendant_pre(pos, root) {
+ struct cgroup_cls_state *cs = cgrp_cls_state(pos);
+
+ /*
+ * Don't propagate if @pos has local configuration. We can
+ * skip @pos's subtree but don't have to. Just propagate
+ * through for simplicity.
+ */
+ if (!cs->is_local)
+ cs->classid = cgrp_cls_state(pos->parent)->classid;
+ }
+
+ rcu_read_unlock();
+}
+
static int write_classid(struct cgroup *cgrp, struct cftype *cft,
const char *buf)
{
@@ -80,8 +118,19 @@ static int write_classid(struct cgroup *cgrp, struct cftype *cft,
return -EINVAL;
mutex_lock(&netcls_mutex);
- cs->classid = clamp_val(v, 0, UINT_MAX);
- cs->is_local = v >= 0;
+
+ if (v >= 0) {
+ cs->classid = clamp_val(v, 0, UINT_MAX);
+ cs->is_local = true;
+ } else {
+ if (cgrp->parent)
+ cs->classid = cgrp_cls_state(cgrp->parent)->classid;
+ else
+ cs->classid = 0;
+ cs->is_local = false;
+ }
+ propagate_classid(cgrp);
+
mutex_unlock(&netcls_mutex);
return 0;
}
@@ -112,15 +161,6 @@ struct cgroup_subsys net_cls_subsys = {
.subsys_id = net_cls_subsys_id,
.base_cftypes = ss_files,
.module = THIS_MODULE,
-
- /*
- * While net_cls cgroup has the rudimentary hierarchy support of
- * inheriting the parent's classid on cgroup creation, it doesn't
- * properly propagates config changes in ancestors to their
- * descendents. A child should follow the parent's configuration
- * but be allowed to override it. Fix it and remove the following.
- */
- .broken_hierarchy = true,
};
struct cls_cgroup_head {
--
1.7.11.7
WARNING: multiple messages have this Message-ID (diff)
From: Tejun Heo <tj@kernel.org>
To: daniel.wagner@bmw-carit.de, serge.hallyn@canonical.com,
ebiederm@xmission.com, nhorman@tuxdriver.com, tgraf@suug.ch
Cc: davem@davemloft.net, lizefan@huawei.com, cgroups@vger.kernel.org,
containers@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 3/3] netcls_cgroup: implement proper hierarchy support
Date: Fri, 16 Nov 2012 19:31:02 -0800 [thread overview]
Message-ID: <1353123062-23193-4-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1353123062-23193-1-git-send-email-tj@kernel.org>
netcls_cgroup implemented rather weird hierarchy behavior. A new
cgroup would inherit configuration from its parent but once created it
operates independently from its parent - updates to a parent doesn't
affect its children.
Proper hierarchy behavior can easily be implemented using cgroup
descendant iterator and the is_local flag. Writing a positive value
to "net_cls.classid" updates the cgroup's classid and propagates the
classid downwards. Writing a negative value removes the local config
and makes it inherit the parent's classid, and the inherited classid
is propagated downwards.
This makes netcls_cgroup properly hierarchical and behave the same way
as netprio_cgroup.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
net/sched/cls_cgroup.c | 62 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 51 insertions(+), 11 deletions(-)
diff --git a/net/sched/cls_cgroup.c b/net/sched/cls_cgroup.c
index 6e3ef64..e9e24ac 100644
--- a/net/sched/cls_cgroup.c
+++ b/net/sched/cls_cgroup.c
@@ -70,6 +70,44 @@ static u64 read_classid(struct cgroup *cgrp, struct cftype *cft)
return cgrp_cls_state(cgrp)->classid;
}
+/**
+ * propagate_classid - proapgate classid configuration downwards
+ * @root: cgroup to propagate classid down from
+ *
+ * Propagate @root's classid to descendants of @root. Each descendant of
+ * @root re-inherits from its parent in pre-order tree walk. This should
+ * be called after the classid of @root is changed to keep the descendants
+ * up-to-date.
+ *
+ * This may race with a new cgroup coming online and propagation may happen
+ * before finishing ->css_online() or while being taken offline. As a
+ * cgroup_cls_state is ready after ->css_alloc() and propagation doesn't
+ * affect the parent, this is safe.
+ *
+ * Should be called with netcls_mutex held.
+ */
+static void propagate_classid(struct cgroup *root)
+{
+ struct cgroup *pos;
+
+ lockdep_assert_held(&netcls_mutex);
+ rcu_read_lock();
+
+ cgroup_for_each_descendant_pre(pos, root) {
+ struct cgroup_cls_state *cs = cgrp_cls_state(pos);
+
+ /*
+ * Don't propagate if @pos has local configuration. We can
+ * skip @pos's subtree but don't have to. Just propagate
+ * through for simplicity.
+ */
+ if (!cs->is_local)
+ cs->classid = cgrp_cls_state(pos->parent)->classid;
+ }
+
+ rcu_read_unlock();
+}
+
static int write_classid(struct cgroup *cgrp, struct cftype *cft,
const char *buf)
{
@@ -80,8 +118,19 @@ static int write_classid(struct cgroup *cgrp, struct cftype *cft,
return -EINVAL;
mutex_lock(&netcls_mutex);
- cs->classid = clamp_val(v, 0, UINT_MAX);
- cs->is_local = v >= 0;
+
+ if (v >= 0) {
+ cs->classid = clamp_val(v, 0, UINT_MAX);
+ cs->is_local = true;
+ } else {
+ if (cgrp->parent)
+ cs->classid = cgrp_cls_state(cgrp->parent)->classid;
+ else
+ cs->classid = 0;
+ cs->is_local = false;
+ }
+ propagate_classid(cgrp);
+
mutex_unlock(&netcls_mutex);
return 0;
}
@@ -112,15 +161,6 @@ struct cgroup_subsys net_cls_subsys = {
.subsys_id = net_cls_subsys_id,
.base_cftypes = ss_files,
.module = THIS_MODULE,
-
- /*
- * While net_cls cgroup has the rudimentary hierarchy support of
- * inheriting the parent's classid on cgroup creation, it doesn't
- * properly propagates config changes in ancestors to their
- * descendents. A child should follow the parent's configuration
- * but be allowed to override it. Fix it and remove the following.
- */
- .broken_hierarchy = true,
};
struct cls_cgroup_head {
--
1.7.11.7
next prev parent reply other threads:[~2012-11-17 3:31 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-17 3:30 [PATCHSET cgroup/for-3.8] netcls_cgroup: implement hierarchy support Tejun Heo
2012-11-17 3:30 ` Tejun Heo
[not found] ` <1353123062-23193-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-11-17 3:31 ` [PATCH 1/3] netcls_cgroup: introduce netcls_mutex Tejun Heo
2012-11-17 3:31 ` Tejun Heo
[not found] ` <1353123062-23193-2-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-11-19 14:01 ` Daniel Wagner
2012-11-19 14:01 ` Daniel Wagner
2012-11-19 14:01 ` Daniel Wagner
2012-11-17 3:31 ` [PATCH 2/3] netcls_cgroup: introduce cgroup_cls_state->is_local Tejun Heo
2012-11-17 3:31 ` Tejun Heo
2012-11-19 12:54 ` Daniel Wagner
[not found] ` <1353123062-23193-3-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-11-19 12:54 ` Daniel Wagner
2012-11-19 17:30 ` [PATCH v2 " Tejun Heo
2012-11-19 17:30 ` Tejun Heo
2012-11-19 17:30 ` Tejun Heo
[not found] ` <20121119173026.GJ15971-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2012-11-19 19:18 ` Daniel Wagner
2012-11-19 19:18 ` Daniel Wagner
2012-11-19 19:18 ` Daniel Wagner
2012-11-17 3:31 ` Tejun Heo [this message]
2012-11-17 3:31 ` [PATCH 3/3] netcls_cgroup: implement proper hierarchy support Tejun Heo
[not found] ` <1353123062-23193-4-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-11-19 13:47 ` Daniel Wagner
2012-11-19 13:47 ` Daniel Wagner
[not found] ` <50AA385A.90503-kQCPcA+X3s7YtjvyW6yDsg@public.gmane.org>
2012-11-19 17:08 ` Tejun Heo
2012-11-19 17:08 ` Tejun Heo
[not found] ` <20121119170859.GI15971-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2012-11-19 19:17 ` Daniel Wagner
2012-11-19 19:17 ` Daniel Wagner
2012-11-19 19:17 ` Daniel Wagner
2012-11-17 3:31 ` Tejun Heo
2012-11-18 3:04 ` [PATCHSET cgroup/for-3.8] netcls_cgroup: implement " David Miller
2012-11-18 3:04 ` David Miller
2012-11-18 3:04 ` David Miller
[not found] ` <20121117.220421.1904738911212014470.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-11-18 14:25 ` Tejun Heo
2012-11-18 14:25 ` Tejun Heo
2012-11-18 14:25 ` Tejun Heo
2012-11-19 13:59 ` Daniel Wagner
2012-11-19 13:59 ` Daniel Wagner
[not found] ` <50AA3B5E.3080701-98C5kh4wR6ohFhg+JK9F0w@public.gmane.org>
2012-11-19 19:01 ` Tejun Heo
2012-11-19 19:01 ` Tejun Heo
2012-11-19 15:07 ` Neil Horman
2012-11-19 15:07 ` Neil Horman
2012-11-19 19:21 ` Tejun Heo
2012-11-19 19:21 ` Tejun Heo
[not found] ` <20121119192142.GM15971-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2012-11-20 5:44 ` Tejun Heo
2012-11-20 5:44 ` Tejun Heo
2012-11-19 19:21 ` 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=1353123062-23193-4-git-send-email-tj@kernel.org \
--to=tj-dgejt+ai2ygdnm+yrofe0a@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=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org \
--cc=serge.hallyn-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org \
--cc=tgraf-G/eBtMaohhA@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.