From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 8B0BC46F4A6 for ; Tue, 25 Aug 2026 17:36:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787679364; cv=none; b=KMsr/28IJZhiTTgZwQ5ASBM94tip3z4k1mnugre6M7r9UkmLnRBqbAKEVX92RfWoYQy1kDuj+m6WqjYuIx2Cs1WZj+3UjleQ3xQOmsyBbcGvqdycqg9/EDWunNO32z/gzkZPGMaJuABi7MNseRrdBrdk0Bqs1MD31X5v4PWyw7M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787679364; c=relaxed/simple; bh=6x4EvH14csKLCvmL3Kj65rVWBKt55exrxC501T1PVro=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=OywOIz49DaJJomFHlvHDxq/f62UaMyoE7T9K9wt+PCzWDPvPJo4htBMcQK9GCQTtSfSf7eMv5EuQk2K+vbk5gm9pEn92UZ2q6fWw9wPz9OLjLYE4KUTtOf8J92SwrFNjHuchJ+9+QicGFoFRaPJBy9UWNMTL1EaCQiyPoHf3Mcc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PAMvjuAt; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PAMvjuAt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1787679360; x=1819215360; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=6x4EvH14csKLCvmL3Kj65rVWBKt55exrxC501T1PVro=; b=PAMvjuAtTHBknP6wGUNnIOr205hZ+tuY31iwUyNRnLsARpbxsqTdHhSl wY4f69zAT5RMrWVka75gy8PPZplSmY3wPpZHujGw7tnTWJZ0qJjcf8Tgm aGHbLmfyQ2EnNaJSu7d3SxCUe5mwo1yjaoS8Kp+37Z7Qh3i7LhGLEaQcY WxNqTZXhMdU0fR1Juyt32mLzgqfuQgKq0NrA61t0ICic20XV3Krwkhm0f FgRa6Bjp7VPY46iGFq0e7WpF2F5pA70fH4CHiB1yxLQRN4Uds9+E7b3KG RRE01sIrcyRky6TWYAIJlzShy2v9JEY3fLyi7BnrWAbkoxYuLFw4BVjHX A==; X-CSE-ConnectionGUID: tsDXaD3KQqyzTfplzj8NnQ== X-CSE-MsgGUID: 7XLz1LwbR7aHIjGDMs6UXg== X-IronPort-AV: E=McAfee;i="6800,10657,11886"; a="88284320" X-IronPort-AV: E=Sophos;i="6.25,243,1779174000"; d="scan'208";a="88284320" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2026 10:35:59 -0700 X-CSE-ConnectionGUID: yBV0vyaXTO6ew4hSdaQshA== X-CSE-MsgGUID: NmMQwEKSTluLjGyYvsBjYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,243,1779174000"; d="scan'208";a="267922646" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by orviesa009.jf.intel.com with ESMTP; 25 Aug 2026 10:35:59 -0700 From: Tim Chen To: Peter Zijlstra , Ingo Molnar Cc: Tim Chen , K Prateek Nayak , Vincent Guittot , Chen Yu , Ricardo Neri , Len Brown , Aubrey Li , linux-kernel@vger.kernel.org, Ricardo Neri Subject: [PATCH] sched/fair: avoid creating misfits during cache-aware balancing Date: Tue, 25 Aug 2026 10:41:12 -0700 Message-Id: <20260825174112.2580942-1-tim.c.chen@linux.intel.com> X-Mailer: git-send-email 2.32.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 Cache-aware load balancing biases tasks toward their preferred LLC. On asymmetric CPU capacity systems (e.g. big.LITTLE) the destination LLC may contain CPUs that are too small to run the task. Pulling the task there turns it into a misfit, trading a cache-locality gain for a capacity loss that's more detrimental to performance. Guard both cache-aware migration entry points against this: - can_migrate_llc_task(): forbid the LLC migration when the task fits its source CPU but would not fit the destination CPU. - alb_break_llc(): veto the active balance under the same condition so the runnable task is not pushed onto a CPU that cannot accommodate it. Both checks are gated with checks for hybrid processors, so symmetric systems are unaffected. Tasks that already do not fit their source CPU are left to the existing LLC policy, since the move cannot make their fitness worse (this also preserves misfit up-migration to bigger CPUs). Additionally, if there are misfit tasks found in the load balancing classification phase, prioritize misfit task migrations over LLC load aggregation on asymmetric systems. A better fitting CPU will boost performance more than better cache locality. Reviewed-by: Ricardo Neri Tested-by: Ricardo Neri Reviewed-by: Chen Yu --- kernel/sched/fair.c | 50 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6d881e530f89..cf5c022bbd55 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10691,17 +10691,40 @@ static enum llc_mig can_migrate_llc(int src_cpu, int dst_cpu, return mig_llc; } +static inline bool task_misfits_asym_cpu(struct lb_env *env, struct task_struct *p) +{ + /* + * On asymmetric CPU capacity domains, do not let cache-aware + * balancing pull the task onto a destination CPU that cannot + * accommodate it. Doing so would turn the task into a misfit on + * the destination, trading a cache-locality gain for a capacity + * loss. If the task already does not fit its source CPU, the move + * cannot make things worse, so let the LLC preference decide. + */ + if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && p && + !task_fits_cpu(p, env->dst_cpu) && + task_fits_cpu(p, env->src_cpu)) + return true; + + return false; +} + /* * Check if task p can migrate from source LLC to * destination LLC in terms of cache aware load balance. */ -static enum llc_mig can_migrate_llc_task(int src_cpu, int dst_cpu, +static enum llc_mig can_migrate_llc_task(struct lb_env *env, struct task_struct *p) { struct mm_struct *mm; bool to_pref; - int cpu; + int cpu, src_cpu, dst_cpu; + + if (task_misfits_asym_cpu(env, p)) + return mig_forbid; + src_cpu = env->src_cpu; + dst_cpu = env->dst_cpu; mm = p->mm; if (!mm) return mig_unrestricted; @@ -10758,6 +10781,14 @@ alb_break_llc(struct lb_env *env) unsigned long util = 0; struct task_struct *cur; + /* + * Migrating misfit tasks from current CPU + * to CPU with a better fit. + * Prioritize that over LLC preference. + */ + if (env->migration_type == migrate_misfit) + return false; + if (env->src_rq->nr_running <= 1) return true; @@ -10765,7 +10796,8 @@ alb_break_llc(struct lb_env *env) if (cur && cur->sched_class == &fair_sched_class) util = task_util(cur); - if (can_migrate_llc(env->src_cpu, env->dst_cpu, + if (task_misfits_asym_cpu(env, cur) || + can_migrate_llc(env->src_cpu, env->dst_cpu, util, false) == mig_forbid) return true; } @@ -10805,8 +10837,7 @@ static bool migrate_degrades_llc(struct task_struct *p, struct lb_env *env) READ_ONCE(p->preferred_llc) != llc_id(env->dst_cpu)) return true; - if (can_migrate_llc_task(env->src_cpu, - env->dst_cpu, p) != mig_forbid) + if (can_migrate_llc_task(env, p) != mig_forbid) return false; return true; @@ -11869,6 +11900,15 @@ static inline bool llc_balance(struct lb_env *env, struct sg_lb_stats *sgs, if (env->sd->flags & SD_SHARE_LLC) return false; + /* + * On asymmetric domains, group_misfit_task_load + * should be prioritized to move tasks to CPU that fit them + * over aggregating tasks to their preferred LLC. + */ + if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && + sgs->group_misfit_task_load) + return false; + /* * Skip cache aware tagging if nr_balanced_failed is sufficiently high. * Threshold of cache_nice_tries is set to 1 higher than nr_balance_failed -- 2.32.0