From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 3BB08DDCD for ; Sat, 1 Aug 2026 12:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785586662; cv=none; b=BrNYNHzsi9n6/EdA9+4yaECUF9DEok7fxa3K6j9kkiNJWZ/Wx07MshbMsEHzCXbsKKQQ63yYWIvaJqG54YxfOwzAf0NXeUZ3up2Th86XNa6467pRdqXuOUppepYQ/bG92w9VFKW9kM5U4R85dEe6o8RhN+z2hO0vV5cOpmvqCnU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785586662; c=relaxed/simple; bh=ozZtAN8c3DU4MA3gIf4oGLLi3CnZ4INdaSZclfJO8Pg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WBC5byBrwVjj7pXnudprgLgNZjeFyLKk1G3htIZI1K4W6sexgUFquer+dXRP2+JHNghLFlTOfL4ELGybCkXHWt3Vs5J/7+Dc3nlJuxuYbzhE0SYArCxonoYFCFMCUHrF7a7oRHIH9Pq5Hd4j6wt61OkS/0qJ1e+EXQ59NUuORy4= 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=kTsHv4oT; arc=none smtp.client-ip=209.85.214.180 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="kTsHv4oT" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2caea3f742bso20308685ad.0 for ; Sat, 01 Aug 2026 05:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785586658; x=1786191458; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=f4Q7VeK2dytvwVpU0K2vC/UvjAMOp2OKqWB8l5b5S/Y=; b=kTsHv4oTrB0bixsEfc3Q3RGMkLoVFo3qub2gD8luiC5Au2QykU4SfiApt0Lqvj6fmg T54qK9mp4FlesghSV2JbI7Ss3w9sHizRnjJIzyfiS8JYWtRMKNswJEyAQvsinFn7jUQj 7XhA09rn4GkyfIanXcMO+rkzDHLQVjSNHyaeAR0qlF/rrIMpVstMkuPwMZZsN0qlRXig lOxZFO3RDTXaeQBNlWEFq+h1YQ/G+neP7B9G304Y29o8YBaaASpNj+mhEXVPJn3tJ4DD QVBBlRI9fyqVS1tzH1LrHR81blB32mr++aLGMahjAoeoOtDMcHsXzTZpjU4u2BDdLgTU jUCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785586658; x=1786191458; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f4Q7VeK2dytvwVpU0K2vC/UvjAMOp2OKqWB8l5b5S/Y=; b=bnAVbrseoEd+cIpzlGsnwGRXEoTKtIiIQbyn4clotlgVYphlS344Qs8ur/LnxIpd21 aZFcSDrU+pYX2yC8tT8qNrxNEcFyAwB+HlXn9+DA0qyPEvYmNiimysrE4b+M6N4VhdXB Fan4EodfVTRmUHw2IvCGLcX0JTKf30vTyWxZviVDsl339pTeVErt9AKKApkZbeFINdmp 2DzX6nCAV0OQ5QZdDsBASN624uQ9CFI7dreqObHC+dx4Uvd7bxiimEMoc+cXN+JoqbZL //uF3FhmAeTzxhd2UDXzHk9hsbS6neTfSFElMKXmlolSRMCFi4yWgGRuv/2zxAi8VGvk D/Mg== X-Gm-Message-State: AOJu0Yy38uXwXtbTyBmj8apexPYE+uYRLZpDujsFxiol1jkBT/7EoFXj 30aYoZvAUlqj7g5rndJPbboPIL+reo5AkdmBNJ9II4TFyo3v8n1rn1PnUNQyDv5dm6e4Ew== X-Gm-Gg: AR+sD133vGm5Vt0xh9TjlUhPMcJ6PGMdHa02PkDO+8lbqvdyo3bI7j9dHCKWRubm8OU pRe+AnHHlHCMz1hQsfQq9YDqiX+aRnuVOpo4SWzYkPnyb+Gm/2RAXwzmxt4WwnGB+0CkCx9K43P I+PcbA/GkLaxU3gegzAqf1b5n4cTrf5NIpyVpceuk3vf3XEftRyZlWhSb2ZDHpvOPo0Dhluh7KQ 0mPaw1CAQaRQsHUnPjtDK1FukCyqSUZdrEM1DV4oloCvzeg3Dm8GpIzsK1fslM3ALhWT/mZnIor WMyRsZjnUOeVtUwUBb178bs81FBz/ByB2gi3fvtIOTviptbMlRbb0lsuOwn2xcnW9BCbz8/Wq/i Y2F8F7khZCtgd+QU4mCpQc4kjY022yMhpSXdfMHhZoFC1gyc+1g3s20y9H2M85mQ3K1SQhFKQ/Z BDnUd9MT93HQup5F1/sdBd+HOcKi7laYuUCHYLaWF36sGl6mLdJDhNVn/MntBYY18LR3YjnRTBD HOt53usYU2Ypbg= X-Received: by 2002:a17:903:1b43:b0:2ca:d658:d874 with SMTP id d9443c01a7336-2d0523f9f93mr33409515ad.23.1785586657700; Sat, 01 Aug 2026 05:17:37 -0700 (PDT) Received: from PC-2B0BA19500175.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d04ae5aac8sm17275815ad.24.2026.08.01.05.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 05:17:37 -0700 (PDT) From: Lu Wang To: linux-kernel@vger.kernel.org Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, Lu Wang Subject: [PATCH] sched/cache: honor migrate_llc_task semantics in active load balance Date: Sat, 1 Aug 2026 20:17:29 +0800 Message-ID: <20260801121729.2468102-1-wanglu.priv@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A passive load-balance pass marks group_llc_balance as migrate_llc_task and queues active balance when it cannot move a task. The CPU stopper callback constructs a fresh lb_env, so preserve the migration type on the runqueue across the asynchronous boundary. For CAS-directed active balance, reject a candidate whose preferred LLC does not match the destination LLC. This keeps the fallback from moving a task away from its preferred LLC. Fixes: e4c9a4cb244a ("sched/cache: Add migrate_llc_task migration type for cache-aware balancing") Signed-off-by: Lu Wang --- kernel/sched/fair.c | 25 ++++++++++++++++++++++--- kernel/sched/sched.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d78467ec6..cf036a8a0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10645,6 +10645,18 @@ alb_break_llc(struct lb_env *env) return false; } +/* + * Returns true if p's preferred LLC does not match the destination CPU, + * meaning this task should not be migrated under migrate_llc_task semantics. + */ +static inline bool +migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env) +{ + return sched_cache_enabled() && + env->migration_type == migrate_llc_task && + READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu); +} + /* * Check if migrating task p from env->src_cpu to * env->dst_cpu breaks LLC localiy. @@ -10673,8 +10685,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env) * run on env->dst_cpu, skip the tasks do not prefer * env->dst_cpu, and find the one that prefers. */ - if (env->migration_type == migrate_llc_task && - READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu)) + if (migrate_llc_task_wrong_dst(p, env)) return true; if (can_migrate_llc_task(env->src_cpu, @@ -10697,6 +10708,12 @@ alb_break_llc(struct lb_env *env) return false; } +static inline bool +migrate_llc_task_wrong_dst(struct task_struct *p, struct lb_env *env) +{ + return false; +} + static inline bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env) { @@ -10796,7 +10813,7 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env) * 4) too many balance attempts have failed. */ if (env->flags & LBF_ACTIVE_LB) - return 1; + return !migrate_llc_task_wrong_dst(p, env); degrades = migrate_degrades_locality(p, env); if (!degrades) { @@ -13485,6 +13502,7 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq, if (!busiest->active_balance) { busiest->active_balance = 1; busiest->push_cpu = this_cpu; + busiest->active_balance_type = env.migration_type; active_balance = 1; } @@ -13654,6 +13672,7 @@ static int active_load_balance_cpu_stop(void *data) .src_rq = busiest_rq, .idle = CPU_IDLE, .flags = LBF_ACTIVE_LB, + .migration_type = (enum migration_type)busiest_rq->active_balance_type, }; schedstat_inc(sd->alb_count); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 56acf502b..82084d405 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1266,6 +1266,7 @@ struct rq { /* For active balancing */ int active_balance; int push_cpu; + int active_balance_type; /* enum migration_type */ struct cpu_stop_work active_balance_work; /* CPU of this runqueue: */ -- 2.43.0