Re: [RFC PATCH] sched: Fix integer overflow issue of cpu weight delta

From: I Hsin Cheng
Date: Tue Dec 03 2024 - 01:36:21 EST


On Mon, Dec 02, 2024 at 11:41:03AM +0100, Peter Zijlstra wrote:
> On Mon, Dec 02, 2024 at 06:13:44PM +0800, I Hsin Cheng wrote:
>
> > I think there's one point to concern, do we have a fixed range of
> > "tg_weight()" ?
>
> kernel/sched/fair.c:__sched_group_set_shares()
>
> shares = clamp(shares, scale_load(MIN_SHARES), scale_load(MAX_SHARES));
>
> if (tg->shares == shares)
> return 0;
>
> tg->shares = shares;


Thanks for clarify this ! So tg->shares should be clamped between (1 <<
1) and (1 << 18), No overflow issue should happen as long as we're sure
the value of "shares" won't exceed the range.

Then why don't we make the type of "tg->shares" to "int" or "unsigned"?
so the size of this member can be shrink. Is there any specific reason
to make "tg->shares" as "unsigned long" ? at the same time I want to ask
does "tg->shares" basically means the same as the task group's weight?

I didn't see any explanation about it in the documentation, or I
might've missed it.

Best regards,
Richard Cheng.