From patchwork Thu Aug 10 16:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13349707 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 6178FC04A6A for ; Thu, 10 Aug 2023 16:24:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1B5D6B0078; Thu, 10 Aug 2023 12:24:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CC366B007B; Thu, 10 Aug 2023 12:24:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86C946B007D; Thu, 10 Aug 2023 12:24:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7869B6B0078 for ; Thu, 10 Aug 2023 12:24:53 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 297351610B5 for ; Thu, 10 Aug 2023 16:24:49 +0000 (UTC) X-FDA: 81108718866.05.0B84A59 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf28.hostedemail.com (Postfix) with ESMTP id 099FAC0008 for ; Thu, 10 Aug 2023 16:24:50 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=XFsFzQqd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691684691; 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=Nt6CR9HHeK7zgBz6fcScWFIY0NBszh7vNKMQXcDtos0=; b=WTDS+7jMU3KUli3KDjEzWLrqahM1jEP0AdFqO5XCvfKO/xFnFYRlF8kJ9Hoejta+d+RCPh DbRXGXIPRKhmBWPvttsVqclXzKYF0wfj22QiGlHHK2CASPwjqsosPIBNAk6VzJjLfTRWWr UesHxiGyaaLB4WQHoQfPmRepYKxNWwo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=XFsFzQqd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691684691; a=rsa-sha256; cv=none; b=70mPhbHUIy6JAiIBg5IoWC0R+cZqoan9xHGGTKE0Qu6gnzB1XhVJJVpelayczt5tN0HQ4i mK1BE1ZOdOOaeyNRUDAHjmTwxfGU6tiLuT6qjkLXTRlSEoo0eNl8E/rvE0rTM00IyCGqR6 xbB1u9MQISQ6+z85DKT52ODxZap/49k= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-686b9964ae2so841247b3a.3 for ; Thu, 10 Aug 2023 09:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691684690; x=1692289490; 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=Nt6CR9HHeK7zgBz6fcScWFIY0NBszh7vNKMQXcDtos0=; b=XFsFzQqdaTaPQRn6vyEKmgGKISYvFL/a6YMDa77xCoXUJFV6954HgACo6As6lTmO69 ZKjDlc1V8S38EIFNwQ0yt7lx8Z747kn6RUFY4Q5T9mQSdTsnHof2DwQo90tMjIUhcmhF 1NhyZ+FgbibFcbOArCPbbApw3NYcJ4Vrut4/yslOdF0A4ayO1+QkunBxsDzw0LkGKSKx mQ+LFHEM/UbfAFr4g/ODj6M2NkfxFAisnT6/viOipN9H1YfSFKNeqk2mG0glgsX+ERvC b7qSUha5wggKGIAq/HTrx7uiVRJD5SS5OTzVVL1sKQOUZEaeG1gNeiU/HMRGYAp8JkJg fLBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691684690; x=1692289490; 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=Nt6CR9HHeK7zgBz6fcScWFIY0NBszh7vNKMQXcDtos0=; b=ZJEzGusL9Hy32kDdYUNFS7Xir6k2B7hvPK+8Oeqy0CmCTrLOWT3awFUWxyI/0eASoK YERAgK6jvqIcHmPg+ZfuebW29kPALr76jlDW0EVvwScGBaap2CU7GK8AtVFj2CXpNsIg j15hZaDiR3Q9dLVAjn/ZlW/WExzx5EV2IZwZq9DVMFJMx06ajLia++klxkyntHiRSLAf Tv99Q8CEPLpUEulx+RtrZ7uM/Upbdj1emQfnCx7oZlXOQXdftQSzCjHatpOjWi8GN8MN M50ouN8/XdeeqtquvofId1IVj6c9Oq6egPy/YfHRU6W9q4fBHhIgtZTbtHaAeGMJqSPw Nvvg== X-Gm-Message-State: AOJu0YzeS4ikYfpfmg9GbhcFLOgCSpReXgY2pNQIaKzDoCZ982QZKVI2 G7WHrn/dYVZFi9gkFXgI7KU= X-Google-Smtp-Source: AGHT+IF+HSKdTxdkxlmBxL9la1pCFwMfvcL9kLyLQbU13M/krB/0NdbxKsUiSjtnGTzzM/pJoXXx/A== X-Received: by 2002:a05:6a21:3e0a:b0:13a:fa9e:787b with SMTP id bk10-20020a056a213e0a00b0013afa9e787bmr2366502pzc.12.1691684689654; Thu, 10 Aug 2023 09:24:49 -0700 (PDT) Received: from localhost ([216.228.127.129]) by smtp.gmail.com with ESMTPSA id l6-20020a62be06000000b0066f37665a63sm1724928pff.73.2023.08.10.09.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:24:49 -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 , Peter Lafreniere , 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 1/4] numa: generalize numa_map_to_online_node() Date: Thu, 10 Aug 2023 09:24:39 -0700 Message-Id: <20230810162442.9863-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230810162442.9863-1-yury.norov@gmail.com> References: <20230810162442.9863-1-yury.norov@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 766gic4um64gjtc8hgczjxpdmxnwk7su X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 099FAC0008 X-HE-Tag: 1691684690-907769 X-HE-Meta: U2FsdGVkX1+TNyGLn3xxsce8Tn7BXXWm0UgCMAxdtHh8bXAk1FuBvi2PydhoOxJEuUCB4MDH5QLDEqtizZ8G2MQs10rIzQ31KyvN57WNIUJMO4E6MDwFTK0/fGQLWbJ5axTjsfOpCu5KSGYD7UUOTDJMvhPniKOr7zutogNLZLbEfhM+iJc0gjxEcZyC6rnpPY4QnwPfOQb4ZmItIsXss0LWl62MgEJ/BM5p654Rv2cq3KZmqjpzOCKuIDH3bpZxco7Wa585y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jgCb2lApNUEd3hFG9G6r89iYSO5n/N8kN7zX+JDsPNQ7HostHmsdquwTyNciphQlIaPebi8Qs2u+SXmd1tUGQV3rg5h9YVvzJSkfp1hRnjOYOxpL0LWtRDMcIUeg7WHYs9LX8nMeK9Ibl3eH4yYjiY19E7L3ea4mVqKr0iAB4krPHNxAssYg6at1fAjKHvGTfIsZXSKZZ89NxzFRSuNm2DQpkztG5MRpk+SZqAiasWwsRh47weB9WKkqIePw== 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 is in fact searches for 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(node) to numa_nearest_node(node, state), so that others won't need opencode the logic. The following patches apply it where applicable. 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..db74dd957d2c 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) {