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) { From patchwork Sat Aug 19 14:12:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358635 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 99129EE49A8 for ; Sat, 19 Aug 2023 14:12:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08CE190000E; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0155C900007; Sat, 19 Aug 2023 10:12:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD2BF90000E; Sat, 19 Aug 2023 10:12:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C2E2F900007 for ; Sat, 19 Aug 2023 10:12:48 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8458BA08E4 for ; Sat, 19 Aug 2023 14:12:48 +0000 (UTC) X-FDA: 81141045216.16.6C67C00 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf12.hostedemail.com (Postfix) with ESMTP id 9E33540008 for ; Sat, 19 Aug 2023 14:12:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ZfnvpAJg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.42 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=1692454365; 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=QFVxXxStyebQd2+5mwYh1o0joRC2SclF2vbhFRruGlE=; b=MZ3mQEb1Afsj4FwfiF3/i9SSHmrr5qTfSBFkN8MrudPOdJdjP2U9CtRwSpiSl2oyteDQzQ 5TaivsmdpQZMurB6OXWZus6BGc9a6lwKio+EWpy8Tfk7kUahiPe3IEMhzEyoOIt3lTk//Y +zeam6Qlm6YDYIOfY5yiaY1+Fvi2Jlg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=ZfnvpAJg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454365; a=rsa-sha256; cv=none; b=caI7MBTkvaWpCkJUx6hh/EbYDL+tBone+HFg+JUhiqGwY4LQDidDI9+0mkdnwR202/gEQM G0QQMoZVp/P2lBrZ3Io0eEpWoTHJJGFIzjhDVdQMxw1pWs4IiU6QcjO83sd1TWGOkdE/8t 5Q8cW8Al9R6ME7lZgAdFeC/yn+VMnr8= Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-64f383be0d4so146496d6.3 for ; Sat, 19 Aug 2023 07:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454365; x=1693059165; 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=QFVxXxStyebQd2+5mwYh1o0joRC2SclF2vbhFRruGlE=; b=ZfnvpAJgMbfQ3CZw7R7tBTIb0/CjcaNSgcbF2GnwC1IHBGukLBv2YpA5Xks+Msu2TA uMhZWngetDzl4ElT+MpmnGvhNpcECn0iQeDQaf7+z5ohObKr5KveEms6lREnz0pkluIU lbhrThEQrUqq6005xo225pWxTJLTL7a5laff9rT5866P9fbRYXvRztLy4FgY5FGg/NNs 0+QPT5LsThOBOcRtvSSNj3gmKBcKzSr9A+7gOARHUk+/0caenQwXXwwIjYV4cA1ZWQsh TniAp6hta2j/wAcjBcjfdlP6BU1uXdT2cSDxOe10NQwQoEvi2oJ38UOEwKOB6im0XK+m //JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454365; x=1693059165; 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=QFVxXxStyebQd2+5mwYh1o0joRC2SclF2vbhFRruGlE=; b=ZSQA9FF4JFHenNSsLczxKRSKZ+7raqWHzncRS7+7QPrw8xH7wVeXZNLEDWM+vYO6mj YpaMpZlWD9Ns1/SBMqRaTtrL+G1iZnEOpmVb7OrSGtQFLabVynQWX7KEOsl9WBmnhP7Y DVtIWZFaMY7NHft8hifIMLAEg/rNq7SNJhxBPaE/7Oh8i4MHI77aKIEOm/VOHYV7Npk3 kPyTN5QPG4cxfEsXFqBBUxtfoqc3y43FsIeeQvZmFtQNSZV6o4mGiEQa9hcSE+4pClqY hZ75v0rGZIja2z4w9OzHddol4htOAKijrgaiU+tLSVQZ1a7O7NxgYgd/hyzcPEw0mdaU pb/g== X-Gm-Message-State: AOJu0YxKyNwk4SjxRjIjnFJ6L4JTO3ICnho4IqtEByWJlSrCOy4hdgGO d9Du7t5yPWZHlkWZD2frw5k= X-Google-Smtp-Source: AGHT+IFUX8eTyssulPQya93DY8TjvT45WssAgMpP4ifh6tDP9KAQSGhQl+ktG/q4W6s+7sBb8lbdUw== X-Received: by 2002:a0c:8e83:0:b0:640:5beb:d89d with SMTP id x3-20020a0c8e83000000b006405bebd89dmr2415714qvb.40.1692454364731; Sat, 19 Aug 2023 07:12:44 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id h16-20020a0cab10000000b0064906cfe430sm1473236qvb.135.2023.08.19.07.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:44 -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 2/6] sched/fair: fix opencoded numa_nearest_node() Date: Sat, 19 Aug 2023 07:12:34 -0700 Message-Id: <20230819141239.287290-3-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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9E33540008 X-Stat-Signature: g4iksokq3zkqs87mxyz4qk91zjcsf667 X-Rspam-User: X-HE-Tag: 1692454365-183205 X-HE-Meta: U2FsdGVkX1+USYujpecvlx5dH0tg/MfKRH175yz7B69aHUFb0TV8lfcs/e8AJXyL3nmHJ0l77HKn0L1oEUgtuGaf25D7HdmiMuQm5r2M2xFy57EA4g3el3ecsbAsJT1dpY0keumMN1Z5oeK1i1xc5dXJ1m+VGnKsQAXM+NwPPfELlreXQt+Ur0Ckxq9lVHcQpJeo2braa0GGAPy686W+QvWyykBvxzgSIUDEbmGoPcOdoJpmV8wKAFt/9hrH2fddhJYxYlgcq8JOqetAeP6S0CU2DcNK93u876KnMOgLDXTzlHAQ2VHElrVreLmqzTCH0R5HERmJZr0/k8TBU73sPpmzQiYTPeC2t/R3MYU7IwoFPsYvyRK5gYrmQxnX5WdsQxrQo050uTwOD10kPwHsmMVEuIxPi61+5Xxmsp3A2xAyCNVXf7LFkjKacNCs6ruHG0aFpREjmgSld9vaIJ5wcGzcpHrHZGjyrSTMuwaM/8d2LtNRC0Wr88qUIep23CEPaLJySgwNbIVqk72GI0aP9lEzRUIW+Zljfb2qVQY0XR4V59jI64VOM+/9iZjDFijaliK3wJPKY4IEwS58aR8rEOA1EIUBfjfkyyf5XuoXdhKtoPk16JQ3KmVtHt2voI89v4asp6SbzE1u19sr1vR5c4YSwVXJUeGDlmV6RVEVeRR592+83VE8XHYEvRpp6L75vCCyk1EiJFYXiibojcpv0J/pE9Z+7PUklQAD8amiCx0rVHKgyOsurzaPLJ59GUr6EvLwxvEj4GY72nHsEASwZLmDNKzqZCt89EK45RWQgyRmJuPKebRy4p3G+Ld0Q0mBZrIjp/uNjhYIOLtba5fcjC10c4i3bln9khwzFejHHuJJeGJOVlRs1xiwONUAqGujQtPgG1CmY/O43x/tYw/yQXQA1OtXmJzTBA9YYf8cAU6BR1b+OydP/DcfTZqUkUJgUB857fCXOp9k9FuCwDZ D3SQ6Gss 6gUhBES+Mgq5rlD0MGZND4eszpRIDD7BCp9491JdR98jgXrUoL/IxJF26+fJ2P5hRhUgpIINuwv52VYt65hTnmGUVvSPG7y17kGjWPhh38SXaJfFeI9DFj6Uua/0VRACBqNGIVlVzV3sd0UyAm6imu5I1mOCRzok7i2vzQaNlQHKVKisdWikn1W8aVWV6px/2allLUpsmDkn8uznMgsCZxiYThIBHtF00Qxm857XWAmSatP+6Q1AHsLzcdBqODex32B8bCTFQcIcHI6woI0GlRQiJJs1VIy2s7pLoumQgJbx93OmNLQQiruhyloCsPvrI0QUrJRlqmZUkqf9eHFnRNBhkhojd1gtkXO6WSqbiqfAxi6KIcP9o9OArCOk+WT1u49ruahpdD/9ojlKoGVIn5F7VmYatCAUvJJ3VMKiy26yzOgpCFmFnJ5f9ZvL7K4t3GV8Iz839mO+IjQRAbCZBAu7ZmP/2WIqiGZQ8wWTO2z0ItOgoaYpuhe28cHo61H1O6zi+mknv6ejsrKdKNrCr093yLYqYYQ3epB8+MsNprIHNM4hVAEBcTqnusCMvhuYrEeVsALJkEL/L72tPs3CUi2j68A== 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: task_numa_placement() searches for a nearest node to migrate by calling for_each_node_state(). Now that we have numa_nearest_node(), switch to using it. Signed-off-by: Yury Norov --- kernel/sched/fair.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b3e25be58e2b..e7b7cf87937b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2645,19 +2645,7 @@ static void task_numa_placement(struct task_struct *p) } /* Cannot migrate task to CPU-less node */ - if (max_nid != NUMA_NO_NODE && !node_state(max_nid, N_CPU)) { - int near_nid = max_nid; - int distance, near_distance = INT_MAX; - - for_each_node_state(nid, N_CPU) { - distance = node_distance(max_nid, nid); - if (distance < near_distance) { - near_nid = nid; - near_distance = distance; - } - } - max_nid = near_nid; - } + max_nid = numa_nearest_node(max_nid, N_CPU); if (ng) { numa_group_count_active_nodes(ng); From patchwork Sat Aug 19 14:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358637 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 29A91EE4993 for ; Sat, 19 Aug 2023 14:12:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 596A0900007; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B4EF900018; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 127DC900007; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D5342900011 for ; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AF0E61A0933 for ; Sat, 19 Aug 2023 14:12:49 +0000 (UTC) X-FDA: 81141045258.21.9064D8A Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by imf28.hostedemail.com (Postfix) with ESMTP id E5BEBC000E for ; Sat, 19 Aug 2023 14:12:46 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=YHzUfnhp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.167.177 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=1692454366; 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=igV7SREietQ24odTG+SOK9M1ry44nQsh1uk2kgh31uI=; b=euuTHzOcZdrphM4OPRpvITG3/z0m6TJjqN5WRh94uJpieTm5uSPPvbtXn/urLQHyjQYPVP PL/fQIy9mUGsVE4WxfOVOaHjvg7YMnND4bpKTis8EclWU0DOXKm1+YrFwkjwNikxUqUf0T mbBjEVHF5JvbgI69ISSiajluLxSFXLk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=YHzUfnhp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.167.177 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454366; a=rsa-sha256; cv=none; b=GaZeCUkFgVMDpW6STqiZ4OSR9xAz9NUaQS/BNhfgAfbV7sVAuYKNoiTPUVF7x9FjaSAGq/ O8ry/r4skXAY5+tpmxWEcl7CvA/Z/MnQ9rtsBW7m81JU3mjws6JGThKII725NYejtk3LNi 5N8tKX9VdxfLkEgI+MNJ+LhXXkR8VKI= Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3a7d4030621so1171264b6e.3 for ; Sat, 19 Aug 2023 07:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454366; x=1693059166; 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=igV7SREietQ24odTG+SOK9M1ry44nQsh1uk2kgh31uI=; b=YHzUfnhp2ULvFItZJ3o9nXuTnirno2N6SDjG259/ov8RQGn1YKf8iAafsV/TZmzM9G +JnpUr2gmWptKe9x+JSvawiBnbrHhC0ttUD2okQ/G1fkWvTO+q+8WWnRri6umDq+AeyL uI0r086HHFLAzxmjNMoczkq3+6neOsKWrv7/U+R0BktdT2UnHnqO2MbZ02/Sv0a3y64w uVF4L/O5aitTTPQbj/ImVhoNslyY90UeKiLJpC1hbba+hqARYZbe+jJxR1t91g/UGIRk cj0t8on3AEkxlEMjodaPmpu584rPPq3QYwFMKZXzjDyKDOj1sI+dorfQbPfPplhlCTXI V2Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454366; x=1693059166; 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=igV7SREietQ24odTG+SOK9M1ry44nQsh1uk2kgh31uI=; b=Uoq0DxTDM3YVitOg/TJqCtrVIneQr7KqLjgnQCvgUHf9XDF9ataXi6vA7a9j74ox+9 rnF/5Esp5hH9Ws1J68SsZxSy3zHullLbX/r1Ob6ZyGGyvNKSqn2hMiYqTnd3fTfdQ743 Fi8DPTiJXemIcmpzZk3O/pGHaOWrY6kk7nFkuqj7HEvk8Lq08MPRMogvwQ2LhWHh2zuO pfzNQparlGxGKObCjwH1EBK7sCCkD8W9Oc4nmN5k0w2WIiYcCnbv3nMuPBtoqmFZ4a5M 0PxEOzoRXHkayGxgXg47oioFoJN0K7IkI0CyhnbIdVYFW+1eoJF9LrLQKizjrKHmd1zw eBOQ== X-Gm-Message-State: AOJu0YyhoA4SBEStBhctU0NfOlCd43KWPuCCeg6ZJcEoHGBDcfnGQJoA WLp+95/EUyAjZEiSqHrygmg= X-Google-Smtp-Source: AGHT+IHSqqEDImaL7LnYyBklQgJU18/Wzpv/z+7QriCsXPpQMlpRzLKW65D8myoE3i10msbA9KqjvA== X-Received: by 2002:a05:6358:e486:b0:135:499b:a68c with SMTP id by6-20020a056358e48600b00135499ba68cmr488750rwb.8.1692454365835; Sat, 19 Aug 2023 07:12:45 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id r11-20020a0ccc0b000000b00631fea4d5bcsm1466439qvk.95.2023.08.19.07.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:45 -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 , Guenter Roeck Subject: [PATCH v2 3/6] sched: fix sched_numa_find_nth_cpu() in CPU-less case Date: Sat, 19 Aug 2023 07:12:35 -0700 Message-Id: <20230819141239.287290-4-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-Rspamd-Queue-Id: E5BEBC000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: eid6b8up7edn9gppeogym9qrqnhiyh44 X-HE-Tag: 1692454366-71449 X-HE-Meta: U2FsdGVkX1/7md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ynoLFgSysk2Qp16Sn0zClBJNjV/XuzDKQRKQ/PPfPXSLBbnngFNnrmOdcDm5jbaWx8RNjaOeJLe7PDpip4oyXG1hRZEPXyQFlzgmWlJFINSHZAMTFJPBRFD5gfFgSeDkaKyx0fIHlu5af9PfRAWiGEiMq7L68W9kabdFIDamd6Vcdbmcqpk9pFjNPdy5wfQeeJgqis7XFOOnsCMEg1QwnsI13vn25XzSQNUGwTKVwPnb+IPTnLSQ6nHP84zbLt5CYl1ADEGCzWldGaDSqYp3B+xknYUuEv+ZMFg79LMogDuLiaC8OITAznFwSba5ag2dL4VCbvXOWik6U37eexabSIOk/0WVt1wHC1WzbT6b18aUBy+M2AoQlP+eLyhIvoOgW8jkp70Wovfhb/WHtieaGIe2fd7VNDcKXUocVev+VtVNi9EDmy4zU6vj/xvkYmrOKqhcZUiQSGpFdSqkfJQonAlnKauHAj8nCUxNAoqcazuCOJOHgBQI1AXVe8jo2bqO/3VqkYErN4Z4y9xgLhK6MO17MVAV4lZKqwlx+0VDu1E2EMJby8FqMwad++b5OFg4mR30pcustYrJb8rjeT15Zx0VbWBLgigjHU+C3BkoXMCV1C9qRPDbmWSh/kRrMm0uboeUzg42LMUesZWhY+Gr6Cjgv0Z9A3RHvOUYTa8+z/JV/j4DaXrKrNyYFipEg== 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: When the node provided by user is CPU-less, corresponding record in sched_domains_numa_masks is not set. Trying to dereference it in the following code leads to kernel crash. To avoid it, start searching from the nearest node with CPUs. Fixes: cd7f55359c90 ("sched: add sched_numa_find_nth_cpu()") Reported-by: Yicong Yang Closes: https://lore.kernel.org/lkml/CAAH8bW8C5humYnfpW3y5ypwx0E-09A3QxFE1JFzR66v+mO4XfA@mail.gmail.com/T/ Reported-by: Guenter Roeck Closes: https://lore.kernel.org/lkml/ZMHSNQfv39HN068m@yury-ThinkPad/T/#mf6431cb0b7f6f05193c41adeee444bc95bf2b1c4 Signed-off-by: Yury Norov Reviewed-by: Yicong Yang --- kernel/sched/topology.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index d3a3b2646ec4..c6e89afa0d65 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2113,12 +2113,16 @@ static int hop_cmp(const void *a, const void *b) */ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) { - struct __cmp_key k = { .cpus = cpus, .node = node, .cpu = cpu }; + struct __cmp_key k = { .cpus = cpus, .cpu = cpu }; struct cpumask ***hop_masks; int hop, ret = nr_cpu_ids; rcu_read_lock(); + /* CPU-less node entries are uninitialized in sched_domains_numa_masks */ + node = numa_nearest_node(node, N_CPU); + k.node = node; + k.masks = rcu_dereference(sched_domains_numa_masks); if (!k.masks) goto unlock; From patchwork Sat Aug 19 14:12:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358636 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 2B2B2EE4993 for ; Sat, 19 Aug 2023 14:12:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B483900016; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C3B1900011; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E490F900016; Sat, 19 Aug 2023 10:12:49 -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 C704B900007 for ; Sat, 19 Aug 2023 10:12:49 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A687916092C for ; Sat, 19 Aug 2023 14:12:49 +0000 (UTC) X-FDA: 81141045258.20.B8BE4CC Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf12.hostedemail.com (Postfix) with ESMTP id D706340003 for ; Sat, 19 Aug 2023 14:12:47 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=DG6joiC2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.48 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=1692454367; 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=SmmjHmVn6ls0sfUQEL2MtTTuL3JIkk0EADWsp1ssJ1I=; b=L9k3CIBpc8PbewEekrpjM9wSpvaPyNct+frv8DUmeEbZxZYtD5y96m8wvRztlL06DlaSDU afZ8tMzUKKK/LKpdHkg6NvdSIpUhl91eDlpV6Y1AX+AcypZa1wZv0BoQ4pC7XuO5MeZc2U 1FvAz/un+NILAbkmyd6AsWcBEYvgd20= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=DG6joiC2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454367; a=rsa-sha256; cv=none; b=ocs06AQMLDw+WBoMKSH7XqT4AoRan5bi8b1Jp5/sVtBjYUmXnlDZig1zo7SwIf/c+ZCVzO D1nAFoqFSzlmDu8yZ1LHWeCkvTxdNbEy3FiAkwlB83hbzd7xxvmfDyE3gPC4Yj75iU0/Q9 pV6ms4ft5U7vZEPCyW20o9HvBqanWco= Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-64f383be0d4so146586d6.3 for ; Sat, 19 Aug 2023 07:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454367; x=1693059167; 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=SmmjHmVn6ls0sfUQEL2MtTTuL3JIkk0EADWsp1ssJ1I=; b=DG6joiC2Lh32MiV3Hhqxx3JWfQDfDz/+8b0EdnMI1S+h3jh7LlNSk0ZQqNJgRg62Z7 3rlaxuUKCDxday8et0CVelK2WFG3zjQNY2LFZOzuTLwxfBhJqvEfVigb/4QPBMbQcxjU qjqzPnj0LYYPPADAvFTkSkVDZfLtCn1hLjx1jfvoUGGiDN9oLQeTTHtTTmJTcCitifem CKA0GfI3ugT45tKAdlgqZEDA18Rftgam1AdPVf8K6HYQufQ6i7Il64g3uPRSBc+0rc0k wfwnK3RBh06a2KwGVvE7GvgcZQYFOyPzUvnjFYV6Kv+K90LdXhq+3wO3Px4qqG69USp8 cr3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454367; x=1693059167; 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=SmmjHmVn6ls0sfUQEL2MtTTuL3JIkk0EADWsp1ssJ1I=; b=jJPncZP9twfm3Vu9ADbH9DutggrjzeYOxYyrrlNrGBuSNY+xIbr0HttuAmElCDAbUp dUSaiaVMLAbOfsY7Yj96zH3z7HnlqQomPulvNSomEOnJLiifE5+8FazwNo5iavvTF9IH QIfZuLPsjWmnlqmgBTbl1HpFIg9/bERlSZ6qtjyUMkrMz87XY4kmV13lyCDp1ex99BQj dlPYDVlt0ASJK4UpREnp4ux46ZnDxbgf4bfVYm4i2qUhjppainnRVDDxddRh4dK3f764 6J2Tap2THEjxmLBl7uOPXs7+j0/jy+TXPfvN+b5ZM0r+IXLo/RC8xTMLz41WL7ZrshxO xezg== X-Gm-Message-State: AOJu0YyIDKZ9+M79XX3L970gnMvnfy09bvhFRFmN/gtm51xVdYl6Mpk9 DRwYROegrnN84LxwbwS9QHM= X-Google-Smtp-Source: AGHT+IEfRsyy5LserSpARnbs4AMrhHIcl356NFzEZZyieATaLVkGrmSM4un/e4KNH9OAVV4li0xoAg== X-Received: by 2002:a0c:e413:0:b0:64b:997f:5a7e with SMTP id o19-20020a0ce413000000b0064b997f5a7emr2602799qvl.8.1692454366974; Sat, 19 Aug 2023 07:12:46 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id g22-20020a0caad6000000b006262de12a8csm1464891qvb.65.2023.08.19.07.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:46 -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 4/6] sched: fix sched_numa_find_nth_cpu() in non-NUMA case Date: Sat, 19 Aug 2023 07:12:36 -0700 Message-Id: <20230819141239.287290-5-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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D706340003 X-Stat-Signature: hrifbaret7yhqoboo5od39fj7fqq1xja X-Rspam-User: X-HE-Tag: 1692454367-419844 X-HE-Meta: U2FsdGVkX1+RtCfsQ9NbjTtPWnnX6SyLPBygKSz8o4lmG5ERiGTqeFwcREBPeNZuwaYwfA3c3V48RxhkKdsTa3exkoS4IU8gXhHfIIDz5VHURkJ5tfEZ98f0ZUyfiVvyBjuy5jC4BAAmzLzgLRPDiOV3uaN13HE8BqP19UYaba7p8qAuaOLsyypfP31Z6ogdlGdlImeho3SkHt1foi1cd6NelNHUNzWE6MBywOxWHyrntrqSDaBerru+teVVPUk2yYrvkhzCJm7x2kVTqj35RF8fDOQRyXyGU1voY67f+hdY4+63AKESeinNkzTzLsSpomLXu1MW3YMGu48YkJoMyA4Ntek4Paz1j4tTrU1F2gpq+gUqut/MWiXOSVin0g73V477Op1KCC7Wtci580MbMIF5Gpd2UQKZE1KET2UFoEpdJyQ971fpJnFWxAqPbHCenqxuV35tZQv0ZnVTdGnGAE+HwigDgXib/HB8lNchqQ/WhDmrT+/olytMNSXzB4Ux1Gt/DELHHTKuKWm7/X31j15XG+QCRKHpaftWa7HS0L0GSM3i9kecMnvygiTiCY80iKV8QhUPgFA09TWwqH9ohRbOXp6NMcwF0pLn/7eT1ec2g8mSgTwwcSRTW2n46gfY+Yf2vaU60Der/vwOrqZuTlzsA2rq1lKhQIETlKRLvYWQaIEAfd2V5udCEpbHyystxn+tVVK3NI/7pDcZCfrHIMKJU8pozIU0TH/HGE6Qi+x5fBUCYalljp1aujRVctjfHjQNaAgd2oSslCEMxiHntc96lvutHiVOpF5NmhaMX3R3LxKiAlbimDg5cOXvGzwsQONpLmlSAH3X1Sz/i+usrHPa7XCC3jM5xO/WwHpWCR3zCM+hI0rtV/uBkB27s+o2SYJ8tjzjxrC+Z+kSGZVJFiETM75r3SH8iyPkHSunNi6f+WISK8AsaMHYq2oDINmsGUaDEmXMiktjcPdUxVE q90+ql+W micPvD5pWlHIFJBYCCjWtWUWJUadqwOfmoFQJT6xgB/hD3mCBVPnBjKNIwrZVpO8T1cJ/rHvrGDvAW7MKc1Gk4hBL4iOjPVWiFb14XNxa4xT3xUd9ljc5aZWFfXYw28nk3w8mkuf9t7HURuRxCJJaS+lBlXBHTVJGAWg+d/ekSPf4G3x8XVLNMNw7tWvOvUDJSrU7tEbVzcLpr8EKfBAMXlU1C7S9uNnSBcvN/ELS0asNSywJR/QPVJGPiBjsZFdi4H0ZCWgoTs/EUrLdxz/Ftcok7/G1HFaMDZO6JZIFXmGE+5mUfkkNdY+QY/YyEcpjZGMVcUU2eDZ1L6Y2OaM1haID+bPEEOl3yJ6nxIdByxqDvaBssvXLjRFkSoAJ0BAocjCxa3iePlByxFQzRH8CkCzr4PZTJe3deuLKF0ndrPTJiG/BpElJGYH/1szGdb5lnHslXSpx9UnTczXOel6SgfU5p7JqAaW/2XCVAxWMAQLnnAWDDbMSSAJ2Gh/HbvYVqiEMOQ2lHeL9Z6UmlKqMSFnOmg1pTS7zDjWmuWIcVKAxbyWCNezMfVv4UzKnyc/1gHM2wET3GJxu1xNisE/8FFjESw== 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: When CONFIG_NUMA is enabled, sched_numa_find_nth_cpu() searches for a CPU in sched_domains_numa_masks. The masks includes only online CPUs, so effectively offline CPUs are skipped. When CONFIG_NUMA is disabled, the fallback function should be consistent. Fixes: cd7f55359c90 ("sched: add sched_numa_find_nth_cpu()") Signed-off-by: Yury Norov --- include/linux/topology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/topology.h b/include/linux/topology.h index fea32377f7c7..52f5850730b3 100644 --- a/include/linux/topology.h +++ b/include/linux/topology.h @@ -251,7 +251,7 @@ extern const struct cpumask *sched_numa_hop_mask(unsigned int node, unsigned int #else static __always_inline int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) { - return cpumask_nth(cpu, cpus); + return cpumask_nth_and(cpu, cpus, cpu_online_mask); } static inline const struct cpumask * From patchwork Sat Aug 19 14:12:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358638 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 A0DF0EE4993 for ; Sat, 19 Aug 2023 14:12:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 128D2900018; Sat, 19 Aug 2023 10:12:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B2C2900011; Sat, 19 Aug 2023 10:12:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6D6F900018; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C7D7B900011 for ; Sat, 19 Aug 2023 10:12:50 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 984A5A09A4 for ; Sat, 19 Aug 2023 14:12:50 +0000 (UTC) X-FDA: 81141045300.10.998606F Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf27.hostedemail.com (Postfix) with ESMTP id CF67740013 for ; Sat, 19 Aug 2023 14:12:48 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=U7AgRT8E; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.222.169 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=1692454368; 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=Crn5/+8WdRhCgV6i5ssfAVZRKeJzdqL7IL6ctYKnl6U=; b=ArhrtYFhJqOVSutgvvAFAp+8CNKf7tpBncUfSe+QuHVSPq05e1PDFEHRlmZtIRfYZ3Q/Qa 3BbnrRg3xebTwTDQSCye5+k7uNqFgo7eHjg9Bw17d6EiidlQ7Igpy9p++bft6RURcKe1ep DVyYAxeANSwN3wA7DEYavb4HvinBfyI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=U7AgRT8E; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.222.169 as permitted sender) smtp.mailfrom=yury.norov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454368; a=rsa-sha256; cv=none; b=aqt7vbYUx/+p83q34231pBbRnxdjmfCGuTHe6zDVagcbvi0JmO4ipUmzVcC0YQ9K1Mo8AA D+ROxvHzda/l7Qx8kPojtUD5I7W7K2XNuHFR1tAXWR8T8ciMpdJs86Tq8dCpAHfg5P/35V G/fzdhroFrYaiFBTbWQWHcx+7IU3/KQ= Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-76d9a79e2fdso39459185a.1 for ; Sat, 19 Aug 2023 07:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454368; x=1693059168; 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=Crn5/+8WdRhCgV6i5ssfAVZRKeJzdqL7IL6ctYKnl6U=; b=U7AgRT8Ejxxl/VEdRwqDG1ENqN4QGxU6q+qxz0PKZpU9PSYvv4hGm/LQQLGxOrW1gJ CWLHmh7bBtOZQEIirnGLdBTRwYf5ThOF0JN0i91aMcJOkDKLZxhdvJ3WZr20h2BmTR/b icRcsHm5yrdnjCN64NRgjkhAgWD8MzAJiawtCyEU8rZpGuPTFn7dVM43FYHmSDsEpWgH WeYgmoVQ6tUx1hhTGyjdZmYTtK6mjtcolc7TSb9NigZLMaPqqeQrDZdjkyl/ECDxq5VC CZEAbglb9Y0vPOZDMQZOKdkUtKdyAS3YZNc/qBVNVgenMfI4FRZzgHQ1iiynIlneqMrG HyuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454368; x=1693059168; 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=Crn5/+8WdRhCgV6i5ssfAVZRKeJzdqL7IL6ctYKnl6U=; b=RNWb4+sF0oUcdYXGsau7IeBCs4w+2v70QAlz4pp9GJzBST+M1DkpflH9EigIo5hHTr Ruwnt5bmj8LNqYKk96+Y8qRVTqg+DfxjzTgJc7zugLxmZ6WAyvib13IVG7O8FC7hDCwr 7W/tNJY9zPfYqP/OdNxukr697rySxuCl4mWt1ayS4CnQnapQ1Ddub7NXf1PxB7pBxg9k iYtyB1QxUbYBmnAmsNzcndbM/2qO+RX8+Ss8NHad5482u0t134t51o63KAdN2o/SqTgS EmAG6yHUKHpXZGRybvFsdmb60SQSrpWzh4WMavqoixb4sc8IRuDpRqLlb9s62QTVii+t Lsfw== X-Gm-Message-State: AOJu0YyAy9EfM63njfE/LPlvuGYALQhQ8qG/TrluyXiFWXQTR9heFIXG AeGiHZgmixw8jQcQFXdFCF4= X-Google-Smtp-Source: AGHT+IETTvZTEFyiJf8ZsCBw1Z942T/yFUfrCc+lCrhAif1gu2FCfd/M7wsnPaQD+/POCrDPVTsgpw== X-Received: by 2002:a05:620a:2987:b0:76c:e764:5081 with SMTP id r7-20020a05620a298700b0076ce7645081mr2825410qkp.37.1692454367995; Sat, 19 Aug 2023 07:12:47 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id 22-20020a05620a079600b0076ce061f44dsm1204827qka.25.2023.08.19.07.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:47 -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 5/6] sched: handle NUMA_NO_NODE in sched_numa_find_nth_cpu() Date: Sat, 19 Aug 2023 07:12:37 -0700 Message-Id: <20230819141239.287290-6-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-Rspamd-Queue-Id: CF67740013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: uhcq1p5z7grk6d5zyngsqq9zidgn8q6h X-HE-Tag: 1692454368-573336 X-HE-Meta: U2FsdGVkX1+lAdFZIjUdcJb9uCkO2NlO0G1WPGJ4WG+Vzo3oHScWyix1hpreej65/q9hdmbHYDhzEtrJSS4b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HeGBbg0tkC8RGBDkyisRznTzSm4NzcPwp95PiBRPHvmXDDPDvj/VEq/qXMlxsNAa4oUX/fkP8KGCzmoNf7Z0HGjIUM3fH3nEUSQGdqLRxxB5pcZaWQHC1xgw0mIB5/vVPiyAQ53w152+qG8o890VO8KZXk55RSC+wgsWksDO7KVs8jndIY0TjsM/xrQjjqN1xr9Ew6rSoyvmT2zZfgW8cAc44FswzU/8A8roubbsKJq1Kr7JpBrYjl0Sp6qO0Qczo2g+tTf7qmcK8wUfBA4SD8Cv7ua69Ikzr5zXC0VFASmMbYvkuK1Tdo3lG7gs9BpBYsqv3CVqe1vyY2y4pfDqQn6iRPfe4wbMP7vNjSPvvyLwj8cOwi37e+zxOZS4X4xTRolIzA== 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: sched_numa_find_nth_cpu() doesn't handle NUMA_NO_NODE properly, and may crash kernel if passed with it. On the other hand, the only user of sched_numa_find_nth_cpu() has to check NUMA_NO_NODE case explicitly. It would be easier for users if this logic will get moved into sched_numa_find_nth_cpu(). Signed-off-by: Yury Norov --- kernel/sched/topology.c | 3 +++ lib/cpumask.c | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index c6e89afa0d65..bc6802700103 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2117,6 +2117,9 @@ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) struct cpumask ***hop_masks; int hop, ret = nr_cpu_ids; + if (node == NUMA_NO_NODE) + return cpumask_nth_and(cpu, cpus, cpu_online_mask); + rcu_read_lock(); /* CPU-less node entries are uninitialized in sched_domains_numa_masks */ diff --git a/lib/cpumask.c b/lib/cpumask.c index 19277c6d551f..e77ee9d46f71 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -147,9 +147,7 @@ unsigned int cpumask_local_spread(unsigned int i, int node) /* Wrap: we always want a cpu. */ i %= num_online_cpus(); - cpu = (node == NUMA_NO_NODE) ? - cpumask_nth(i, cpu_online_mask) : - sched_numa_find_nth_cpu(cpu_online_mask, i, node); + cpu = sched_numa_find_nth_cpu(cpu_online_mask, i, node); WARN_ON(cpu >= nr_cpu_ids); return cpu; From patchwork Sat Aug 19 14:12:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13358639 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 60E2DEE4993 for ; Sat, 19 Aug 2023 14:13:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45DAD90001A; Sat, 19 Aug 2023 10:12:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E7A6900011; Sat, 19 Aug 2023 10:12:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2144490001A; Sat, 19 Aug 2023 10:12:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 09E71900011 for ; Sat, 19 Aug 2023 10:12:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D5F651408A7 for ; Sat, 19 Aug 2023 14:12:51 +0000 (UTC) X-FDA: 81141045342.26.7C7C352 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by imf23.hostedemail.com (Postfix) with ESMTP id 14A79140010 for ; Sat, 19 Aug 2023 14:12:49 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=YPTYau8i; spf=pass (imf23.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.47 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=1692454370; 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=kSjHpIarSFWJNPdWsAvPv/NwMFUjoCdaJnar30zRHJU=; b=6Y/2ixgQP8BqItCT8UjOqICJ+fccCnyMFWZeHKTCnlrEBL1WFCqhjyNrA1Q0FUGC+dFpn4 x2NMb+s6CdFQGJtQCX2P2NsRK0idCNJVqTK0NpBh3zB1Uefni2ql014oWR5X0o+SoTJoSI bkLcNKJAP+Pj796nibKq3K9XUhE94OA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692454370; a=rsa-sha256; cv=none; b=4iezM28yoQWwa8kOuzEdgNfJwA5yPtZ7/HW0jdcq04ln8W5+G5cl4iU3iCdooKnPLDqkYH Ak331cqKjU5a787nXLEsPcadSbwX8JB6K1M8Xajq3CIyHBCWuRpUzv6scCXj8D0ou2+NWQ lIOjcUQgr8oalFXVqtyQ8ZVsORKAkDw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=YPTYau8i; spf=pass (imf23.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.219.47 as permitted sender) smtp.mailfrom=yury.norov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-64bb576b8abso7988236d6.2 for ; Sat, 19 Aug 2023 07:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692454369; x=1693059169; 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=kSjHpIarSFWJNPdWsAvPv/NwMFUjoCdaJnar30zRHJU=; b=YPTYau8iMQLnPV+8MSH/8fja/dsf3ZcEtp5kyGNDrnFQqPSXA5t6VdW4PpzV8wj9De 9w4eBuHp337uqHsSO8utHM8/RVexJMd4Nq1n4C8TDizf3M2jE01bhejhVqpv67N90w3m /8hJWdkhJO1gY/EjNZkWkBPTBTnXoF4wuIv9yOUkUWDdwRQyE9douqL/HsdzxxILocF1 iOyufwrqJiVlOWBYHXCP40osxOUD/3qinlpd6jk6RJgTZk4jgn6odD4ol+tnkFtuw5k6 LxPvVHNtQxQz8fCwlXbUSbbzBIOIa6DuKbo9gMZIF6Uov1UISZHXIyeaEbDQRmznnsAk dP0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692454369; x=1693059169; 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=kSjHpIarSFWJNPdWsAvPv/NwMFUjoCdaJnar30zRHJU=; b=DthQLe12FWRuHHmzJmp4gKXTooooBHxhXXOZe9S9Y7t8cLV+fTsRiMkL7GX8Sx4dV1 7A5mIF8JdDnDJCz6w3kaRk2AKXWk2syvN+oIFMF2uRmI88tYFtPhMA1TMRdDTRrRr9OB 2mNrHPN4cz1h9Qa70AlBjp/HdYcnKGiMh0ZHXpp1+YgoRg8qGdfLTX1YrE20WS61dSh9 V8KRh54g3V9PVqm85pT+Z7ZDMUPbZqtHNbDGEAwQE+Mws12ChLs5zwHhlrSTPWagNTSK 0RbI9j5mBu/fdhl34j3NTqIWgaVWxfrBWKCdGMVYY5OAhgdpTYxthl0DUrg7e9xe0lIz 3pTA== X-Gm-Message-State: AOJu0Yyu0PBMSIJEq5EQkZBiVfXf2kEOOjq85bae6oiwU5qvP9WV/aEm Kt6cgxkLJKHx5hro94jK400= X-Google-Smtp-Source: AGHT+IFlP2jDt8uZ7TktMhzGEL+WSo8Hr7UkTWitsqazph963ocRgXITG4K/KKqigpjjb7d7gIYaJQ== X-Received: by 2002:a0c:f34d:0:b0:647:1764:7e1a with SMTP id e13-20020a0cf34d000000b0064717647e1amr1891960qvm.27.1692454369104; Sat, 19 Aug 2023 07:12:49 -0700 (PDT) Received: from localhost ([32.218.242.113]) by smtp.gmail.com with ESMTPSA id x8-20020a0ce0c8000000b0062def68f75csm68439qvk.124.2023.08.19.07.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 07:12:48 -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 6/6] sched: fix sched_numa_find_nth_cpu() comment Date: Sat, 19 Aug 2023 07:12:38 -0700 Message-Id: <20230819141239.287290-7-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-Rspamd-Queue-Id: 14A79140010 X-Rspam-User: X-Stat-Signature: h61t78d3ywpfbnmnzehzgqupsj7mniq7 X-Rspamd-Server: rspam03 X-HE-Tag: 1692454369-661568 X-HE-Meta: U2FsdGVkX18QTvfvBiw33gC+RbtquzuWEQCJyYlXPfAqgs2HMzuqYrB1UFPgqxUrqSo7X6IBxhN0lF5m6BEEo4VGPC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+tl7fAK16hkpEkX0zFRsRHzHhfTVvYwe/Wo2BrBajZtCaltekylcp74LwfHdu98MLBk+AH0+YE8XFykU4t86eprGci6tZ+tKEzBaCY1zPxGY0FErQWdh/2PzSPZH/UFbkMIAmrYNEsu6eUTHIyWR9Agk7i/+/KKmqJ2TcdfPHmxI0pS1TmKSD9PIsVHJun7P2+2RWcvaT7ry5No9UIe8gV+mq9vYU1G94EXvKvOFmnPrSJAult2HGBmkver74XscGtCkz3f6pCY6iuWZcKZ7sr4AgulX2MRDPj4j1R8nBAupzEymR8KmcFrJTy6u+o2eQ4g1JQGcRXVV3YV5hNbrBW8LZJ05bgOjp0NVxOSqe1Oqtw04+iBhqv9dVPVCKEHNLEHOYVyIZFh7YHL1QFbPUgNL5gZEk4saVp5vQ== 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: Reword sched_numa_find_nth_cpu() comment and make it kernel-doc compatible. Signed-off-by: Yury Norov --- kernel/sched/topology.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index bc6802700103..789b281d2380 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -2103,13 +2103,15 @@ static int hop_cmp(const void *a, const void *b) return -1; } -/* - * sched_numa_find_nth_cpu() - given the NUMA topology, find the Nth next cpu - * closest to @cpu from @cpumask. - * cpumask: cpumask to find a cpu from - * cpu: Nth cpu to find - * - * returns: cpu, or nr_cpu_ids when nothing found. +/** + * sched_numa_find_nth_cpu() - given the NUMA topology, find the Nth closest CPU + * from @cpus to @cpu, taking into account distance + * from a given @node. + * @cpus: cpumask to find a cpu from + * @cpu: CPU to start searching + * @node: NUMA node to order CPUs by distance + * + * Return: cpu, or nr_cpu_ids when nothing found. */ int sched_numa_find_nth_cpu(const struct cpumask *cpus, int cpu, int node) {