From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 5B1201E5B63 for ; Sat, 1 Aug 2026 12:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785586984; cv=none; b=FLr3bG94YxMGYVS1rApz8/GFSmzwuVttZ7oN6UuANlQ3z7MRRNNg6woM5uebIV76Ixc3l1ygPuVH6xKbmHhFDKkUbz9xkC8ZxDUIAdjac/j96heAntvUhZDNw8DY9M7DV6sLcdN4F1QlokLO9GeRrSwXBo8mkfgs8XxwXLdab3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785586984; c=relaxed/simple; bh=SiKgtOySrYmf1vYc2UJ3Rh9xNtoVI62l9bPRDug+V3w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pQo+poamYz2iHPQqjdraFgwUcV3xfH3ocQDEX6HowcqZtaFIpY0FTyRBtLRNnRjufbFaceQkUQgMc10zq3mgo0aNvHO/RMllq8ABdClee6QHEwODUXsIBfPr6iAUGYHyupX2HhOXipCBkcCpa6LWJ0HpENjGDzuRSVNLeQ9yaA4= 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=T3Lmj/RP; arc=none smtp.client-ip=209.85.210.172 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="T3Lmj/RP" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-848761b5897so1383462b3a.3 for ; Sat, 01 Aug 2026 05:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785586982; x=1786191782; 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=2JT2mU4Dx1Y9MbBDXuGlKlGeyhcO6/z4llhTX4pGN1U=; b=T3Lmj/RP1vPNjI+02yPCWqA+/oqUYFXf40+uRbhdkyl4ucEjpHP8DmUFESsNxJDKxF HFZumW0wdKpVrxmKYif6LDJ6c+rZZNH8vOFILG8Odc0aOsPKu9ZrgE/Yv2ydwDVN7APa legRYN7ywjZy++fCzHFF8/vkuhR+q8CLy6e/1FQtZOr1sHIDGJptiJ2PZ7MVpd8HAOcP Z2n8JslZyZ2Ca4lawm4zyFiQejciXpRH4pxTDJsjN//41n4UWGg/E0ZfThqCWSgKyXGd b9O2MbENpRt626rgn9bjIl3OteVO/1klj9SxFsK8qrN6am7cuaDS4uM3eVgvitEJrRMk UV1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785586982; x=1786191782; 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=2JT2mU4Dx1Y9MbBDXuGlKlGeyhcO6/z4llhTX4pGN1U=; b=JrTPvhiliGdib9LncuAZySbAR4KzkaBpQSVZa0B4n9VYbMccrNcyOxoB3RyB3kneV+ RMQW5JQQxfRL/UrAhFJoP4KmLJ0cOzE2PKEHHoeb/iIdpiK6Ohs/KW1ddVaao/Lhh/FP +Cx1m90/rms678c0Y4TmC3iLiy5ZKxIH7ONhC9CNXjCaKLkL3NsMamLovHbR3T8wPrra hQpEy2c50F3uXTg/f8N+tUD4a1HRGMzFXU2DHPiPSmcyLEkMuNfW4LVOUkuOlK9QS4nu xM7sunwDTl9fz2vLdcqllug7kfq5J947JyFNXaIye2lrVZc9w+6GHsglqlsIpqNqYnc6 6eRg== X-Gm-Message-State: AOJu0YycWLcHliAsYNIqJC84kDrZ41HBZk4folx/nMe18s/17Cq5jQUu +UXcPD/h8tNyVjlnLTKPv9zW/69rGNrd6kRmczGTimob/EnT67PhY+7zzTMPGpsBNSo= X-Gm-Gg: AR+sD12RxnlUEwcarSOhJU42CGMwXDVi85hJMAHjAWqKvVKnnrahZ6mm3gtharfyUhs 0tiSs6q5ant2fNIpWNOuP8bZYqCqWwnlUbV5umuoQvIQp38fajcVJWcWY30IqS3VVL/zpzMq0l2 z1nHvUprSlkAkQ6x2Tr8boYD57GDz8hohLksoMgNXoFOwHEDRtSfB7jex6ErW7+zd7oFLBsdkc/ 3c4EmpxJvNylUhRRylBoUYBBayncUeM94/Twf0+J4oH6q6qnRm4leNQx5LEeyeewLin81m3Q4TW VxgrieYwqDelMSb5eSj6KQf9sis88RM+LqNN4vu17hnFP5rY4S1qsQJtoQRLFsObj2u/AOoccun Gt/6FxC0yCHWoBtI5x4/ZmFv/eHviCOhmzAycL7VEZsgYt/aZoXhtf7P4OdkkfqqoL7xX7OKGGR FmTMTgPjaW4+ZOyNHyUk5hGI/KZoXb+e2hv/QfbEgnourDTVbtELM3uh5uhSxDftR4rSWVm5K7/ wmAvpmrkMmtSgf+dicVjc5b+efN63R2hRgNUQ== X-Received: by 2002:a05:6a00:1388:b0:84e:1da9:6a53 with SMTP id d2e1a72fcca58-84ee47b7522mr3031692b3a.19.1785586982492; Sat, 01 Aug 2026 05:23:02 -0700 (PDT) Received: from PC-2B0BA19500175.company.local ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84edc2d7b97sm1617526b3a.43.2026.08.01.05.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2026 05:23:01 -0700 (PDT) From: Lu Wang To: linux-kernel@vger.kernel.org Cc: tim.c.chen@linux.intel.com, yu.c.chen@intel.com, peterz@infradead.org, mingo@redhat.com, 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:22:52 +0800 Message-ID: <20260801122252.2476258-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 --- v2: add Tim Chen and Chen Yu to Cc 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