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 9A9D2C48BC3 for ; Tue, 20 Feb 2024 06:33:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF0198D0003; Tue, 20 Feb 2024 01:33:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA0178D0001; Tue, 20 Feb 2024 01:33:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D67048D0003; Tue, 20 Feb 2024 01:33:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C38228D0001 for ; Tue, 20 Feb 2024 01:33:12 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 907644059D for ; Tue, 20 Feb 2024 06:33:12 +0000 (UTC) X-FDA: 81811215024.07.2CC4276 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 3EF3B100003 for ; Tue, 20 Feb 2024 06:33:09 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JuMOJcFc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of aneesh.kumar@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=aneesh.kumar@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708410790; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LHZk0oeFahViP4bbbLTr0s/BLVfspCD/3jRr/l0gpEE=; b=AVZQ7TLGJS8Ij9efOlTjOEZ5cpkmMjfoeqLBh3nTe+zOlLW3Nd8bLqRNVnXECME//hly6W DqwSzLbr0SlJ1l0VY8snueorilUDEw365IoQjwK66AeL1KxtTPKodZ1d6SCDx4HWKg1vVm cXtbSKZLdFSXtkb3Jd5Dd+L9H3p14LE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JuMOJcFc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of aneesh.kumar@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=aneesh.kumar@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708410790; a=rsa-sha256; cv=none; b=bWE/c3RNdWr8i2yXXq5MPNM3RBuDgJXRarHDXZpZ/IWBcyKwzixvgqkj6xIQkDGLdxN99g CCVWcYRSuNMCJvUPTytEAbqTa+x7Snl6cf+G3OWnQbGWlalkAznf8Kq+V5mU/LFzUpY9Sr 5UTWjnoOTMdK1/P6gjPxGdaW/WzGPVc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 5D3AACE17D1; Tue, 20 Feb 2024 06:33:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC7D1C433C7; Tue, 20 Feb 2024 06:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708410785; bh=gZZeREXEUghP1MKgAgV1Z2A/YMLqIsmKYAK87mJddTs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=JuMOJcFcTd82+d09cB2S5AxQMjuCMX/j3NFvQfhFhL84oJlNQZ/+f16rcbgBihoPk XiAYa7+nzkg7noKjtEUMNauwGDJ52VmclnLOcLoP7ZK9nk2HveOvskBh7J1noQusZe Wu+W+l7p+f2oKzAngCGeWc1Okiv8ASmooh6SgO0It6Nh9z7D8tELTxgTfBYDPbC9Jp ueUiUY4WB2ArDBlpCJoXE+dSxXQXLassKo8MjDhzOkMFRTfRbNwzfRX0NHlJ+qTcO5 QA3e2fL+mDtJ5Ukd0B+XKIt6O84QxEaj+xYVzg0BZ4EeshEfVXY81kegqS2H0RBjys uLhUFLzdsFB/w== Message-ID: <7097ff95-6077-4744-a770-b90d224c0c9b@kernel.org> Date: Tue, 20 Feb 2024 12:02:55 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] mm/mempolicy: Use the already fetched local variable Content-Language: en-US To: "Huang, Ying" Cc: Andrew Morton , Donet Tom , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dave Hansen , Mel Gorman , Ben Widawsky , Feng Tang , Michal Hocko , Andrea Arcangeli , Peter Zijlstra , Ingo Molnar , Rik van Riel , Johannes Weiner , Matthew Wilcox , Mike Kravetz , Vlastimil Babka , Dan Williams , Hugh Dickins , Kefeng Wang , Suren Baghdasaryan References: <9c3f7b743477560d1c5b12b8c111a584a2cc92ee.1708097962.git.donettom@linux.ibm.com> <20240218133851.22c22b55460e866a099be5ce@linux-foundation.org> <63a0f7c4-3c3f-4097-9a24-d1e3fc7b6030@linux.ibm.com> <20240219172130.82a16c1ebecbf8ba86a8987d@linux-foundation.org> <21f343fa-84a7-4539-91e2-6fc963dbfb62@kernel.org> <87frxnps8w.fsf@yhuang6-desk2.ccr.corp.intel.com> From: "Aneesh Kumar K.V" In-Reply-To: <87frxnps8w.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 3EF3B100003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: pwywgxzpgt3g81c17pydmzhu734jjhcz X-HE-Tag: 1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KGqwzZnWbHO24ZtNQZjMqgvJ77l35oZ06N1B933j4dtO/4M8KBISRJ/VTU1sJ85mJ7DBmlmp8BISsXbxDkCRu9eK5v43f9GMQ31DHaR+n/y0g3Au8GXkFjFRr9lnmwkGbmRoqCrMzUyu7JZuB+nejKbdpUhhXY0WtrvoULoJjZTFrygDbAZtwazz9PidQvLpFhZgC8F3wgMyKkCr6t2tS6pXRxFYXumEluzmOialo0LyWkck5IsscL6NFvg== 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: List-Subscribe: List-Unsubscribe: On 2/20/24 11:55 AM, Huang, Ying wrote: > "Aneesh Kumar K.V" writes: > >> On 2/20/24 6:51 AM, Andrew Morton wrote: >>> On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom wrote: >>> >>>>>> --- a/mm/mempolicy.c >>>>>> +++ b/mm/mempolicy.c >>>>>> @@ -2526,7 +2526,7 @@ int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, >>>>>> if (node_isset(curnid, pol->nodes)) >>>>>> goto out; >>>>>> z = first_zones_zonelist( >>>>>> - node_zonelist(numa_node_id(), GFP_HIGHUSER), >>>>>> + node_zonelist(thisnid, GFP_HIGHUSER), >>>>>> gfp_zone(GFP_HIGHUSER), >>>>>> &pol->nodes); >>>>>> polnid = zone_to_nid(z->zone); >>>>> int thisnid = cpu_to_node(thiscpu); >>>>> >>>>> Is there any dofference between numa_node_id() and >>>>> cpu_to_node(raw_smp_processor_id())? And it it explicable that we're >>>>> using one here and not the other? >>>> >>>> Hi Andrew >>>> >>>> Both numa_node_id() and cpu_to_node(raw_smp_processor_id()) return the current execution node id, >>>> Since the current execution node is already fetched at the beginning (thisnid) we can reuse it instead of getting it again. >>> >>> Sure, but mine was a broader thought: why do we have both? Is one >>> preferable and if so why? >> >> IIUC these are two helpers to fetch current numa node id. and either of them can be used based on need. The default implementation shows the details. >> (One small difference is numa_node_id() can use optimized per cpu reader because it is fetching the per cpu variable of the currently running cpu.) >> >> #ifndef numa_node_id >> /* Returns the number of the current Node. */ >> static inline int numa_node_id(void) >> { >> return raw_cpu_read(numa_node); >> } >> #endif >> >> #ifndef cpu_to_node >> static inline int cpu_to_node(int cpu) >> { >> return per_cpu(numa_node, cpu); >> } >> #endif >> >> In mpol_misplaced function, we need the cpu details because we are using that in other place (should_numa_migreate_memory()). So it makes it easy >> to use cpu_to_node(thiscpu) instead of numa_node_id(). > > IIUC, numa_node_id() is faster than cpu_to_node(thiscpu), even if we > have thiscpu already. cpu_to_node() is mainly used to get the node of > NOT current CPU. So, IMHO, we should only use numa_node_id() in this > function. > This change? modified mm/mempolicy.c @@ -2502,8 +2502,7 @@ int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, pgoff_t ilx; struct zoneref *z; int curnid = folio_nid(folio); - int thiscpu = raw_smp_processor_id(); - int thisnid = cpu_to_node(thiscpu); + int thisnid = numa_node_id(); int polnid = NUMA_NO_NODE; int ret = NUMA_NO_NODE; @@ -2573,7 +2572,7 @@ int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, polnid = thisnid; if (!should_numa_migrate_memory(current, folio, curnid, - thiscpu)) + raw_smp_processor_id())) goto out; } -aneesh