From patchwork Sat Aug 19 14:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62B0AEE4993 for ; Sat, 19 Aug 2023 14:12:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4C4990000C; Sat, 19 Aug 2023 10:12:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BAE03900007; Sat, 19 Aug 2023 10:12:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B2FE90000C; Sat, 19 Aug 2023 10:12:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 87A8C900007 for ; Sat, 19 Aug 2023 10:12:46 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 53FC64042F for ; Sat, 19 Aug 2023 14:12:46 +0000 (UTC) X-FDA: 81141045132.23.315724B Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf15.hostedemail.com (Postfix) with ESMTP id 7D5E8A000F for ; Sat, 19 Aug 2023 14:12:44 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="gc/1EWDc"; spf=pass (imf15.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=yury.norov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692454364; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uf9CTvZgeFnZIxznv1sHeC3yripV+bDt6DFW7z/9P+A=; b=pgQK6wBi/WoxVIJB/DsT9pBLkzrCfpP8IWQMzwuEhWA7ZoJrp6MFDyS83bczTz3jwGts7T egzzinU50JzQgzdnB2Hs/Z3PVoV3wUNZ9cNdLS8JO8pymbHXUlpI/twsyjRKAOBgAUi7KT xfHAd4jjrlEUl+UxbayDrd330azZpX4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454364; a=rsa-sha256; cv=none; b=HJgGWgy0PumL/+QQpvutPfx95SowyWK1ORpUY9bGm/bVdhkTThkoLG/w86Ul2dXi8x7Khj 8HmCKSnBPssD1jc6UKbUK7X/GcHwogYPCXwMmrzC2gzNdOU2Zkt5dlh7M1RSTrmgEZop18 uVNuzipVmebIRFJHpYM26QVHS4Q6CSM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="gc/1EWDc"; spf=pass (imf15.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.128.179 as permitted sender) smtp.mailfrom=yury.norov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-58ca499456dso20024837b3.1 for ; Sat, 19 Aug 2023 07:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454363; x=1693059163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uf9CTvZgeFnZIxznv1sHeC3yripV+bDt6DFW7z/9P+A=; b=gc/1EWDc23XJKVaSsGUTWb76KcCm7bL450mDTtcfp5orDsZ0x+Im2b89o82pkGYPWI 2kKh97M0Pq7E6YI2JQ/rY98jLUI6q+y6Lfk5DxI3rTh/kXImFMu6dvwiSxbbwTFx4DWs BmPmqnq0ztWSsuWtLDuqVl8xesUfwyR/COfFhlO+wFNYUEJbVGZOGxxCyhaqLsZpUhHt psuAlS3iNnxR5tqGB6vLwR8cAkieCaqf8MJCvd4Kd5NQMPMeZf1RaksZoemImF2e5Sps Xq8VtTGwn6+KwuC2/RzFwbmFFxUBOeaU4SX5xY1EWJUuY/hz2lGPWJifS4G6MR1+kdNA ApSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454363; x=1693059163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uf9CTvZgeFnZIxznv1sHeC3yripV+bDt6DFW7z/9P+A=; b=LiG1C3qJg524T5dSqW7Llcc0edGQgDjtNkvsJQc6JCDlzPLeS0C4OQOOPrX9Ny/WGF 93uXCoQgC2rxk1n/tlio/GzVDNFWhC6BYdmEOwNy8WwXPcD1KJz88NxO7oYNaKL0fGXJ JTT2tb9XkeuMaz/aRw376MXTdYufIWQWVj6umVP59XH8a7MOIMyghmTOwVRZvR/Q0BLr 2btvhEbTYktIaYroLp8NF1DU0JudeS1OkDFoH3GO+l6ZYFmPchXZfFEkY9bk6pB7wvHq JoRlPO940z3Y+wxRNFdXvrJxB/hNmGbCY0h88+kAgg2qFpxCMEhhdza93OpPvlW/VUie KUfg== X-Gm-Message-State: AOJu0Yx//ih2VF9J7MWvNAFcV8keZJGbyxZt0PTHJbwmNUSfmaY4OWWd 9STR1RJ3fqIA+IWvay/B9ro= X-Google-Smtp-Source: AGHT+IEoff5wDnqvsze/t8OiCL4lM8ZHmxWRyutUm7aAYNfsUsVv7+2AJf68cb+zqoIwdne80+wp6A== X-Received: by 2002:a0d:eb8f:0:b0:589:c2fe:2afb with SMTP id u137-20020a0deb8f000000b00589c2fe2afbmr2161158ywe.30.1692454363496; Sat, 19 Aug 2023 07:12:43 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id g20-20020a0ce4d4000000b0063d245c00b5sm1482645qvm.0.2023.08.19.07.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:43 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Yury Norov , Ingo Molnar , Peter Zijlstra , Andrew Morton , Ben Segall , Daniel Bristot de Oliveira , Dietmar Eggemann , Jacob Keller , Jakub Kicinski , Juri Lelli , Mel Gorman , Steven Rostedt , Tariq Toukan , Valentin Schneider , Vincent Guittot , shiju.jose@huawei.com, jonathan.cameron@huawei.com, prime.zeng@huawei.com, linuxarm@huawei.com, yangyicong@hisilicon.com, Andy Shevchenko , Rasmus Villemoes Subject: [PATCH v2 1/6] numa: generalize numa_map_to_online_node() Date: Sat, 19 Aug 2023 07:12:33 -0700 Message-Id: <20230819141239.287290-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230819141239.287290-1-yury.norov@gmail.com> References: <20230819141239.287290-1-yury.norov@gmail.com> MIME-Version: 1.0 X-Stat-Signature: 3nzs3hxutfem1t88e6j9f9r7iddybi7m X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7D5E8A000F X-Rspam-User: X-HE-Tag: 1692454364-948676 X-HE-Meta: U2FsdGVkX19Too1XjVOsqTURAqQz7ZaBvj9kGMQooPzkcTDusrk5zUciFQRTy3NiFD8bAGtF7h662xhDvIu22AlDWaZBOyLv7G3DMBrdyPd0wBWWkAbRnL0duGrft6YpwCfjUCRAW1XhSTOmMH3BZs3S7eLZ2tt5dSKOTdBNEC4dAM97m1DM5oiHzdkCRpbCzj6wRUHusRoYYsAtSpKXTmd1wc7/Ot+7hqf7fACWyUkVK+le38nFXIdN5x30Trx3obcyWqUlXd/SMLK+XuQfj11s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5sH249YWv5ItO1o18I8Ff4pgUYtPpjz3R6WKxReIgXcu+vbd1QR+q4vEKE8B0ylFAO76Af57mAwmlP03Lf+ZKUl/RICg6ltHzM2aL6LjstpNSsbFc5TDGWyWpq4VYVSP4EaaRWAAniIcU8zZvShfwpdazdI03ojSI+DrYndFdHan4SCA0aBuPN7QYv/uzv+7jE7g5rON7ngLSKqqJMUD0ckIGLaZc8euo3BXbATztd6/IvZ0Cve0gc5Zsp5YveA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The function in fact searches the nearest node for a given one, based on a N_ONLINE state. This is a common pattern to search for a nearest node. This patch converts numa_map_to_online_node() to numa_nearest_node() so that others won't need to opencode the logic. Signed-off-by: Yury Norov --- include/linux/numa.h | 7 +++++-- mm/mempolicy.c | 18 +++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/linux/numa.h b/include/linux/numa.h index 59df211d051f..fb30a42f0700 100644 --- a/include/linux/numa.h +++ b/include/linux/numa.h @@ -25,7 +25,7 @@ #include /* Generic implementation available */ -int numa_map_to_online_node(int node); +int numa_nearest_node(int node, unsigned int state); #ifndef memory_add_physaddr_to_nid static inline int memory_add_physaddr_to_nid(u64 start) @@ -44,10 +44,11 @@ static inline int phys_to_target_node(u64 start) } #endif #else /* !CONFIG_NUMA */ -static inline int numa_map_to_online_node(int node) +static inline int numa_nearest_node(int node, unsigned int state) { return NUMA_NO_NODE; } + static inline int memory_add_physaddr_to_nid(u64 start) { return 0; @@ -58,6 +59,8 @@ static inline int phys_to_target_node(u64 start) } #endif +#define numa_map_to_online_node(node) numa_nearest_node(node, N_ONLINE) + #ifdef CONFIG_HAVE_ARCH_NODE_DEV_GROUP extern const struct attribute_group arch_node_dev_group; #endif diff --git a/mm/mempolicy.c b/mm/mempolicy.c index c53f8beeb507..0fc9a3b1d765 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -131,22 +131,26 @@ static struct mempolicy default_policy = { static struct mempolicy preferred_node_policy[MAX_NUMNODES]; /** - * numa_map_to_online_node - Find closest online node + * numa_nearest_node - Find nearest node by state * @node: Node id to start the search + * @state: State to filter the search * - * Lookup the next closest node by distance if @nid is not online. + * Lookup the closest node by distance if @nid is not in state. * - * Return: this @node if it is online, otherwise the closest node by distance + * Return: this @node if it is in state, otherwise the closest node by distance */ -int numa_map_to_online_node(int node) +int numa_nearest_node(int node, unsigned int state) { int min_dist = INT_MAX, dist, n, min_node; - if (node == NUMA_NO_NODE || node_online(node)) + if (state >= NR_NODE_STATES) + return -EINVAL; + + if (node == NUMA_NO_NODE || node_state(node, state)) return node; min_node = node; - for_each_online_node(n) { + for_each_node_state(n, state) { dist = node_distance(node, n); if (dist < min_dist) { min_dist = dist; @@ -156,7 +160,7 @@ int numa_map_to_online_node(int node) return min_node; } -EXPORT_SYMBOL_GPL(numa_map_to_online_node); +EXPORT_SYMBOL_GPL(numa_nearest_node); struct mempolicy *get_task_policy(struct task_struct *p) {