Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1501603ybx; Tue, 5 Nov 2019 17:35:09 -0800 (PST) X-Google-Smtp-Source: APXvYqx6CLfk2DQdewHXCQ3cnV651wVcRDfqWGgJe6YH9bC9waLlOUdFZYmeNmcqtBKugXxdproF X-Received: by 2002:a50:a2c5:: with SMTP id 63mr15928284edm.48.1573004109858; Tue, 05 Nov 2019 17:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573004109; cv=none; d=google.com; s=arc-20160816; b=I9IKBt4XguuY7jUpqhYlrzgURn1uHRa19GV9M9j/YKld6huFAZrRmxiuFOUKMEYb4M kcb3PJXPV6rA6NM7kvf8mzua3QhQMWysaougiRQd/hyVK46/2RHhLZbFhWm2ghmXxA/T jMa9NC/pl/Ebnjdh17E0XQi5yU4XCMwcUBOQJhfCm+WyT1tswMAuqumYf5rjDdAT3DyR kYszEbnb2XBt0jrSPB+3zXPdRud0KRt8PntLYUifZpZMrLDhKnEkwCBsiVZ5i1nxN3ze W8fuM+vd6Tj9NCXEWXGIOZnaWWwykwq5EQ+sjbZPHrSlSbt9b3BSbWnOxmw0wVYxZW4b X5SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9QoV5EYyjWPgqqJpOihx5ArhIRXvPqOTFzvfRnovAwo=; b=emlBS/slW16ksjZPkDv/abbEpkKhtTutXuqqfkvG7G8N8GHg6P0AY73OhUMb/cpoVk /f/dbt0fqWuh1cYwnaDWBG47/LMDBI9WSzuB2I1SkCtSxvsqdBx1DnwNjLjMVif+ZsNj FyeBey0M4Ly99WY7F+WioV5t/QnpaOtbAUD7i2VqeBIWPOh8p6Ys9rLMDdsE+N0/Pv9f hpJ6LWtgf15aKCi0Iyn3YEuvo9Aew/er+dYgW5YEcC4Gytk+PrMxoyj0gAZCPFaIeha5 BmBYfvYJ5JdHu+BeFWV2/sbEunFMDRPYYUKEKwg5UlRnHQ3XL1+qiyBKdPprbfhd5G+Q gNdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=exSWQAkq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si1724637ejf.345.2019.11.05.17.34.43; Tue, 05 Nov 2019 17:35:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=exSWQAkq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730683AbfKFBeC (ORCPT + 99 others); Tue, 5 Nov 2019 20:34:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:45476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730231AbfKFBeB (ORCPT ); Tue, 5 Nov 2019 20:34:01 -0500 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5E3A521A49; Wed, 6 Nov 2019 01:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573004040; bh=XMuTrxExlNXwc59KHpMaJLkEvPjFjpqC/tjBExf6rlI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=exSWQAkqaw1wfaoYHAe0SJ8QkilzGB6Vbt9yPlwgg2j32HPGrJ3EvJCIM1uXkH2r4 bGCkYKm4qJp11OWIm0RK1uwj84heN3lfE6dCnLC24nCgcJxbb1MjDFucTH9eOhk24j zIfzyBNCbi9T96b/qsxFnRUFa5d8rPLzGYsSCGmI= Date: Tue, 5 Nov 2019 17:33:59 -0800 From: Andrew Morton To: Michal Hocko Cc: Shaokun Zhang , linux-kernel@vger.kernel.org, yuqi jin , Mike Rapoport , Paul Burton , Michael Ellerman , Anshuman Khandual Subject: Re: [PATCH v2] lib: optimize cpumask_local_spread() Message-Id: <20191105173359.39052327cf221d9c4b26b783@linux-foundation.org> In-Reply-To: <20191105070141.GF22672@dhcp22.suse.cz> References: <1572863268-28585-1-git-send-email-zhangshaokun@hisilicon.com> <20191105070141.GF22672@dhcp22.suse.cz> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 5 Nov 2019 08:01:41 +0100 Michal Hocko wrote: > On Mon 04-11-19 18:27:48, Shaokun Zhang wrote: > > From: yuqi jin > > > > In the multi-processor and NUMA system, I/O device may have many numa > > nodes belonging to multiple cpus. When we get a local numa, it is > > better to find the node closest to the local numa node, instead > > of choosing any online cpu immediately. > > > > For the current code, it only considers the local NUMA node and it > > doesn't compute the distances between different NUMA nodes for the > > non-local NUMA nodes. Let's optimize it and find the nearest node > > through NUMA distance. The performance will be better if it return > > the nearest node than the random node. > > Numbers please The changelog had : When Parameter Server workload is tested using NIC device on Huawei : Kunpeng 920 SoC: : Without the patch, the performance is 22W QPS; : Added this patch, the performance become better and it is 26W QPS. > [...] > > +/** > > + * cpumask_local_spread - select the i'th cpu with local numa cpu's first > > + * @i: index number > > + * @node: local numa_node > > + * > > + * This function selects an online CPU according to a numa aware policy; > > + * local cpus are returned first, followed by the nearest non-local ones, > > + * then it wraps around. > > + * > > + * It's not very efficient, but useful for setup. > > + */ > > +unsigned int cpumask_local_spread(unsigned int i, int node) > > +{ > > + int node_dist[MAX_NUMNODES] = {0}; > > + bool used[MAX_NUMNODES] = {0}; > > Ugh. This might be a lot of stack space. Some distro kernels use large > NODE_SHIFT (e.g 10 so this would be 4kB of stack space just for the > node_dist). Yes, that's big. From a quick peek I suspect we could get by using an array of unsigned shorts here but that might be fragile over time even if it works now? Perhaps we could make it a statically allocated array and protect the entire thing with a spin_lock_irqsave()? It's not a frequently called function.