<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="caret-color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.666666984558105px; background-color: rgb(255, 255, 255); display: inline !important">>Will
the function work correctly in case jf we completely remove above "if"? </span><span style="caret-color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.666666984558105px; background-color: rgb(255, 255, 255); display: inline !important">Is
this "if" optimization for init_css_set?</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="caret-color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.666666984558105px; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
This is indeed an optimization. And also it looks like it's the most common case.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Kirill Tkhai <ktkhai@virtuozzo.com><br>
<b>Sent:</b> Friday, April 17, 2020 12:15 PM<br>
<b>To:</b> Valeriy Vdovin <Valeriy.Vdovin@virtuozzo.com>; devel@openvz.org <devel@openvz.org>; Konstantin Khorenko <khorenko@virtuozzo.com>; Pavel Tikhomirov <ptikhomirov@virtuozzo.com><br>
<b>Subject:</b> Re: [PATCH v10 6/9] ve/cgroup: unmark ve-root cgroups at container stop</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On 16.04.2020 19:14, Valeriy Vdovin wrote:<br>
> Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com><br>
> Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com><br>
> ---<br>
> include/linux/cgroup.h | 1 +<br>
> kernel/cgroup.c | 42 ++++++++++++++++++++++++++++++++++++++++++<br>
> kernel/ve/ve.c | 2 ++<br>
> 3 files changed, 45 insertions(+)<br>
> <br>
> diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h<br>
> index 0a42f93..1bd0fe7 100644<br>
> --- a/include/linux/cgroup.h<br>
> +++ b/include/linux/cgroup.h<br>
> @@ -636,6 +636,7 @@ int cgroup_task_count(const struct cgroup *cgrp);<br>
> <br>
> #ifdef CONFIG_VE<br>
> void cgroup_mark_ve_roots(struct ve_struct *ve);<br>
> +void cgroup_unmark_ve_roots(struct ve_struct *ve);<br>
> #endif<br>
> <br>
> /*<br>
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c<br>
> index 60a4ca4..1dd36ed 100644<br>
> --- a/kernel/cgroup.c<br>
> +++ b/kernel/cgroup.c<br>
> @@ -635,6 +635,35 @@ static struct css_set *find_css_set(<br>
> }<br>
> <br>
> /*<br>
> + * Walk each cgroup link of a given css_set and find a cgroup that<br>
> + * is the child of cgroupfs_root in argument.<br>
> + */<br>
> +static struct cgroup *css_cgroup_from_root(struct css_set *css_set,<br>
> + struct cgroupfs_root *root)<br>
> +{<br>
> + struct cgroup *res = NULL;<br>
> +<br>
> + BUG_ON(!mutex_is_locked(&cgroup_mutex));<br>
> + read_lock(&css_set_lock);<br>
> +<br>
> + if (css_set == &init_css_set) {<br>
> + res = &root->top_cgroup;<br>
<br>
Will the function work correctly in case jf we completely remove above "if"?<br>
Is this "if" optimization for init_css_set?<br>
<br>
> + } else {<br>
> + struct cg_cgroup_link *link;<br>
> + list_for_each_entry(link, &css_set->cg_links, cg_link_list) {<br>
> + struct cgroup *c = link->cgrp;<br>
> + if (c->root == root) {<br>
> + res = c;<br>
> + break;<br>
> + }<br>
> + }<br>
> + }<br>
> + read_unlock(&css_set_lock);<br>
> + BUG_ON(!res);<br>
> + return res;<br>
> +}<br>
> +<br>
> +/*<br>
> * Return the cgroup for "task" from the given hierarchy. Must be<br>
> * called with cgroup_mutex held.<br>
> */<br>
> @@ -4237,6 +4266,19 @@ void cgroup_mark_ve_roots(struct ve_struct *ve)<br>
> mutex_unlock(&cgroup_mutex);<br>
> }<br>
> <br>
> +void cgroup_unmark_ve_roots(struct ve_struct *ve)<br>
> +{<br>
> + struct cgroup *cgrp;<br>
> + struct cgroupfs_root *root;<br>
> +<br>
> + mutex_lock(&cgroup_mutex);<br>
> + for_each_active_root(root) {<br>
> + cgrp = css_cgroup_from_root(ve->root_css_set, root);<br>
> + clear_bit(CGRP_VE_ROOT, &cgrp->flags);<br>
> + }<br>
> + mutex_unlock(&cgroup_mutex);<br>
> +}<br>
> +<br>
> struct cgroup *cgroup_get_ve_root(struct cgroup *cgrp)<br>
> {<br>
> struct cgroup *ve_root = NULL;<br>
> diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c<br>
> index eedb85d..db3b600 100644<br>
> --- a/kernel/ve/ve.c<br>
> +++ b/kernel/ve/ve.c<br>
> @@ -618,6 +618,8 @@ void ve_exit_ns(struct pid_namespace *pid_ns)<br>
> if (!ve->ve_ns || ve->ve_ns->pid_ns != pid_ns)<br>
> return;<br>
> <br>
> + cgroup_unmark_ve_roots(ve);<br>
> +<br>
> ve_workqueue_stop(ve);<br>
> <br>
> /*<br>
> <br>
<br>
</div>
</span></font></div>
</body>
</html>