From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.234 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796557208; b=BcuRw0n/pL0R5dJ0PFv+TxKbfE/aPX5/L57gJvQHA0ZTF/pPs9FvGwbb4MSHce1VlC+R eiqZA5Z6AfUNsuGQXgUDxGkOSao8elLNdvkW4qj7xIxsOxSCHO2Zgq7jvm1FtsEfWZIvW ik9eONrdfJVFE0CxvV6ciPfz2k/56BM3HPTwRr7lan0A07sSgx77UoGVvcMiR5zRGX39K 7/4a0PDoc/KRqaraOJhVVCnd3AnaBxKSa+bOJLJ5wmldDjhxjcWZ43jdxT3l3RWeM/51X xsIVse3vViPdLSD/b4F0KiPvFO7qrUaZWZiS2PPq4GGe6t+f4Th9jZqyJio+H/FsQzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796557208; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=Yc14jGYhP4dVZI5Gwc5fKStcisXQODbyjhXnYeSyI48=; b=fJbOantiYz1lyTbocoPlJDp7YMxX9p30Y9aaYS0+lfXw/O0OJD+MkQue9wRl69Gw+4cC TLHU0hDSZ6qNXzAjRGmjPiEDwuwJoVFtNRu0SpwRYoxAp4gLdlgVoRMcFoPawL5aPqZ/p 05xK7hgj+rffu2kRfD3RfGm0JL3pChLgCeWYZCBKBuVj/YNza5YK7VXTrzQSrvrb4f50M PF/poiciV6uVacCO6DApk2vH5hc9ygFzFaAoggd79g5myzWgdWF26XHveeeqnostHgTht 4Hn8XDL1N28ZngHlSKFvwhj9W4xUHGpA0sD68b3czh2WfMaFjzAxFUPjsTsX1cVlgRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="QG0+/BI0"; arc=none smtp.remote-ip=91.218.175.234 Received: from mta0.migadu.com (out-234.mta0.migadu.com [91.218.175.234]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5935606A33F for ; Sun, 6 Dec 2026 11:40:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A5935606A33F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=QG0+/BI0 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=2PuPc6y8RLIpTdApaDEyb6fSEk22RxNDPHQQ2WsUVTs=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796557204; v=1; x=1797162004; b=QG0+/BI0fx8IQ6lHFHsLHFE0EAV9VB9P2xCbkAeEE8JhkG0QMbxlNVbSR+mWdZLNJywWleK0 tz7WnfX6B65bpRG4fTti7+GUNLn//7E+r3PnIwjB7ANyUEr4sue/Kl0Qy6CnMYdgClbsFRgL61E 1hPI2zuX0aUWkky7GINDDPoE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 999ea5a0ee3235fc; Sun, 06 Dec 2026 11:40:02 +0000 X-Mizu-Trace-ID: 999ea5a0ee3235fc X-Migadu-Flow: FLOW_OUT From: Qiliang Yuan Date: Sun, 06 Dec 2026 06:38:44 -0500 Subject: [PATCH 7/8] sched/fair: Avoid pulling tasks away from memory that cannot follow them X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261206-feat-numab-series-v1-7-2af21ad24718@linux.dev> References: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev> In-Reply-To: <20261206-feat-numab-series-v1-0-2af21ad24718@linux.dev> To: Peter Zijlstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Mel Gorman , K Prateek Nayak , David Hildenbrand , Andrew Morton Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Valentin Schneider , Zi Yan , Gregory Price , Ying Huang , Kefeng Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qiliang Yuan X-Mailer: b4 0.13.0 The load balancer evens out busy CPUs across NUMA nodes and only reluctantly moves a task away from its preferred node: migrate_degrades_locality() makes such a task cache hot, but once a domain has failed to balance more often than cache_nice_tries the move happens anyway, and active balancing does not ask at all. For a task whose memory cannot follow it, a move to another package is not undone by migration, so the task keeps paying for remote accesses or is pulled back by NUMA placement only to be pushed out again. Refuse to pull a task whose memory was found stuck out of the lowest NUMA domain around its preferred node. A task that shares its CPU may still leave, but only when no CPU of that domain is idle to take it instead. Moves within the domain are left to the usual rules. The check comes before the active balance shortcut in can_migrate_task(), so both regular and active balancing honour it, consistent with the placement side, and sched_balance_rq() does not wake the stopper for an active balance that would be refused. Signed-off-by: Qiliang Yuan --- kernel/sched/fair.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7fc5845324f4f..515775a8db6ee 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10823,7 +10823,53 @@ static long migrate_degrades_locality(struct task_struct *p, struct lb_env *env) return src_weight - dst_weight; } +/* Return true if @p could run on an idle CPU in the lowest NUMA domain of @cpu */ +static bool numa_nearby_cpu_idle(struct task_struct *p, int cpu) +{ + struct sched_domain *sd; + int i; + + sd = rcu_dereference_all(per_cpu(sd_numa, cpu)); + if (!sd) + return false; + + for_each_cpu_and(i, sched_domain_span(sd), p->cpus_ptr) { + if (idle_cpu(i)) + return true; + } + return false; +} + +/* + * Pulling a task whose memory cannot follow it out of the NUMA neighbourhood of + * that memory puts every access on a remote link. Keep it there unless its CPU + * is contended and no CPU in the neighbourhood is idle to take it instead; + * moves within the neighbourhood are left to the usual rules. + */ +static bool migrate_strands_memory(struct task_struct *p, struct lb_env *env) +{ + int pref = p->numa_preferred_nid; + + if (!static_branch_likely(&sched_numa_balancing) || + !(env->sd->flags & SD_NUMA) || !p->numa_mem_stuck || + pref == NUMA_NO_NODE) + return false; + + if (!numa_node_nearby(pref, cpu_to_node(env->src_cpu)) || + numa_node_nearby(pref, cpu_to_node(env->dst_cpu))) + return false; + + return env->src_rq->cfs.h_nr_runnable <= 1 || + numa_nearby_cpu_idle(p, env->src_cpu); +} + #else /* !CONFIG_NUMA_BALANCING: */ +static inline bool migrate_strands_memory(struct task_struct *p, + struct lb_env *env) +{ + return false; +} + static inline long migrate_degrades_locality(struct task_struct *p, struct lb_env *env) { @@ -11298,6 +11344,9 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env) * 3) task is cache cold, or * 4) too many balance attempts have failed. */ + if (migrate_strands_memory(p, env)) + return 0; + if (env->flags & LBF_ACTIVE_LB) return !migrate_llc_task_wrong_dst(p, env); @@ -14033,6 +14082,10 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq, if (!cpumask_test_cpu(this_cpu, busiest->curr->cpus_ptr)) goto out_one_pinned; + /* Nor if can_migrate_task() would refuse to strand its memory */ + if (migrate_strands_memory(busiest->curr, &env)) + goto out_one_pinned; + /* Record that we found at least one task that could run on this_cpu */ env.flags &= ~LBF_ALL_PINNED; -- 2.43.0