From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DBDA2BE62E for ; Wed, 10 Dec 2025 15:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765382390; cv=none; b=HZhManB+PCzfJapFv9YqWScjaD8T96IYSrTPWFqjtoiyUOBnXeQgfh3mzhXOGHsF4Zl5JpVlzo3VfA1LYqsIAKnbWfAxiX9bMvs8lNtmpHf/veuIRIUqh9uSjIoLI+/VXWJ0w1k68FMiAsMpbWxXhzZnzCcbSO3YQfH5Su2UFMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765382390; c=relaxed/simple; bh=z5MJ/EStDecer9NUCqiacj7fiYEzTkMVlHW8GBvNsj4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=n+Cva3XZE0BDGQrTQEG/LQ3sJ19NNernNXw2bJTVYRSion6BOcAo2C6iq3kuN2SzrZmj7NyBRz6muZq3q6XfcGwoilc8NSw5PEk+89nvtDT0DsL7gDh+aJR4TTxfObMO9pit9qdmmiE9w5UMg+moDZ8LcGdal2v+z1rk+0npKV4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=VoQR1q0H; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VoQR1q0H" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=bjM2pV5tfuTs8Dc3ee+BfzqhcsOL1+3l5zyXLdtL9KU=; b=VoQR1q0HLkNk9VQUt9Ah0L6PId bb6RGYtXVQ+T/WHPCKlHwTwcyqK8nD0yuaLQ9TILTtEeHEUCTfdjVAf9xaZs4XhHSLp/JiJe5Rmom yhY/T4hR6PE8lvPZjjbVhOSVikNO1Y4pAe24nlBI7xVNb6SO2ipBtvDTZceIbUCxqZp0EcRMPpzpA MLby/4kIsgzQ4boWrCXxtae2UX5SxvogjdFaMjGZ7HUx5zLSIetdaPNR2q/Za7ADOolUy+AWtLqrr BxTkLBOPnzcprNLj9vevRWauKUnuZMkEGJoG1sJVFGbfJDBX+QvMXHXGskxftp+1sX83pWc1ih7Tg zd4VchXQ==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vTLj1-0000000DXwC-3LbT; Wed, 10 Dec 2025 15:03:31 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 4EF39302EC2; Wed, 10 Dec 2025 16:58:48 +0100 (CET) Date: Wed, 10 Dec 2025 16:58:48 +0100 From: Peter Zijlstra To: Tim Chen Cc: Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , 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 , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 14/23] sched/cache: Consider LLC preference when selecting tasks for load balancing Message-ID: <20251210155848.GV3707891@noisy.programming.kicks-ass.net> References: <048601436d24f19e84c0a002e1c5897f95853276.1764801860.git.tim.c.chen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <048601436d24f19e84c0a002e1c5897f95853276.1764801860.git.tim.c.chen@linux.intel.com> On Wed, Dec 03, 2025 at 03:07:33PM -0800, Tim Chen wrote: > Currently, task selection from the busiest runqueue ignores LLC > preferences. Reorder tasks in the busiest queue to prioritize selection > as follows: > > 1. Tasks preferring the destination CPU's LLC > 2. Tasks with no LLC preference > 3. Tasks preferring an LLC different from their current one > 4. Tasks preferring the LLC they are currently on > > This improves the likelihood that tasks are migrated to their > preferred LLC. > > Signed-off-by: Tim Chen > --- > > Notes: > v1->v2: No change. > > kernel/sched/fair.c | 66 ++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 65 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index aed3fab98d7c..dd09a816670e 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -10092,6 +10092,68 @@ static struct task_struct *detach_one_task(struct lb_env *env) > return NULL; > } > > +#ifdef CONFIG_SCHED_CACHE > +/* > + * Prepare lists to detach tasks in the following order: > + * 1. tasks that prefer dst cpu's LLC > + * 2. tasks that have no preference in LLC > + * 3. tasks that prefer LLC other than the ones they are on > + * 4. tasks that prefer the LLC that they are currently on. > + */ > +static struct list_head > +*order_tasks_by_llc(struct lb_env *env, struct list_head *tasks) > +{ > + struct task_struct *p; > + LIST_HEAD(pref_old_llc); > + LIST_HEAD(pref_new_llc); > + LIST_HEAD(no_pref_llc); > + LIST_HEAD(pref_other_llc); > + > + if (!sched_cache_enabled()) > + return tasks; > + > + if (cpus_share_cache(env->dst_cpu, env->src_cpu)) > + return tasks; > + > + while (!list_empty(tasks)) { > + p = list_last_entry(tasks, struct task_struct, se.group_node); > + > + if (p->preferred_llc == llc_id(env->dst_cpu)) { > + list_move(&p->se.group_node, &pref_new_llc); > + continue; > + } > + > + if (p->preferred_llc == llc_id(env->src_cpu)) { > + list_move(&p->se.group_node, &pref_old_llc); > + continue; > + } > + > + if (p->preferred_llc == -1) { > + list_move(&p->se.group_node, &no_pref_llc); > + continue; > + } > + > + list_move(&p->se.group_node, &pref_other_llc); > + } > + > + /* > + * We detach tasks from list tail in detach tasks. Put tasks > + * to be chosen first at end of list. > + */ > + list_splice(&pref_new_llc, tasks); > + list_splice(&no_pref_llc, tasks); > + list_splice(&pref_other_llc, tasks); > + list_splice(&pref_old_llc, tasks); > + return tasks; > +} > @@ -10119,6 +10181,8 @@ static int detach_tasks(struct lb_env *env) > if (env->imbalance <= 0) > return 0; > > + tasks = order_tasks_by_llc(env, &env->src_rq->cfs_tasks); > + > while (!list_empty(tasks)) { > /* > * We don't want to steal all, otherwise we may be treated likewise, Humrph. So NUMA balancing does this differently. It skips over the tasks that would degrade locality in can_migrate_task(); and only if nr_balanced_failed is high enough do we ignore that. Also, if there are a significant number of tasks on the list, this gets in the way of things like loop_break, since it does this sort unconditionally. Bah, this feels like there is a sane way to integrate all this, but it seems to escape me at the moment. I'll ponder it a bit more.