Re: [PATCH v2 20/23] sched/cache: Add user control to adjust the parameters of cache-aware scheduling
From: Chen, Yu C
Date: Wed Jan 21 2026 - 11:19:29 EST
Hi Yangyu,
On 1/21/2026 11:21 PM, Yangyu Chen wrote:
On 4/12/2025 07:07, Tim Chen wrote:
[ ... ]
+ scale = get_sched_cache_scale(256);
Hi Tim Chen and Chen Yu,
There's an integer overflow here. Since the unit of LLC size is bytes, you have a 256-scale unit. For a typical LLC size of 32M, you calculate 32M multiplied by 256, which equals 8GB. This value exceeds the maximum integer value (2GB, INT_MAX), resulting in an integer overflow.
I think such function should be use u64. Below is my patch:
Thanks very much for the investigation, Jianyong previously also
mentioned this issue
https://lore.kernel.org/all/SI2PR04MB49317BA503E9C8A381956D6AE38CA@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
we will fix the issue accordingly.
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 205208f061bb..bcafb3c2b369 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1226,20 +1226,20 @@ static int llc_id(int cpu)
return llc;
}
-static inline int get_sched_cache_scale(int mul)
+static inline u64 get_sched_cache_scale(int mul)
{
if (!llc_aggr_tolerance)
return 0;
if (llc_aggr_tolerance == 100)
- return INT_MAX;
+ return ULLONG_MAX;
return (1 + (llc_aggr_tolerance - 1) * mul);
}
static bool exceed_llc_capacity(struct mm_struct *mm, int cpu)
{
- unsigned int llc, scale;
+ unsigned long long llc, scale;
I suppose we only need to change llc to u64, and not change
scale, because (llc * scale) would be converted to u64 anyway.
thanks,
Chenyu