Re: [PATCH v2 20/23] sched/cache: Add user control to adjust the parameters of cache-aware scheduling

From: Chen, Yu C

Date: Thu Jan 15 2026 - 07:14:00 EST


Hello Jianyong,

On 1/15/2026 6:03 PM, Jianyong Wu wrote:
Hello Tim, Chen Yu,


  static bool exceed_llc_capacity(struct mm_struct *mm, int cpu)
  {
+    unsigned int llc, scale;
      struct cacheinfo *ci;
      unsigned long rss;
-    unsigned int llc;
      /*
       * get_cpu_cacheinfo_level() can not be used
@@ -1252,19 +1266,54 @@ static bool exceed_llc_capacity(struct mm_struct *mm, int cpu)
      rss = get_mm_counter(mm, MM_ANONPAGES) +
          get_mm_counter(mm, MM_SHMEMPAGES);
-    return (llc <= (rss * PAGE_SIZE));
+    /*
+     * Scale the LLC size by 256*llc_aggr_tolerance
+     * and compare it to the task's RSS size.
+     *
+     * Suppose the L3 size is 32MB. If the
+     * llc_aggr_tolerance is 1:
+     * When the RSS is larger than 32MB, the process
+     * is regarded as exceeding the LLC capacity. If
+     * the llc_aggr_tolerance is 99:
+     * When the RSS is larger than 784GB, the process
+     * is regarded as exceeding the LLC capacity because:
+     * 784GB = (1 + (99 - 1) * 256) * 32MB
+     */
+    scale = get_sched_cache_scale(256);
+    if (scale == INT_MAX)
+        return false;
+
+    return ((llc * scale) <= (rss * PAGE_SIZE));
  }
Suppose the LLC is 16 MB (which is 16777216 bytes). If we set `llc_aggr_tolerance` to 99, the `scale` value will be 25089. When calculating `16777216 * 25089`, the result is 420923572224, which exceeds 2^32 and thus causes an integer overflow.


[resend might be due to smtp issue]
Good catch! Let me switch it to u64, it should be big enough for
llc size(max to about (2^64 -1)/2589 bytes)

thanks,
Chenyu