From patchwork Fri Aug 12 05:57:09 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: 12941920 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 9B661C00140 for ; Fri, 12 Aug 2022 05:58:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A8F98E0003; Fri, 12 Aug 2022 01:58:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 332548E0001; Fri, 12 Aug 2022 01:58:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AD0E8E0003; Fri, 12 Aug 2022 01:58:39 -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 0B3DE8E0001 for ; Fri, 12 Aug 2022 01:58:39 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E4C9440E8D for ; Fri, 12 Aug 2022 05:58:38 +0000 (UTC) X-FDA: 79789886316.03.0802F1C Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf21.hostedemail.com (Postfix) with ESMTP id 674031C01BD for ; Fri, 12 Aug 2022 05:58:38 +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 27C5gOIT025344; Fri, 12 Aug 2022 05:58:27 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=ZSg3RqRbN4v0XDqmeX0HctksS/vI4TIlPh6CTw4ub/o=; b=aTEKFiH2jn9R7FH3NLsluCvKeM97rSfPg8Gjslz0S7TUoVLmZ4M5Ku7l1diEK6eF8gme jI4+0EKSh4N/UJ141raJOyKMU9z/uO1skW4xOy5QmGRGkMXqSEbGmhjrNNH1MCXuZLAM qIcDqtsOWML1yxCHzuwTDvoIv3l/iO2ux1eQ5EHL1WRYitIDCBQEV5Ze1koNa0umDWjn m4tEuDDqUS0obhSfmjn+y04F5LyyVIFc+ooXv2++3tsq2hfcKPKwALyRC0sm7Gqi8UrH 6TayYpJA3QgROBoO77VZ6i6j7gyuE1ejYqLBGirxLGhZ81IV4AT4bwlkRPpgS1oRtDRh rA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hwgxu0b3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Aug 2022 05:58:27 +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 27C5iRP9032199; Fri, 12 Aug 2022 05:58:26 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hwgxu0b38-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Aug 2022 05:58:26 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27C5ZPGm031932; Fri, 12 Aug 2022 05:58:24 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma02wdc.us.ibm.com with ESMTP id 3huwvffcd8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 12 Aug 2022 05:58:24 +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 27C5wO718979186 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 12 Aug 2022 05:58:24 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13F807805F; Fri, 12 Aug 2022 05:58:24 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 99AAB7805E; Fri, 12 Aug 2022 05:58:18 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.116.179]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 12 Aug 2022 05:58:18 +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, Bharata B Rao , "Aneesh Kumar K.V" Subject: [PATCH v14 10/10] lib/nodemask: Optimize node_random for nodemask with single NUMA node Date: Fri, 12 Aug 2022 11:27:09 +0530 Message-Id: <20220812055710.357820-11-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220812055710.357820-1-aneesh.kumar@linux.ibm.com> References: <20220812055710.357820-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: uFfWbS563dvPIlfQCnFHt3nMfCBMyM4D X-Proofpoint-GUID: ObaSRfe0pp8Njs6KE-KmROPq2p2pBf42 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-12_04,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 bulkscore=0 clxscore=1015 phishscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 adultscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208120015 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660283918; 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=ZSg3RqRbN4v0XDqmeX0HctksS/vI4TIlPh6CTw4ub/o=; b=lZPnVx1JnqdSRiGI7esmkCL0luE2XH1nE3vX/xpaXgdh7dm5gG7mA2FQ0xRfN0xoKZzgSN ySFFCqv3GSxvVtb7AcqwIpXgCjg8fEWJLLxqZXGm537EsQZ5+6jud/diYi6nYXpcZfawhK ZAYcQDF1AoeLopzwpYLWuz0TolKyByo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=aTEKFiH2; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf21.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660283918; a=rsa-sha256; cv=none; b=zX8F7jY1bXQi8wruE1GL2pLcyQbNVFlHUvc9ynzGDLOPyBWKzpxt37xY81l4AAHlQPfgOL DvMENJC7c1HDXJsEaU8qyBhNL78Bd7AaRegfyurRPq+6Syl9JZ89Fte3HBc/1qOpkITD8h /9NCQRvbAjOoX769AS8ODvlWY++HLhQ= X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 674031C01BD X-Rspam-User: X-Stat-Signature: yhbfbmkn8fre3efqm19ts75dtr4ehn44 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=aTEKFiH2; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf21.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com X-HE-Tag: 1660283918-40840 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. A simple test as below before = rdtsc_ordered(); for (i= 0; i < 100; i++) { rand = node_random(&nmask); } after = rdtsc_ordered(); Without fix after - before : 16438 With fix after - before : 816 Signed-off-by: Aneesh Kumar K.V --- include/linux/nodemask.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 4b71a96190a8..ac5b6a371be5 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -504,12 +504,21 @@ static inline int num_node_state(enum node_states state) static inline int node_random(const nodemask_t *maskp) { #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) - 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; #else return 0;