From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7441C31771B for ; Thu, 18 Dec 2025 11:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766057844; cv=none; b=Yjv7VwzWJ3ZMUOaxYyv51AmryLN8Wk+uOqJO2iqG8kfcCAfDc9M8VBYW1dQ+OuG6lQ5EDlSYw8vAS2WDWgDCO3ruJK9gUiHIQVCtHpL8aKF/TEYcSNqBqpcUZObgxIH+SlllbMPlipebtBmT1k03V8MqO11J6Lfy7p06eijNQis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766057844; c=relaxed/simple; bh=6isxcIXtzthTyuVXjcTdgQ/+vwi/QPbe85NTbk1s2y0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=f6e82B9oEg/lybAn4p2HjL7u5NOb4GLe9PbCoLk6IH0Lz8nFaZRD/u+3rZFGC7IXl3Vgpo1GIdYUtoskMYS5e3+7OYuPDTB+dP7988L8QUaCBn9fZfbAxyyIjwDi3NCk1ifN+LxwEaDZfClMvFXwe1U/4F9Mojr6pK/gmyvVMmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bZ81AyAI; arc=none smtp.client-ip=209.85.219.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bZ81AyAI" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-88a35a00506so7713676d6.2 for ; Thu, 18 Dec 2025 03:37:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766057841; x=1766662641; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=YT52FifVVhMx0W6CwF6h/FP2XbX577FljzCwWIcvT6g=; b=bZ81AyAI81yRZ3DtorDg3ceRwld/5DrRWWEWGanvVQsDuVqQwmTfZSPqUbKiG0TU1V HdBFU16Gb6kJ5qa5u0JdRDNu9HE5DgvuHmKjnTs5+If7cdcnuNx+XUVeOsBaSU56olcW 3PpYW+P/SlntUGYDsjmCx0pz/9rxlwb0Jklbq/kyvoLSEcYOsrmd8DZ4wXvdxenasdno 4m/u0sw55WmHYQzrYaLDhrpX/wpTsSPS61g8+ecjhW+gm5PzmZDiqaqgFoIQvIRg4SVW cfri3yus37FPMbhAGEk0C8HnHiLkfLYPrFVU4a3dvQqmRFjW+Jwo85soI9jvTAOwPpEJ k/VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766057841; x=1766662641; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=YT52FifVVhMx0W6CwF6h/FP2XbX577FljzCwWIcvT6g=; b=B7GkmID4TIk0YoVWbz1leyfRrJs18cFb4LgGmFN6pgWOMezMWzVAsGoNrs3aHaMrhg GlLYapq9XRVrupJ5R2ZcpGXLYhCgQPo8qk6bdVxdYFfqwQ8OvO7eIeT/IJxIlVX6FlNl Y4I2bSiRF/tBwGWnCGP4uSYKCfz5SsjQJ9MXFWktCxFEn26hw36tUFaMKOAXXxaotB6n whZi0bi3EqmZ4hskYsmqirCbQZi6t6BlhRUl/mJQIJrW9BN4HmUA6wceBNMiIO1HDr2g jzuH1BuI1th7FHZN9Zl8G9rGZteooM2Wkn/FQfDHMLdwdJux8kppjhtG9Lda3jFHomsQ Fq4w== X-Forwarded-Encrypted: i=1; AJvYcCUs/Lt0jCf86knkinAvpTGa/WGLmgkcRby4ogg8zT2+2gHeH+7t1u6T0yqe8XBvF0bn5lC4nTbKwm1FkrA=@vger.kernel.org X-Gm-Message-State: AOJu0YzHq8MhHnCJEsGByEi0ViVjvGYDrzyrTTFBSy39kFs5YG+0UqUa 17NJjqlOJ/m8LUigQ6bVOStDDWwYePC5K95ZSjNDerToeUlTigWURZC3 X-Gm-Gg: AY/fxX5CguqzDhqlPtiBEyx9YUbfMIj8l4oDdhlC+yN5EOSgMR6ZSsqPwyBZXrFW/WP 1FFe7cdFvTedP6fkauSu2vVJCSZLTvvjGp9xP8kLe/nlxJSMwZHxbMJn+jotXXfFKnojNdsBNN+ aZcW478uQS/B7PbQhfPnl4qPQCSlkBEVbJSDUY6hgh1G7/hHmL4EGSB87yhIt7GlaXCUx09lZcU xsiib/CPy5TBeMzn+mXkVgxGrWghuO+SfGKq854rtgsDpA9u8VxKLdDesBtzcKnuMT9DGIw6yRk aJdZ/Yn4VVnVF6BaaxzFRX84C9gtHemvpz25TTTHpksQHmgjf8RR3p0xPtjRlCocMc2eZQrZy6R lxa2Vcgdh+TmHXWAU8qy+KIQuxvXiUtuNl/filRZ/x8eiAB+dqcL+rBlCSy1PvhfqIBM6Osuxs8 NmVv4lbUhkKO2Ml10lawZmw8f/CFB/glGpCHdNow== X-Google-Smtp-Source: AGHT+IF3tTWk9EwLWIAQyq6bpSmkVYKfy2dNccoHDUtoa9Nlz0tGSh7UebYqhTXcQvsGNZ2tfISWFg== X-Received: by 2002:a05:6a00:330d:b0:7aa:93d5:820f with SMTP id d2e1a72fcca58-7f66810bd78mr19789070b3a.30.1766050982710; Thu, 18 Dec 2025 01:43:02 -0800 (PST) Received: from [192.168.255.10] ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7fe1212551asm2046422b3a.22.2025.12.18.01.42.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Dec 2025 01:43:02 -0800 (PST) Message-ID: <2924fe29-e813-4dc5-8a1b-86890029e372@gmail.com> Date: Thu, 18 Dec 2025 17:42:53 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 19/23] sched/cache: Avoid cache-aware scheduling for memory-heavy processes To: "Chen, Yu C" Cc: Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , linux-kernel@vger.kernel.org, Tim Chen , Peter Zijlstra , K Prateek Nayak , Vincent Guittot , "Gautham R . Shenoy" , Ingo Molnar , Vern Hao References: <91a7c325-5093-4417-aa98-34df694b0c39@gmail.com> <61cc2b92-1b5a-4af5-9d88-96097c3b0619@intel.com> From: Vern Hao In-Reply-To: <61cc2b92-1b5a-4af5-9d88-96097c3b0619@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2025/12/18 16:32, Chen, Yu C wrote: > On 12/18/2025 11:59 AM, Vern Hao wrote: >> >> On 2025/12/4 07:07, Tim Chen wrote: >>> From: Chen Yu >>> >>> Prateek and Tingyin reported that memory-intensive workloads (such as >>> stream) can saturate memory bandwidth and caches on the preferred LLC >>> when sched_cache aggregates too many threads. >>> >>> To mitigate this, estimate a process's memory footprint by comparing >>> its RSS (anonymous and shared pages) to the size of the LLC. If RSS >>> exceeds the LLC size, skip cache-aware scheduling. >> Restricting RSS prevents many applications from benefiting from this >> optimization. I believe this restriction should be lifted. For >> memory- intensive workloads, the optimization may simply yield no >> gains, but it certainly shouldn't make performance worse. We need to >> further refine this logic. > > Memory-intensive workloads may trigger performance regressions when > memory bandwidth(from L3 cache to memory controller) is saturated due RSS size and bandwidth saturation are not necessarily linked, In my view, the optimization should be robust enough that it doesn't cause a noticeable drop in performance, no matter how large the RSS is. We need to have a more profound discussion on this. > to task aggregation on single LLC. We have seen this issue in stream > benchmark runs in previous version. > > Patch 23 introduces a debugfs knob llc_aggr_tolerance that lets userspace > tune the scale factor. This allows memory-intensive workloads to perform > task aggregation when their footprint is small and the administrator > considers > it safe. As you noted in another patch, fine-grained control would > improve > flexibility—and this can be addressed in future iterations. > >>> Note that RSS is only an approximation of the memory footprint. >>> By default, the comparison is strict, but a later patch will allow >>> users to provide a hint to adjust this threshold. >>> >>> According to the test from Adam, some systems do not have shared L3 >>> but with shared L2 as clusters. In this case, the L2 becomes the >>> LLC[1]. >>> >>> Link[1]: https://lore.kernel.org/all/3cb6ebc7-a2fd-42b3-8739- >>> b00e28a09cb6@os.amperecomputing.com/ >>> >>> Co-developed-by: Tim Chen >>> Signed-off-by: Chen Yu >>> Signed-off-by: Tim Chen >>> --- >>> >>> Notes: >>>      v1->v2: Assigned curr_cpu in task_cache_work() before checking >>>              exceed_llc_capacity(mm, curr_cpu) to avoid out-of-bound >>>              access.(lkp/0day) >>> >>>   include/linux/cacheinfo.h | 21 ++++++++++------- >>>   kernel/sched/fair.c       | 49 >>> +++++++++++++++++++++++++++++++++++---- >>>   2 files changed, 57 insertions(+), 13 deletions(-) >>> >>> diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h >>> index c8f4f0a0b874..82d0d59ca0e1 100644 >>> --- a/include/linux/cacheinfo.h >>> +++ b/include/linux/cacheinfo.h >>> @@ -113,18 +113,11 @@ int acpi_get_cache_info(unsigned int cpu, >>>   const struct attribute_group *cache_get_priv_group(struct >>> cacheinfo *this_leaf); >>> -/* >>> - * Get the cacheinfo structure for the cache associated with @cpu at >>> - * level @level. >>> - * cpuhp lock must be held. >>> - */ >>> -static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, >>> int level) >>> +static inline struct cacheinfo *_get_cpu_cacheinfo_level(int cpu, >>> int level) >>>   { >>>       struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu); >>>       int i; >>> -    lockdep_assert_cpus_held(); >>> - >>>       for (i = 0; i < ci->num_leaves; i++) { >>>           if (ci->info_list[i].level == level) { >>>               if (ci->info_list[i].attributes & CACHE_ID) >>> @@ -136,6 +129,18 @@ static inline struct cacheinfo >>> *get_cpu_cacheinfo_level(int cpu, int level) >>>       return NULL; >>>   } >>> +/* >>> + * Get the cacheinfo structure for the cache associated with @cpu at >>> + * level @level. >>> + * cpuhp lock must be held. >>> + */ >>> +static inline struct cacheinfo *get_cpu_cacheinfo_level(int cpu, >>> int level) >>> +{ >>> +    lockdep_assert_cpus_held(); >>> + >>> +    return _get_cpu_cacheinfo_level(cpu, level); >>> +} >>> + >>>   /* >>>    * Get the id of the cache associated with @cpu at level @level. >>>    * cpuhp lock must be held. >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>> index 6afa3f9a4e9b..424ec601cfdf 100644 >>> --- a/kernel/sched/fair.c >>> +++ b/kernel/sched/fair.c >>> @@ -1223,6 +1223,38 @@ static int llc_id(int cpu) >>>       return llc; >>>   } >>> +static bool exceed_llc_capacity(struct mm_struct *mm, int cpu) >>> +{ >>> +    struct cacheinfo *ci; >>> +    unsigned long rss; >>> +    unsigned int llc; >>> + >>> +    /* >>> +     * get_cpu_cacheinfo_level() can not be used >>> +     * because it requires the cpu_hotplug_lock >>> +     * to be held. Use _get_cpu_cacheinfo_level() >>> +     * directly because the 'cpu' can not be >>> +     * offlined at the moment. >>> +     */ >>> +    ci = _get_cpu_cacheinfo_level(cpu, 3); >>> +    if (!ci) { >>> +        /* >>> +         * On system without L3 but with shared L2, >>> +         * L2 becomes the LLC. >>> +         */ >>> +        ci = _get_cpu_cacheinfo_level(cpu, 2); >>> +        if (!ci) >>> +            return true; >>> +    } >> Is there must call it one by one for get llc size? a static variable >> instead in building sched domain? > > I suppose you suggested introducing a per-CPU variable, like > percpu(sd_llc_bytes, cpu), > or something similar to struct cpuinfo_x86.x86_cache_size. I am not > sure if the community > would endorse introducing this variable, given that sched_cache would > be its only user. > We can leave this as an open question. > > thanks, > Chenyu