* [PATCH] sched: Filter root_task_group at the beginning
@ 2023-09-22 9:43 Haifeng Xu
2023-09-28 21:03 ` Ingo Molnar
0 siblings, 1 reply; 3+ messages in thread
From: Haifeng Xu @ 2023-09-22 9:43 UTC (permalink / raw)
To: peterz
Cc: mingo, vincent.guittot, juri.lelli, dietmar.eggemann, rostedt,
bsegall, mgorman, bristot, vschneid, linux-kernel, Haifeng Xu
We can't change the weight of the root cgroup. Let's handle
root_task_group before doing any real work including acquiring
the shares_mutex.
Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
---
kernel/sched/fair.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index a80a73909dc2..1ac2df87e070 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -12594,6 +12594,9 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
{
int ret;
+ if (tg == &root_task_group)
+ return -EINVAL;
+
mutex_lock(&shares_mutex);
if (tg_is_idle(tg))
ret = -EINVAL;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sched: Filter root_task_group at the beginning
2023-09-22 9:43 [PATCH] sched: Filter root_task_group at the beginning Haifeng Xu
@ 2023-09-28 21:03 ` Ingo Molnar
2023-09-29 11:56 ` Haifeng Xu
0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2023-09-28 21:03 UTC (permalink / raw)
To: Haifeng Xu
Cc: peterz, mingo, vincent.guittot, juri.lelli, dietmar.eggemann,
rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel
* Haifeng Xu <haifeng.xu@shopee.com> wrote:
> We can't change the weight of the root cgroup. Let's handle
> root_task_group before doing any real work including acquiring
> the shares_mutex.
>
> Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
> ---
> kernel/sched/fair.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index a80a73909dc2..1ac2df87e070 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -12594,6 +12594,9 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
> {
> int ret;
>
> + if (tg == &root_task_group)
> + return -EINVAL;
> +
> mutex_lock(&shares_mutex);
> if (tg_is_idle(tg))
> ret = -EINVAL;
So what's the motivation, how common is this case?
Normally this should be a -EINVAL error code path, which sane user-space
presumably never conscisously tries to call in that fashion, right?
It's not worth optimizing pathological cases, especially
since we check for the root CG inside __sched_group_set_shares()
already:
/*
* We can't change the weight of the root cgroup.
*/
if (!tg->se[0])
return -EINVAL;
Thanks,
Ingo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched: Filter root_task_group at the beginning
2023-09-28 21:03 ` Ingo Molnar
@ 2023-09-29 11:56 ` Haifeng Xu
0 siblings, 0 replies; 3+ messages in thread
From: Haifeng Xu @ 2023-09-29 11:56 UTC (permalink / raw)
To: Ingo Molnar
Cc: peterz, mingo, vincent.guittot, juri.lelli, dietmar.eggemann,
rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel
On 2023/9/29 05:03, Ingo Molnar wrote:
>
> * Haifeng Xu <haifeng.xu@shopee.com> wrote:
>
>> We can't change the weight of the root cgroup. Let's handle
>> root_task_group before doing any real work including acquiring
>> the shares_mutex.
>>
>> Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
>> ---
>> kernel/sched/fair.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index a80a73909dc2..1ac2df87e070 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -12594,6 +12594,9 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
>> {
>> int ret;
>>
>> + if (tg == &root_task_group)
>> + return -EINVAL;
>> +
>> mutex_lock(&shares_mutex);
>> if (tg_is_idle(tg))
>> ret = -EINVAL;
>
> So what's the motivation, how common is this case?
It's not common.
The users of __sched_group_set_shares() are sched_group_set_idle() and sched_group_set_shares().
So I want to follow the way in sched_group_set_idle(). If so, we can remove the redundant checks in
__sched_group_set_shares() because all users have filtered the root_task_group.
>
> Normally this should be a -EINVAL error code path, which sane user-space
> presumably never conscisously tries to call in that fashion, right?
Yes.
>
> It's not worth optimizing pathological cases, especially
> since we check for the root CG inside __sched_group_set_shares()
> already:
>
> /*
> * We can't change the weight of the root cgroup.
> */
> if (!tg->se[0])
> return -EINVAL;
>
>
> Thanks,
>
> Ingo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-29 11:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-22 9:43 [PATCH] sched: Filter root_task_group at the beginning Haifeng Xu
2023-09-28 21:03 ` Ingo Molnar
2023-09-29 11:56 ` Haifeng Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox