* [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes
@ 2022-06-16 10:38 Lin Feng
2022-06-16 13:13 ` Mukesh Ojha
2022-06-16 19:35 ` Tejun Heo
0 siblings, 2 replies; 3+ messages in thread
From: Lin Feng @ 2022-06-16 10:38 UTC (permalink / raw)
To: tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel, linf
No funtionality change, but save us some lines.
Signed-off-by: Lin Feng <linf@wangsu.com>
---
kernel/cgroup/cgroup.c | 58 ++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 31 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 1779ccddb734..a8a46eb66f21 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1376,6 +1376,31 @@ static void cgroup_destroy_root(struct cgroup_root *root)
cgroup_free_root(root);
}
+static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset,
+ struct cgroup_root *root)
+{
+ struct cgroup *res_cgroup = NULL;
+
+ if (cset == &init_css_set) {
+ res_cgroup = &root->cgrp;
+ } else if (root == &cgrp_dfl_root) {
+ res_cgroup = cset->dfl_cgrp;
+ } else {
+ struct cgrp_cset_link *link;
+
+ list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
+ struct cgroup *c = link->cgrp;
+
+ if (c->root == root) {
+ res_cgroup = c;
+ break;
+ }
+ }
+ }
+
+ return res_cgroup;
+}
+
/*
* look up cgroup associated with current task's cgroup namespace on the
* specified hierarchy
@@ -1391,22 +1416,8 @@ current_cgns_cgroup_from_root(struct cgroup_root *root)
rcu_read_lock();
cset = current->nsproxy->cgroup_ns->root_cset;
- if (cset == &init_css_set) {
- res = &root->cgrp;
- } else if (root == &cgrp_dfl_root) {
- res = cset->dfl_cgrp;
- } else {
- struct cgrp_cset_link *link;
-
- list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
- struct cgroup *c = link->cgrp;
+ res = __cset_cgroup_from_root(cset, root);
- if (c->root == root) {
- res = c;
- break;
- }
- }
- }
rcu_read_unlock();
BUG_ON(!res);
@@ -1422,22 +1433,7 @@ static struct cgroup *cset_cgroup_from_root(struct css_set *cset,
lockdep_assert_held(&cgroup_mutex);
lockdep_assert_held(&css_set_lock);
- if (cset == &init_css_set) {
- res = &root->cgrp;
- } else if (root == &cgrp_dfl_root) {
- res = cset->dfl_cgrp;
- } else {
- struct cgrp_cset_link *link;
-
- list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
- struct cgroup *c = link->cgrp;
-
- if (c->root == root) {
- res = c;
- break;
- }
- }
- }
+ res = __cset_cgroup_from_root(cset, root);
BUG_ON(!res);
return res;
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes
2022-06-16 10:38 [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes Lin Feng
@ 2022-06-16 13:13 ` Mukesh Ojha
2022-06-16 19:35 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Mukesh Ojha @ 2022-06-16 13:13 UTC (permalink / raw)
To: Lin Feng, tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel
Hi,
On 6/16/2022 4:08 PM, Lin Feng wrote:
> No funtionality change, but save us some lines.
>
> Signed-off-by: Lin Feng <linf@wangsu.com>
> ---
> kernel/cgroup/cgroup.c | 58 ++++++++++++++++++++----------------------
> 1 file changed, 27 insertions(+), 31 deletions(-)
>
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index 1779ccddb734..a8a46eb66f21 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -1376,6 +1376,31 @@ static void cgroup_destroy_root(struct cgroup_root *root)
> cgroup_free_root(root);
> }
>
> +static inline struct cgroup *__cset_cgroup_from_root(struct css_set *cset,
> + struct cgroup_root *root)
> +{
> + struct cgroup *res_cgroup = NULL;
> +
> + if (cset == &init_css_set) {
> + res_cgroup = &root->cgrp;
> + } else if (root == &cgrp_dfl_root) {
> + res_cgroup = cset->dfl_cgrp;
> + } else {
> + struct cgrp_cset_link *link;
> +
> + list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
> + struct cgroup *c = link->cgrp;
> +
> + if (c->root == root) {
> + res_cgroup = c;
> + break;
> + }
> + }
> + }
> +
> + return res_cgroup;
> +}
> +
> /*
> * look up cgroup associated with current task's cgroup namespace on the
> * specified hierarchy
> @@ -1391,22 +1416,8 @@ current_cgns_cgroup_from_root(struct cgroup_root *root)
> rcu_read_lock();
>
> cset = current->nsproxy->cgroup_ns->root_cset;
> - if (cset == &init_css_set) {
> - res = &root->cgrp;
> - } else if (root == &cgrp_dfl_root) {
> - res = cset->dfl_cgrp;
> - } else {
> - struct cgrp_cset_link *link;
> -
> - list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
> - struct cgroup *c = link->cgrp;
> + res = __cset_cgroup_from_root(cset, root);
>
> - if (c->root == root) {
> - res = c;
> - break;
> - }
> - }
> - }
> rcu_read_unlock();
>
> BUG_ON(!res);
> @@ -1422,22 +1433,7 @@ static struct cgroup *cset_cgroup_from_root(struct css_set *cset,
> lockdep_assert_held(&cgroup_mutex);
> lockdep_assert_held(&css_set_lock);
>
> - if (cset == &init_css_set) {
> - res = &root->cgrp;
> - } else if (root == &cgrp_dfl_root) {
> - res = cset->dfl_cgrp;
> - } else {
> - struct cgrp_cset_link *link;
> -
> - list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
> - struct cgroup *c = link->cgrp;
> -
> - if (c->root == root) {
> - res = c;
> - break;
> - }
> - }
> - }
> + res = __cset_cgroup_from_root(cset, root);
>
> BUG_ON(!res);
> return res;
Thanks for the patch
Liked the idea.
Acked-by: Mukesh Ojha <quic_mojha@quicinc.com>
-Mukesh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes
2022-06-16 10:38 [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes Lin Feng
2022-06-16 13:13 ` Mukesh Ojha
@ 2022-06-16 19:35 ` Tejun Heo
1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2022-06-16 19:35 UTC (permalink / raw)
To: Lin Feng; +Cc: lizefan.x, hannes, cgroups, linux-kernel
On Thu, Jun 16, 2022 at 06:38:30PM +0800, Lin Feng wrote:
> No funtionality change, but save us some lines.
>
> Signed-off-by: Lin Feng <linf@wangsu.com>
Applied to cgroup/for-5.20.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-16 19:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 10:38 [PATCH] cgroup.c: add helper __cset_cgroup_from_root to cleanup duplicated codes Lin Feng
2022-06-16 13:13 ` Mukesh Ojha
2022-06-16 19:35 ` 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).