* [PATCH] cgroup: Remove unnecessary call to strstrip()
@ 2020-09-08 13:33 Hao Lee
2020-10-01 14:46 ` Hao Lee
0 siblings, 1 reply; 7+ messages in thread
From: Hao Lee @ 2020-09-08 13:33 UTC (permalink / raw)
To: tj; +Cc: lizefan, hannes, cgroups, linux-kernel, haolee.swjtu
The string buf will be stripped in cgroup_procs_write_start() before it
is converted to int, so remove this unnecessary call to strstrip().
Signed-off-by: Hao Lee <haolee.swjtu@gmail.com>
---
kernel/cgroup/cgroup.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index b6714166106d..90ee7e73eb2e 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4772,14 +4772,12 @@ static ssize_t cgroup_threads_write(struct kernfs_open_file *of,
{
struct cgroup *src_cgrp, *dst_cgrp;
struct task_struct *task;
ssize_t ret;
bool locked;
- buf = strstrip(buf);
-
dst_cgrp = cgroup_kn_lock_live(of->kn, false);
if (!dst_cgrp)
return -ENODEV;
task = cgroup_procs_write_start(buf, false, &locked);
ret = PTR_ERR_OR_ZERO(task);
--
2.24.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] cgroup: Remove unnecessary call to strstrip()
2020-09-08 13:33 [PATCH] cgroup: Remove unnecessary call to strstrip() Hao Lee
@ 2020-10-01 14:46 ` Hao Lee
0 siblings, 0 replies; 7+ messages in thread
From: Hao Lee @ 2020-10-01 14:46 UTC (permalink / raw)
To: tj; +Cc: lizefan, hannes, cgroups, linux-kernel
Ping. Thanks.
On Tue, Sep 08, 2020 at 01:33:50PM +0000, Hao Lee wrote:
> The string buf will be stripped in cgroup_procs_write_start() before it
> is converted to int, so remove this unnecessary call to strstrip().
>
> Signed-off-by: Hao Lee <haolee.swjtu@gmail.com>
> ---
> kernel/cgroup/cgroup.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index b6714166106d..90ee7e73eb2e 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -4772,14 +4772,12 @@ static ssize_t cgroup_threads_write(struct kernfs_open_file *of,
> {
> struct cgroup *src_cgrp, *dst_cgrp;
> struct task_struct *task;
> ssize_t ret;
> bool locked;
>
> - buf = strstrip(buf);
> -
> dst_cgrp = cgroup_kn_lock_live(of->kn, false);
> if (!dst_cgrp)
> return -ENODEV;
>
> task = cgroup_procs_write_start(buf, false, &locked);
> ret = PTR_ERR_OR_ZERO(task);
> --
> 2.24.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cgroup: Remove unnecessary call to strstrip()
2021-01-14 12:44 ` Michal Koutný
2021-01-14 17:35 ` Daniel Jordan
2021-01-15 2:19 ` Hao Lee
@ 2021-01-15 20:31 ` Tejun Heo
2 siblings, 0 replies; 7+ messages in thread
From: Tejun Heo @ 2021-01-15 20:31 UTC (permalink / raw)
To: Michal Koutný; +Cc: Hao Lee, lizefan, hannes, cgroups, linux-kernel
On Thu, Jan 14, 2021 at 01:44:27PM +0100, Michal Koutný wrote:
> Hello.
>
> On Sun, Jan 03, 2021 at 02:50:01AM +0000, Hao Lee <haolee.swjtu@gmail.com> wrote:
> > The string buf will be stripped in cgroup_procs_write_start() before it
> > is converted to int, so remove this unnecessary call to strstrip().
> Good catch, Hao.
>
> Perhaps the code be then simplified a bit
>
> -- >8 --
> From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
> Date: Thu, 14 Jan 2021 13:23:39 +0100
> Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The functions cgroup_threads_start and cgroup_procs_start are almost
> identical. In order to reduce duplication, factor out the common code in
> similar fashion we already do for other threadgroup/task functions. No
> functional changes are intended.
>
> Suggested-by: Hao Lee <haolee.swjtu@gmail.com>
> Signed-off-by: Michal Koutný <mkoutny@suse.com>
Applied to cgroup/for-5.12 w/ minor description update suggested by Daniel.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cgroup: Remove unnecessary call to strstrip()
2021-01-14 12:44 ` Michal Koutný
2021-01-14 17:35 ` Daniel Jordan
@ 2021-01-15 2:19 ` Hao Lee
2021-01-15 20:31 ` Tejun Heo
2 siblings, 0 replies; 7+ messages in thread
From: Hao Lee @ 2021-01-15 2:19 UTC (permalink / raw)
To: Michal Koutný; +Cc: tj, lizefan, Johannes Weiner, cgroups, linux-kernel
> Perhaps the code be then simplified a bit
>
> -- >8 --
> From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
> Date: Thu, 14 Jan 2021 13:23:39 +0100
> Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The functions cgroup_threads_start and cgroup_procs_start are almost
> identical. In order to reduce duplication, factor out the common code in
> similar fashion we already do for other threadgroup/task functions. No
> functional changes are intended.
Nice work. I didn't realize this simplification :)
Regards,
Hao Lee
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cgroup: Remove unnecessary call to strstrip()
2021-01-14 12:44 ` Michal Koutný
@ 2021-01-14 17:35 ` Daniel Jordan
2021-01-15 2:19 ` Hao Lee
2021-01-15 20:31 ` Tejun Heo
2 siblings, 0 replies; 7+ messages in thread
From: Daniel Jordan @ 2021-01-14 17:35 UTC (permalink / raw)
To: Michal Koutný, Hao Lee; +Cc: tj, lizefan, hannes, cgroups, linux-kernel
Hello Michal,
Michal Koutný <mkoutny@suse.com> writes:
> On Sun, Jan 03, 2021 at 02:50:01AM +0000, Hao Lee <haolee.swjtu@gmail.com> wrote:
>> The string buf will be stripped in cgroup_procs_write_start() before it
>> is converted to int, so remove this unnecessary call to strstrip().
> Good catch, Hao.
>
> Perhaps the code be then simplified a bit
>
> -- >8 --
> From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
> Date: Thu, 14 Jan 2021 13:23:39 +0100
> Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The functions cgroup_threads_start and cgroup_procs_start are almost
You meant cgroup_threads_write and cgroup_procs_write.
> kernel/cgroup/cgroup.c | 55 +++++++++++-------------------------------
> 1 file changed, 14 insertions(+), 41 deletions(-)
Ok, sure, that's a good thing.
Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] cgroup: Remove unnecessary call to strstrip()
2021-01-03 2:50 Hao Lee
@ 2021-01-14 12:44 ` Michal Koutný
2021-01-14 17:35 ` Daniel Jordan
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Michal Koutný @ 2021-01-14 12:44 UTC (permalink / raw)
To: Hao Lee; +Cc: tj, lizefan, hannes, cgroups, linux-kernel
Hello.
On Sun, Jan 03, 2021 at 02:50:01AM +0000, Hao Lee <haolee.swjtu@gmail.com> wrote:
> The string buf will be stripped in cgroup_procs_write_start() before it
> is converted to int, so remove this unnecessary call to strstrip().
Good catch, Hao.
Perhaps the code be then simplified a bit
-- >8 --
From: =?UTF-8?q?Michal=20Koutn=C3=BD?= <mkoutny@suse.com>
Date: Thu, 14 Jan 2021 13:23:39 +0100
Subject: [PATCH] cgroup: cgroup.{procs,threads} factor out common parts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The functions cgroup_threads_start and cgroup_procs_start are almost
identical. In order to reduce duplication, factor out the common code in
similar fashion we already do for other threadgroup/task functions. No
functional changes are intended.
Suggested-by: Hao Lee <haolee.swjtu@gmail.com>
Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
kernel/cgroup/cgroup.c | 55 +++++++++++-------------------------------
1 file changed, 14 insertions(+), 41 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 613845769103c..f6279df507f4b 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4726,8 +4726,8 @@ static int cgroup_attach_permissions(struct cgroup *src_cgrp,
return ret;
}
-static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
- char *buf, size_t nbytes, loff_t off)
+static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
+ bool threadgroup)
{
struct cgroup *src_cgrp, *dst_cgrp;
struct task_struct *task;
@@ -4738,7 +4738,7 @@ static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
if (!dst_cgrp)
return -ENODEV;
- task = cgroup_procs_write_start(buf, true, &locked);
+ task = cgroup_procs_write_start(buf, threadgroup, &locked);
ret = PTR_ERR_OR_ZERO(task);
if (ret)
goto out_unlock;
@@ -4748,19 +4748,26 @@ static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
src_cgrp = task_cgroup_from_root(task, &cgrp_dfl_root);
spin_unlock_irq(&css_set_lock);
+ /* process and thread migrations follow same delegation rule */
ret = cgroup_attach_permissions(src_cgrp, dst_cgrp,
- of->file->f_path.dentry->d_sb, true);
+ of->file->f_path.dentry->d_sb, threadgroup);
if (ret)
goto out_finish;
- ret = cgroup_attach_task(dst_cgrp, task, true);
+ ret = cgroup_attach_task(dst_cgrp, task, threadgroup);
out_finish:
cgroup_procs_write_finish(task, locked);
out_unlock:
cgroup_kn_unlock(of->kn);
- return ret ?: nbytes;
+ return ret;
+}
+
+static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ return __cgroup_procs_write(of, buf, true) ?: nbytes;
}
static void *cgroup_threads_start(struct seq_file *s, loff_t *pos)
@@ -4771,41 +4778,7 @@ static void *cgroup_threads_start(struct seq_file *s, loff_t *pos)
static ssize_t cgroup_threads_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
- struct cgroup *src_cgrp, *dst_cgrp;
- struct task_struct *task;
- ssize_t ret;
- bool locked;
-
- buf = strstrip(buf);
-
- dst_cgrp = cgroup_kn_lock_live(of->kn, false);
- if (!dst_cgrp)
- return -ENODEV;
-
- task = cgroup_procs_write_start(buf, false, &locked);
- ret = PTR_ERR_OR_ZERO(task);
- if (ret)
- goto out_unlock;
-
- /* find the source cgroup */
- spin_lock_irq(&css_set_lock);
- src_cgrp = task_cgroup_from_root(task, &cgrp_dfl_root);
- spin_unlock_irq(&css_set_lock);
-
- /* thread migrations follow the cgroup.procs delegation rule */
- ret = cgroup_attach_permissions(src_cgrp, dst_cgrp,
- of->file->f_path.dentry->d_sb, false);
- if (ret)
- goto out_finish;
-
- ret = cgroup_attach_task(dst_cgrp, task, false);
-
-out_finish:
- cgroup_procs_write_finish(task, locked);
-out_unlock:
- cgroup_kn_unlock(of->kn);
-
- return ret ?: nbytes;
+ return __cgroup_procs_write(of, buf, false) ?: nbytes;
}
/* cgroup core interface files for the default hierarchy */
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] cgroup: Remove unnecessary call to strstrip()
@ 2021-01-03 2:50 Hao Lee
2021-01-14 12:44 ` Michal Koutný
0 siblings, 1 reply; 7+ messages in thread
From: Hao Lee @ 2021-01-03 2:50 UTC (permalink / raw)
To: tj; +Cc: lizefan, hannes, cgroups, linux-kernel, haolee.swjtu
The string buf will be stripped in cgroup_procs_write_start() before it
is converted to int, so remove this unnecessary call to strstrip().
Signed-off-by: Hao Lee <haolee.swjtu@gmail.com>
---
kernel/cgroup/cgroup.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 5e9cb81c088a..8b3554c1113a 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4774,8 +4774,6 @@ static ssize_t cgroup_threads_write(struct kernfs_open_file *of,
ssize_t ret;
bool locked;
- buf = strstrip(buf);
-
dst_cgrp = cgroup_kn_lock_live(of->kn, false);
if (!dst_cgrp)
return -ENODEV;
--
2.24.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-01-15 20:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 13:33 [PATCH] cgroup: Remove unnecessary call to strstrip() Hao Lee
2020-10-01 14:46 ` Hao Lee
2021-01-03 2:50 Hao Lee
2021-01-14 12:44 ` Michal Koutný
2021-01-14 17:35 ` Daniel Jordan
2021-01-15 2:19 ` Hao Lee
2021-01-15 20:31 ` 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).