Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp131534pxb; Mon, 13 Sep 2021 15:03:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuDmZgqhOefm9ABRmzhKvnCXczhaVHSkMVEpBPU3yJMI766dAUxtulO8AuIDz3gO8jxExr X-Received: by 2002:a17:906:32c9:: with SMTP id k9mr15265695ejk.218.1631570599889; Mon, 13 Sep 2021 15:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631570599; cv=none; d=google.com; s=arc-20160816; b=cvfRwoGrNCxA0LjFIiGD6VzBEW4o6nqPxrqoxOy+eW1KqRzCX/2jzVYnaZxEXndYBh MVIsRnhW2t2pi9V8gaSwnSxhZLKJ7D22cWJP9C+NnYSK4MlZLcEhycGxOQqTY5Zt4PwQ 1TyhrXqFpXGSWkMt3o6NOIDeeW7KHO5tsMk7+Z4wa5YmpWfa4XM+nk91Hbe4ePL6W6y9 Bh/DGa8toKgGoIxEuYczeRAMEoac7YZzzMad4YHO4SUGF3YA/9SLV94hHXPPTNBwr7Wo ZLJuESPr7zvxc3FrbaBGp3lAwwxkfxx4Q6scvmFItdihP91LPlwr9G+nlp21zKtvOOaB d4cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qckFg9XU9GWGfhm9+1AVhiRm5TCb8bVvYTImtvm5QHQ=; b=MpjvuGUA+h999N6YPOa5WqbrpQXQS0doInrOGGIVw5OM+cxsna+Ab+6+lI1etSZFm0 0hvZMOs4k8/6dJyTF4GuJmHFuEU24Nyd4EffhioedLx8XQeInFMU35L1yiv6fLeNhHyW uA9Qq/Am9YETZQb7wpE1UHIBzsQsMLitmyailIzq9i1PMd58QvVp+UWx7h2GH8oqUszJ SnaVuSPKAQ/aRRhJ1Wpyv9zfDwUSZFZ5N5yLny4lHnVPfdA6eA7xNlNjW0BbsgorkPAV my9MKztgLz4G7c4aFuoRRapC07n2dodbXcKi+2Z/yqiiR9pT5cO4uQoyKHtwfFQcQ4sx 0AFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gf7RkJoo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si7579973ejg.400.2021.09.13.15.02.30; Mon, 13 Sep 2021 15:03:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Gf7RkJoo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242351AbhIMN5f (ORCPT + 99 others); Mon, 13 Sep 2021 09:57:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:42350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245498AbhIMNyn (ORCPT ); Mon, 13 Sep 2021 09:54:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0BD7861248; Mon, 13 Sep 2021 13:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540122; bh=rb5C6WW6/bDKVBxPuN9QOIOw1p0aMDU2t+VfplnDPdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gf7RkJooap/P4jwaKiAtRvYPASkltvsj/7+7RXq84dXbKvvN7PjoCyZBuC0ebuiF8 CfvOD3IS8q3d+oVOBEIpuB1YfXFjFOvpQv3tXstlYTrw8aEZz3q9WpjwP8iPVwMz1L HyJ4wgOBgYGgGYPZUcppggLJWVCO2zpZ8BlGGC5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geetika Moolchandani , Srikar Dronamraju , Valentin Schneider , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.13 028/300] sched/topology: Skip updating masks for non-online nodes Date: Mon, 13 Sep 2021 15:11:29 +0200 Message-Id: <20210913131110.271110144@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Valentin Schneider [ Upstream commit 0083242c93759dde353a963a90cb351c5c283379 ] The scheduler currently expects NUMA node distances to be stable from init onwards, and as a consequence builds the related data structures once-and-for-all at init (see sched_init_numa()). Unfortunately, on some architectures node distance is unreliable for offline nodes and may very well change upon onlining. Skip over offline nodes during sched_init_numa(). Track nodes that have been onlined at least once, and trigger a build of a node's NUMA masks when it is first onlined post-init. Reported-by: Geetika Moolchandani Signed-off-by: Srikar Dronamraju Signed-off-by: Valentin Schneider Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20210818074333.48645-1-srikar@linux.vnet.ibm.com Signed-off-by: Sasha Levin --- kernel/sched/topology.c | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 55a0a243e871..41f778f3db05 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1372,6 +1372,8 @@ int sched_max_numa_distance; static int *sched_domains_numa_distance; static struct cpumask ***sched_domains_numa_masks; int __read_mostly node_reclaim_distance = RECLAIM_DISTANCE; + +static unsigned long __read_mostly *sched_numa_onlined_nodes; #endif /* @@ -1719,6 +1721,16 @@ void sched_init_numa(void) sched_domains_numa_masks[i][j] = mask; for_each_node(k) { + /* + * Distance information can be unreliable for + * offline nodes, defer building the node + * masks to its bringup. + * This relies on all unique distance values + * still being visible at init time. + */ + if (!node_online(j)) + continue; + if (sched_debug() && (node_distance(j, k) != node_distance(k, j))) sched_numa_warn("Node-distance not symmetric"); @@ -1772,6 +1784,53 @@ void sched_init_numa(void) sched_max_numa_distance = sched_domains_numa_distance[nr_levels - 1]; init_numa_topology_type(); + + sched_numa_onlined_nodes = bitmap_alloc(nr_node_ids, GFP_KERNEL); + if (!sched_numa_onlined_nodes) + return; + + bitmap_zero(sched_numa_onlined_nodes, nr_node_ids); + for_each_online_node(i) + bitmap_set(sched_numa_onlined_nodes, i, 1); +} + +static void __sched_domains_numa_masks_set(unsigned int node) +{ + int i, j; + + /* + * NUMA masks are not built for offline nodes in sched_init_numa(). + * Thus, when a CPU of a never-onlined-before node gets plugged in, + * adding that new CPU to the right NUMA masks is not sufficient: the + * masks of that CPU's node must also be updated. + */ + if (test_bit(node, sched_numa_onlined_nodes)) + return; + + bitmap_set(sched_numa_onlined_nodes, node, 1); + + for (i = 0; i < sched_domains_numa_levels; i++) { + for (j = 0; j < nr_node_ids; j++) { + if (!node_online(j) || node == j) + continue; + + if (node_distance(j, node) > sched_domains_numa_distance[i]) + continue; + + /* Add remote nodes in our masks */ + cpumask_or(sched_domains_numa_masks[i][node], + sched_domains_numa_masks[i][node], + sched_domains_numa_masks[0][j]); + } + } + + /* + * A new node has been brought up, potentially changing the topology + * classification. + * + * Note that this is racy vs any use of sched_numa_topology_type :/ + */ + init_numa_topology_type(); } void sched_domains_numa_masks_set(unsigned int cpu) @@ -1779,8 +1838,14 @@ void sched_domains_numa_masks_set(unsigned int cpu) int node = cpu_to_node(cpu); int i, j; + __sched_domains_numa_masks_set(node); + for (i = 0; i < sched_domains_numa_levels; i++) { for (j = 0; j < nr_node_ids; j++) { + if (!node_online(j)) + continue; + + /* Set ourselves in the remote node's masks */ if (node_distance(j, node) <= sched_domains_numa_distance[i]) cpumask_set_cpu(cpu, sched_domains_numa_masks[i][j]); } -- 2.30.2