From mboxrd@z Thu Jan 1 00:00:00 1970 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 A8281C433EF for ; Wed, 8 Jun 2022 05:02:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 273326B0072; Wed, 8 Jun 2022 01:02:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2221D6B0073; Wed, 8 Jun 2022 01:02:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C4118D0001; Wed, 8 Jun 2022 01:02:50 -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 F0DFF6B0072 for ; Wed, 8 Jun 2022 01:02:49 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C768520CCD for ; Wed, 8 Jun 2022 05:02:49 +0000 (UTC) X-FDA: 79553873658.15.91B165D Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf26.hostedemail.com (Postfix) with ESMTP id 5241314005C for ; Wed, 8 Jun 2022 05:02:49 +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 2584rmQH031067; Wed, 8 Jun 2022 05:02:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=RhuxxbL2muM1exHrZkvpaR4qmgjQCeQg6dQ6U2WhEgo=; b=AyVHTgMnNXLAgWt2rjT/uEoUfvrAlHbQSmgnSBB0u2hnzezw1bOOWkECDgM4KPDXJXjp FelFCF2fntvXn81jKZbQ+MyHs107FSw6JXXTAK9I9Myr+pXUtxCCBLKEhhYgtUZrbjcc bNX5oNsC8LrhJBC90QmLEc3jNG5TP92/vGmLi5WFCHcjr/O07H1fBz701UmRNhyp0OWV 4jHZIczTcbKOBjuI1TKdDUQ/YbKBoHk5MhYMUqqtaIzLVnnyG8fvMINyZbUvNopNOUxE oBq68KQNh6euarlmoytfzj4az7o9OrQyFmiebqEKUYsCSgCen+oe87V4+81F49FQzoRQ rw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gjn55r52q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jun 2022 05:02:40 +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 2584sJ7h001142; Wed, 8 Jun 2022 05:02:39 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gjn55r51v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jun 2022 05:02:39 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2584q0SW010256; Wed, 8 Jun 2022 05:02:36 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3gfy19cmap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jun 2022 05:02:36 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25852IGC23331142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Jun 2022 05:02:18 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64D0352054; Wed, 8 Jun 2022 05:02:34 +0000 (GMT) Received: from [9.43.53.124] (unknown [9.43.53.124]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7A81052050; Wed, 8 Jun 2022 05:02:27 +0000 (GMT) Message-ID: <6a2b05db-8e8d-b5e0-6166-f5c41c410c7b@linux.ibm.com> Date: Wed, 8 Jun 2022 10:32:26 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v5 4/9] mm/demotion: Build demotion targets based on explicit memory tiers Content-Language: en-US To: Tim Chen , linux-mm@kvack.org, akpm@linux-foundation.org Cc: Wei Xu , Huang Ying , Greg Thelen , Yang Shi , Davidlohr Bueso , Tim C Chen , Brice Goglin , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Alistair Popple , Dan Williams , Feng Tang , Jagdish Gediya , Baolin Wang , David Rientjes References: <20220603134237.131362-1-aneesh.kumar@linux.ibm.com> <20220603134237.131362-5-aneesh.kumar@linux.ibm.com> From: Aneesh Kumar K V In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UE-Ya6p1P_5TBYb9d9EY-JcuJ91sSLKp X-Proofpoint-ORIG-GUID: 7y_JG1IqOPaOTmZembLo61EzP8KLXCdE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-08_01,2022-06-07_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 impostorscore=0 spamscore=0 clxscore=1015 malwarescore=0 bulkscore=0 adultscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206080022 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=AyVHTgMn; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf26.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-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 5241314005C X-Stat-Signature: 3k6k8ceyh43hpwq1mtpxfz64ioaipayn X-HE-Tag: 1654664569-149918 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: On 6/8/22 4:21 AM, Tim Chen wrote: > On Fri, 2022-06-03 at 19:12 +0530, Aneesh Kumar K.V wrote: >> >> +int next_demotion_node(int node) >> +{ >> + struct demotion_nodes *nd; >> + int target, nnodes, i; >> + >> + if (!node_demotion) >> + return NUMA_NO_NODE; >> + >> + nd = &node_demotion[node]; >> + >> + /* >> + * node_demotion[] is updated without excluding this >> + * function from running. >> + * >> + * Make sure to use RCU over entire code blocks if >> + * node_demotion[] reads need to be consistent. >> + */ >> + rcu_read_lock(); >> + >> + nnodes = nodes_weight(nd->preferred); >> + if (!nnodes) >> + return NUMA_NO_NODE; >> + >> + /* >> + * If there are multiple target nodes, just select one >> + * target node randomly. >> + * >> + * In addition, we can also use round-robin to select >> + * target node, but we should introduce another variable >> + * for node_demotion[] to record last selected target node, >> + * that may cause cache ping-pong due to the changing of >> + * last target node. Or introducing per-cpu data to avoid >> + * caching issue, which seems more complicated. So selecting >> + * target node randomly seems better until now. >> + */ >> + nnodes = get_random_int() % nnodes; >> + target = first_node(nd->preferred); >> + for (i = 0; i < nnodes; i++) >> + target = next_node(target, nd->preferred); > > We can simplify the above 4 lines. > > target = node_random(nd->preferred); > > There's still a loop overhead though :( > Will fix in next update. >> + >> + rcu_read_unlock(); >> + >> + return target; >> +} >> + >> -aneesh