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 CC703C19F21 for ; Wed, 27 Jul 2022 04:36:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0054A8E0002; Wed, 27 Jul 2022 00:36:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF6AA8E0001; Wed, 27 Jul 2022 00:36:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D987F8E0002; Wed, 27 Jul 2022 00:36:13 -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 C619B8E0001 for ; Wed, 27 Jul 2022 00:36:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9559E40B85 for ; Wed, 27 Jul 2022 04:36:13 +0000 (UTC) X-FDA: 79731617826.21.109E6F0 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf05.hostedemail.com (Postfix) with ESMTP id 1FCA110009F for ; Wed, 27 Jul 2022 04:36:12 +0000 (UTC) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26R4MkGL017782; Wed, 27 Jul 2022 04:36:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type; s=pp1; bh=pfnCm8czmgjFT7Ozg90Hrv5PKhLYQ+mhAb5RDtTMtGE=; b=hZPUVSdho0yKdrLxUIfATou+k5FiYSC6+M4dIfqCXmR5qd0vHWAGsPQcscyK6NcDswDO bQlJD7EGfrDIK3S/hlB9aP01cmmvgMIWz/tUAKrIXavjk+jHcimYHe/AKecReYmNrEqt v/9aTYYMi7bvvnMtjHgwY6EqA3DrQUtJEJe16sxwDkt94kIBpEKnAsCACBGyjFR1yjnQ TMHbZfTEQqDXAdpN3U4l2v6NeMYulKrcaWr7Ia9ILTSXtv2QUXuin+Ow06Nurm9PPBF+ n/RVHr8Plfn/cLCsvkKFFZZnLjXMkidmqdJRQN/Wi/4IZUVzcfPbLEiCP8M4aAFzWyU4 /Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hjx9mg8tn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 04:36:00 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26R4TMFI038767; Wed, 27 Jul 2022 04:36:00 GMT Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hjx9mg8t3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 04:36:00 +0000 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26R4K2v1017697; Wed, 27 Jul 2022 04:35:58 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma03wdc.us.ibm.com with ESMTP id 3hg97rxx47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 04:35:58 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26R4ZwlR52232678 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Jul 2022 04:35:58 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2C5E72805C; Wed, 27 Jul 2022 04:35:58 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D25C128059; Wed, 27 Jul 2022 04:35:52 +0000 (GMT) Received: from skywalker.linux.ibm.com (unknown [9.43.5.110]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 27 Jul 2022 04:35:52 +0000 (GMT) X-Mailer: emacs 29.0.50 (via feedmail 11-beta-1 I) From: "Aneesh Kumar K.V" To: "Huang, Ying" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, Wei Xu , 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 Subject: Re: [PATCH v10 5/8] mm/demotion: Build demotion targets based on explicit memory tiers In-Reply-To: <87h733uyc8.fsf@yhuang6-desk2.ccr.corp.intel.com> References: <20220720025920.1373558-1-aneesh.kumar@linux.ibm.com> <20220720025920.1373558-6-aneesh.kumar@linux.ibm.com> <871qu8wc6c.fsf@yhuang6-desk2.ccr.corp.intel.com> <9f14814c-cb08-8032-caff-edcd0594ad41@linux.ibm.com> <87h733uyc8.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Wed, 27 Jul 2022 10:05:50 +0530 Message-ID: <87k07zrx3t.fsf@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: FSP-gXLhloEOnrIdQ8IOjDm20A_55tH9 X-Proofpoint-GUID: l-Ulsb6qn-cnIMzAopsk5iIOf7c1KK7s 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-07-26_07,2022-07-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 suspectscore=0 mlxscore=0 phishscore=0 impostorscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207270014 ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=hZPUVSdh; spf=pass (imf05.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658896573; a=rsa-sha256; cv=none; b=YSDl/0FIWWdLezYGKKtopgppSvF9GwqUZ+kzHtTsn9j0aV6g8VJcoGZoupFGAx1gXPqS3I vDOf7LmqQVExVLG47M7ldnKIzqAQT//hxuP6/CGD4Cb2W1+u3tFjdwzysRC7tx3VAMZuLj 7bg9i0+LA7OjEi20ZBo3TJKIXqZQ9dY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658896573; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pfnCm8czmgjFT7Ozg90Hrv5PKhLYQ+mhAb5RDtTMtGE=; b=arUEsaGTWMxQd5M6Ti7BzQ3CGEqSY60xgROrYmrzrk0/uFpgG/Nzd2Q7Lgd0NiREZ/ZMON k7ZG5qCN7kU9vH5zlzU8qMoCyco8uZEelWDH1LU3BECDm2NJmD8L9lj8SyMJjotzYhx6pJ jM6Sd9Gp78D2HHCZK9vSDA5SpRqxKCw= Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=hZPUVSdh; spf=pass (imf05.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: rspam05 X-Rspamd-Queue-Id: 1FCA110009F X-Stat-Signature: h5aedo5q34y8994d84dixgwagujode33 X-HE-Tag: 1658896572-491125 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: "Huang, Ying" writes: > Aneesh Kumar K V writes: > >> On 7/26/22 1:14 PM, Huang, Ying wrote: >>> "Aneesh Kumar K.V" writes: >>> .... >>> + */ >>>> +int next_demotion_node(int node) >>>> +{ >>>> + struct demotion_nodes *nd; >>>> + int target; >>>> + >>>> + 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(); >>>> + /* >>>> + * 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. >>>> + */ >>>> + target = node_random(&nd->preferred); >>> >>> In one of the most common cases, nodes_weight(&nd->preferred) == 1. >>> Where, get_random_int() in node_random() just wastes CPU cycles and >>> random entropy. So the original struct demotion_nodes implementation >>> appears better. >>> >>> struct demotion_nodes { >>> unsigned short nr; >>> short nodes[DEMOTION_TARGET_NODES]; >>> }; >>> >> >> >> Is that measurable difference? using nodemask_t makes it much easier with respect to >> implementation. IMHO if we observe the usage of node_random() to have performance impact >> with nodes_weight() == 1 we should fix node_random() to handle that? If you strongly >> feel we should fix this, i can opencode node_random to special case node_weight() == 1? > > If there's no much difference, why not just use the existing code? > IMHO, it's your responsibility to prove your new implementation is > better via numbers, for example, reduced code lines, with better or same > performance. > > Another policy is just to use the existing code in the first version. > Then change it based on measurement. One of the reason I switched to nodemask_t is to make code simpler. demotion target is essentially a node mask. > > In general, I care more about the most common cases, that is, 0 or 1 > demotion target. How about I switch to the below opencoded version. That should take care of the above concern. > >> - target = node_random(&nd->preferred); >> + node_weight = nodes_weight(nd->preferred); >> + switch (node_weight) { >> + case 0: >> + target = NUMA_NO_NODE; >> + break; >> + case 1: >> + target = first_node(nd->preferred); >> + break; >> + default: >> + target = bitmap_ord_to_pos(nd->preferred.bits, >> + get_random_int() % node_weight, MAX_NUMNODES); >> + break; >> + } >> >>