From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.230 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796557193; b=LG9/zwrtz6bAk9kP32xAzedXwQ+68arWc51kow29roqOy36jnVJBD+YX3XTefM7urQ+t pvd+n2mj6lR15dicNCEdaEE0C+qaLMO8INEod4EgVevOxippOtS1AxIvFOztp7zOOFlYB HruJlxlx6XkKCWrSzOKlMYHjAqufo4zsu7BrOpLf53kN6zaq2nuhm/4192croeDxepAk3 bZA0j9cbdqjk18DzyEjvQn8dqlrzBeUTOVgOs7lvLh+JUndNuajFYdzaYiuhNrjklBML4 9kdK/3jJ9RH2aRvXe6x7spZVHTuW/K/YKUCvfVTk1D9Jy2ajSxc8jfkhrHooaJarHjg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796557193; 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=rgtKa2tB6/6SWP71CbPqeTfjm5fLrht3B9dNGQBKzn8=; b=WqDP1UhRjOEZRoXRc4C9CB7APfOFY7DvKug1IPkDLZ7e5Ttp1nELKfgsBee8vVQoj/+0 lXVK42SA8DsCL+TGgmiZMAUxrTDXEVM4eDaFCM1rlxqcIoXkr/VVc/T0OTCKys1AUNcAF 2v1a31iG6/Y0lsPl+pbV7T/HFAD+nSiLJ1qLSopjIorI1hZxUeBxQ7xBBulkcLphD0eLT 47rTQGJYsqScmGKdijkPrrJTIdM6kGKFXYJcft75Vh2UtEvmBBCqnoUs722AsWBwRofIJ 999nqMPSSPv/czyjLd6TGAoAyLb/Kdm6Hrwl9aCNkkfPsnps+79jqjlc0EbDvi1+DMQ== 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=KHQnF307; arc=none smtp.remote-ip=91.218.175.230 Received: from mta0.migadu.com (out-230.mta0.migadu.com [91.218.175.230]) (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 6FBE4606A33F for ; Sun, 6 Dec 2026 11:39:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6FBE4606A33F 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=KHQnF307 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Zu9LlD3nF9VWnpjpYYM8cQ8PbZPo0sF/UWWbze7BpfI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796557190; v=1; x=1797161990; b=KHQnF307zKvbKw3noMItOSzBGHN+igzq7/hchJPyD4VUCuCpEA8Lk7NuYrm6DaWqkZbQA7NA iZHmDZRw8I4El125zZitlLtUt7eLmX78308/FOkdXmg8MnLsEJl7JTisbHnqr5ndhuemu5W8iiV 1DtikJmdZemLVBGQ/A18kjng= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id a685f3cd0459019d; Sun, 06 Dec 2026 11:39:50 +0000 X-Mizu-Trace-ID: a685f3cd0459019d X-Migadu-Flow: FLOW_OUT From: Qiliang Yuan Date: Sun, 06 Dec 2026 06:38:43 -0500 Subject: [PATCH 6/8] sched/numa: Keep tasks near 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-6-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 When task_numa_migrate() finds no room on the preferred node of a task, it tries the other nodes in turn and may pick one on another package. For a task whose memory follows it that only delays the convergence. Memory that cannot migrate stays behind, though, and every access from the other package then crosses the link between the packages. Skip candidate nodes outside the lowest NUMA domain around the preferred node for tasks whose memory was found to be stuck, and do not swap such a task out of that domain to make room for another one. task_numa_migrate() already takes its imbalance settings from that domain, sd_numa; with the distances firmware reports for multi-die packages it spans the package of the memory. Nodes inside it are still used to spread such tasks, so they do not all crowd onto the node of their memory. Signed-off-by: Qiliang Yuan --- kernel/sched/fair.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ea483c8dabcf9..7fc5845324f4f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3197,6 +3197,26 @@ static bool load_too_imbalanced(long src_load, long dst_load, * into account that it might be best if task running on the dst_cpu should * be exchanged with the source task */ +/* + * Return true if @nid lies inside the lowest NUMA domain around @pref_nid, the + * one task_numa_migrate() balances in. It covers the nodes at the first remote + * distance of sched_domains_numa_distance[], which is the package when the + * SLIT puts the nodes of a package at that distance. + */ +static bool numa_node_nearby(int pref_nid, int nid) +{ + int cpu = cpumask_first(cpumask_of_node(pref_nid)); + struct sched_domain *sd; + + if (cpu >= nr_cpu_ids) + return true; + + guard(rcu)(); + sd = rcu_dereference_all(per_cpu(sd_numa, cpu)); + return !sd || cpumask_intersects(sched_domain_span(sd), + cpumask_of_node(nid)); +} + static bool task_numa_compare(struct task_numa_env *env, long taskimp, long groupimp, bool maymove) { @@ -3239,6 +3259,11 @@ static bool task_numa_compare(struct task_numa_env *env, if (!cpumask_test_cpu(env->src_cpu, cur->cpus_ptr)) goto unlock; + /* Nor if the swap would take it away from memory that cannot follow */ + if (cur->numa_mem_stuck && cur->numa_preferred_nid != NUMA_NO_NODE && + !numa_node_nearby(cur->numa_preferred_nid, env->src_nid)) + goto unlock; + /* * Skip this swap candidate if it is not moving to its preferred * node and the best task is. @@ -3514,6 +3539,11 @@ static int task_numa_migrate(struct task_struct *p) if (nid == env.src_nid || nid == p->numa_preferred_nid) continue; + /* Keep a task whose memory cannot move near that memory */ + if (p->numa_mem_stuck && + !numa_node_nearby(p->numa_preferred_nid, nid)) + continue; + dist = node_distance(env.src_nid, env.dst_nid); if (sched_numa_topology_type == NUMA_BACKPLANE && dist != env.dist) { -- 2.43.0