From patchwork Mon Aug 8 06:26:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 12938505 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 7D7FDC25B0C for ; Mon, 8 Aug 2022 06:27:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C4498E000C; Mon, 8 Aug 2022 02:27:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94EF08E0008; Mon, 8 Aug 2022 02:27:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A0428E000C; Mon, 8 Aug 2022 02:27:23 -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 6964A8E0008 for ; Mon, 8 Aug 2022 02:27:23 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 44AA01209CD for ; Mon, 8 Aug 2022 06:27:23 +0000 (UTC) X-FDA: 79775443566.12.4883956 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf19.hostedemail.com (Postfix) with ESMTP id D9CFE1A012E for ; Mon, 8 Aug 2022 06:27:22 +0000 (UTC) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2786C77u002741; Mon, 8 Aug 2022 06:27:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Vq7NtUTGJv/Btzc/7iihSXrYrrCuEc0Ypk+wO/4fJgU=; b=soa81K6XdewrUquilSEzClnmi/ZW8Kdv6mDGIpoNcg+UtQsxSSaOP7omH61HiP4L1bGw +yKLWlrRBdK9GaGWhv3AXCivi1Y1Jz7u5QTO5DKVEXtrJNUnAO99Qxwfv3D6xWTnNfcG Wrpl6pT9HjOf5i24mYT8fqstIgbN4o6Jk+cCsBO35r6RisBnJTN+9P8j7QpZTzMs83VC k0VkYdyM8KSgAwMiZ71LA+VUn0+ChjYcaKtp8uYh/OYBonvC83Y0tQM9itBqAtufi37Z zctPMurlfQCT+cen8QCVgHgjs0SwsU48VVys0mjIU5J9gw398NGz5ApNFPimIlYt1HgK 9g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3htw0mrbeh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 06:27:15 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2786Dqh5012289; Mon, 8 Aug 2022 06:27:14 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3htw0mrbdv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 06:27:14 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2786KJNs015604; Mon, 8 Aug 2022 06:27:13 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma03dal.us.ibm.com with ESMTP id 3hsfx9wh2x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 06:27:13 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2786RCoB36372986 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Aug 2022 06:27:12 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3802C7805E; Mon, 8 Aug 2022 06:27:12 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6050C7805F; Mon, 8 Aug 2022 06:27:06 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.19.76]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 8 Aug 2022 06:27:06 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Wei Xu , Huang Ying , Yang Shi , Davidlohr Bueso , Tim C Chen , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Alistair Popple , Dan Williams , Johannes Weiner , jvgediya.oss@gmail.com, "Aneesh Kumar K.V" Subject: [PATCH v13 9/9] lib/nodemask: Optimize node_random for nodemask with single NUMA node Date: Mon, 8 Aug 2022 11:56:01 +0530 Message-Id: <20220808062601.836025-10-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808062601.836025-1-aneesh.kumar@linux.ibm.com> References: <20220808062601.836025-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: t1KZaO_Yul7vT8aqZ_tnU9bCL67z8lYx X-Proofpoint-ORIG-GUID: qk0acrlX4inmpnQSAoP_SET7g4Q8bi1Y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-08_03,2022-08-05_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 adultscore=0 priorityscore=1501 phishscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 impostorscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208080031 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659940043; a=rsa-sha256; cv=none; b=cmKiziuS22cOUUPp3Lhetw3MbousNSnuBCWzxU+KVcxLoTCERPzMD3HsmwFDK5wOpRUrAk 3b7i5hbf8cqbxVNi/C2y7Aih7AkOYX4T7+kTDqkYaiqYB+cOBrHWZfMvPRpNpNssxKhB3q 7u5DpBHX3nyp9HPBMBs4pKe3Dzrq4Qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659940043; 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=Vq7NtUTGJv/Btzc/7iihSXrYrrCuEc0Ypk+wO/4fJgU=; b=q2d5vCIMjxVSJMdBK8Rjrez3vC1LSin3M4sF4IjGlCneFp/K9q61THLt5ZwoDxuj8xQ2Jt z4+yP0ngRm643JrMI8JMZ+XikJFmR1qb+5HE/wEvMEPOlLs/gbPc3C/Yd8JqRRbkjBVScW cpDuSmxD6cXphEfgMwFr3bLdlxs3nZI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=soa81K6X; spf=pass (imf19.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-Stat-Signature: kkdtt7jh3uns1ss89gur5mrsrh15ydqu X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D9CFE1A012E Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=soa81K6X; spf=pass (imf19.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-HE-Tag: 1659940042-252789 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 most common case for certain node_random usage (demotion nodemask) is with nodemask weight 1. We can avoid calling get_random_init() in that case and always return the only node set in the nodemask. Signed-off-by: Aneesh Kumar K.V --- lib/nodemask.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/nodemask.c b/lib/nodemask.c index e22647f5181b..c91a6b0404a5 100644 --- a/lib/nodemask.c +++ b/lib/nodemask.c @@ -20,12 +20,21 @@ EXPORT_SYMBOL(__next_node_in); */ int node_random(const nodemask_t *maskp) { - int w, bit = NUMA_NO_NODE; + int w, bit; w = nodes_weight(*maskp); - if (w) + switch (w) { + case 0: + bit = NUMA_NO_NODE; + break; + case 1: + bit = __first_node(maskp); + break; + default: bit = bitmap_ord_to_pos(maskp->bits, - get_random_int() % w, MAX_NUMNODES); + get_random_int() % w, MAX_NUMNODES); + break; + } return bit; } #endif