From patchwork Thu Aug 18 13:10:42 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: 12947384 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 95DDAC00140 for ; Thu, 18 Aug 2022 16:11:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1081E8E0002; Thu, 18 Aug 2022 12:11:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0902E8E0001; Thu, 18 Aug 2022 12:11:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E73CA8E0002; Thu, 18 Aug 2022 12:11:50 -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 D17128E0001 for ; Thu, 18 Aug 2022 12:11:50 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A7A4741962 for ; Thu, 18 Aug 2022 16:11:50 +0000 (UTC) X-FDA: 79813204380.07.1331EA8 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf29.hostedemail.com (Postfix) with ESMTP id BBEA8120F85 for ; Thu, 18 Aug 2022 15:54:26 +0000 (UTC) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27ICg54K006566; Thu, 18 Aug 2022 13:11:57 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=m2fn92MjFJdmD8qI1OD1ZZfckb8jiPcZlxGR7KNDcb8=; b=GEuaBSeZu7+6VtM7qT0GuZZuObdNf/fQi2RHM42ceUb6GRxWr42z5qq3Yrl6GQxVe7jp /WyiH7j2bB/PkEANZliSjNfSB2ERtIsxsgIB/Q2Lemk77Dbs9DXfs16aJOIN/3FlQaRV 5iJ5lwLF0XVXMybd1VnrGGThpBbBeBdtx7+IV9Qu9eqFu8HVb85/V+1yC7AJgbzQCQYx owkvzvYGPHKOw59LsKgs9a9JGEd7w2KL4A09SSl8JYGy6TaCpmq1so0szGsO+2ZEtSWX OfjGQCiGBKt0LcJMT0af77qEOkaQYrVxT3LGlc1HyhdRiyug9j8ia5zUrgBjCBHryyY+ EA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j1nne93m4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Aug 2022 13:11:57 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27ICgCEV007242; Thu, 18 Aug 2022 13:11:56 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j1nne93k9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Aug 2022 13:11:56 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27ID5Q0k002071; Thu, 18 Aug 2022 13:11:54 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma05wdc.us.ibm.com with ESMTP id 3hx3kaey17-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Aug 2022 13:11:54 +0000 Received: from b01ledav002.gho.pok.ibm.com (b01ledav002.gho.pok.ibm.com [9.57.199.107]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27IDBsnA17695410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Aug 2022 13:11:54 GMT Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56B60124053; Thu, 18 Aug 2022 13:11:54 +0000 (GMT) Received: from b01ledav002.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69E29124052; Thu, 18 Aug 2022 13:11:49 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.111.107]) by b01ledav002.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 18 Aug 2022 13:11:49 +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 v15 10/10] lib/nodemask: Optimize node_random for nodemask with single NUMA node Date: Thu, 18 Aug 2022 18:40:42 +0530 Message-Id: <20220818131042.113280-11-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220818131042.113280-1-aneesh.kumar@linux.ibm.com> References: <20220818131042.113280-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: h821cm1iY4VxjPEtr8AlCehQ-kEpQgcV X-Proofpoint-GUID: cPF8qtUhy1sZdH0c1B30i54NexpZhcNG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-18_12,2022-08-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 mlxlogscore=999 adultscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 phishscore=0 impostorscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208180045 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660838066; a=rsa-sha256; cv=none; b=2rUbaThh7JvsUD8N5GyfwzdpCu/ZyWynKNIJZzfy4EjrWJSxypOkVw1GwPY6UctVhYutff CIl1RkmeTn95bfwrL41wQVxmrWNRr5PNx4vMdt7WPDgESTpSFw9hlys8iqKiPfDeDRyWyt /9T0AamjMTLOB64Ad7NtoxtOmDax7ts= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=GEuaBSeZ; spf=pass (imf29.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660838066; 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=m2fn92MjFJdmD8qI1OD1ZZfckb8jiPcZlxGR7KNDcb8=; b=biO8L+KkR8wu1aPul0PXTDYc06Ui9Q36FVAFg8DWdwW0AqZqursBrJXca5ljiVNWJYl/4n 0XuJH/f+w54Y4stH/f6izqfp4VxrY3bASf28FnbvAPSPJbKybuVlok87l3YqhvYGyt+3aC VtuO8iBEixQwzw7ijJjjBLfoRupZsIs= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=GEuaBSeZ; spf=pass (imf29.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-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: BBEA8120F85 X-Stat-Signature: 6gj9847didyk6ofrwjakx7chy7je975q X-HE-Tag: 1660838066-643108 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 Reviewed-by: "Huang, Ying" 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;