Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp419733ybx; Mon, 4 Nov 2019 23:04:04 -0800 (PST) X-Google-Smtp-Source: APXvYqyhtzoP/Bj01a7kJWMjK6gTwE5t6ilaHzbrymIUg0kwRVY3MDElVyraSG/aYdcJ9piD1rmE X-Received: by 2002:a17:906:e82:: with SMTP id p2mr27535255ejf.237.1572937444099; Mon, 04 Nov 2019 23:04:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572937444; cv=none; d=google.com; s=arc-20160816; b=MX9AeDhJlVS2CK4MTvxFgG4sd5LkjZ5lK20PnANp2gywPJfqJc2OB1udnK229PiqkA 3xngHnG9dv6tCQ1iratjBn0j/tWh71IRPfzncuvv1sKtIbFQp5nq8YCRGDxGj62oOC3l TVHp/euEJzuUcDfY6IKHZmjtnhWhO6ytB7k3cmuBi+8UrfF8T93EWlIS7lGEe0UphKtB u4fJ0+ZJ9g0/TCSYOnirvuDCtN0ZaxVzcpwRM9kTynpF5JZB2Dtr7dIFLbE71bCbjNQS ytEKIMgirwP5EcTdRdm6vDxY6BTLiawGNKUnPLIK/vWzw/xWRJSEzBvh9delbo/iV+cB gT1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=soL8g5VRzd/HpbiYRhg8XA47YOxbg3bQ6vJLM1TdHbA=; b=cK5iwitess7sqDREd8dnESnYblJ0lRvZuAnwGK1qY/owZop2l6B1mhVAmY3TWNXlq7 WjJBZxl5ltXfbLys2ssY0gINX5yKUELKlpt5vzI2ozUX4/UN2M/mTrQCYQx2skTze/dJ meR5w1R3VNKtgZv3rTlefh02lBUJRancpiS9xIURB1XghjjtAmUEKjiUujO9ALLNj0x6 d9zld82FL8YHX3+6V7mCgqLbP/8+3YCNMMvk09cYHikBTbMlEoZi/gtUGJiV19RzcsT8 Zv32b3Hvh1cAEezuLNrWnbAWiwiPbpSgXxgpBzfq3pA9Pv6Y4/6MM/vZp5bn/o+DJfmd QXSQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si10483020eda.235.2019.11.04.23.03.38; Mon, 04 Nov 2019 23:04:04 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387663AbfKEHBp (ORCPT + 99 others); Tue, 5 Nov 2019 02:01:45 -0500 Received: from mx2.suse.de ([195.135.220.15]:49548 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387517AbfKEHBp (ORCPT ); Tue, 5 Nov 2019 02:01:45 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 88710AD35; Tue, 5 Nov 2019 07:01:43 +0000 (UTC) Date: Tue, 5 Nov 2019 08:01:41 +0100 From: Michal Hocko To: Shaokun Zhang Cc: linux-kernel@vger.kernel.org, yuqi jin , Andrew Morton , Mike Rapoport , Paul Burton , Michael Ellerman , Anshuman Khandual Subject: Re: [PATCH v2] lib: optimize cpumask_local_spread() Message-ID: <20191105070141.GF22672@dhcp22.suse.cz> References: <1572863268-28585-1-git-send-email-zhangshaokun@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1572863268-28585-1-git-send-email-zhangshaokun@hisilicon.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 [...] > +/** > + * 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). > + int cpu, j, id; -- Michal Hocko SUSE Labs