Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1554070rdb; Mon, 19 Feb 2024 22:33:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVZLRdrGj/t8vQmFvXagRO05c41oF1JJ/kHKttoQx/SUmfddol92SMzsacjCrcilx9raNin7XVLa2NiiBbAhkObsDCAhXT7PLCJop1qnw== X-Google-Smtp-Source: AGHT+IGmtB9Wixein4C5xnXIEJ6rl/y3T0+7O+S7haEpO3gzsGOT7Ufls5YmhgfUDXmMeBmPjMmE X-Received: by 2002:a05:6102:a52:b0:470:6446:3a01 with SMTP id i18-20020a0561020a5200b0047064463a01mr3670457vss.30.1708410791844; Mon, 19 Feb 2024 22:33:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708410791; cv=pass; d=google.com; s=arc-20160816; b=kmqa3iQfcgNNe8dm3DPEB2GVWeafFGCw6vrHXgJgsV3vOul1ufx9Wrdt4cawZa6jWq rQYvbPy2dlqsu1I6Oxs8BfOvNGmVa2p7rKvGbhMS5wneGl58LJ+rdaQpWZFMr9dYsTYe HGQxeOPTODpWZ6DeQh14Xx8qFUze+GQGQhNbObAz/ONky6+r4UZE4ceYbEzJGd91d0yB /xYAuNn2+QP53pTNDCMlCyLp1odrHKn1XVHLf8szFUNCG2oPof6ZCQKaYmbr2SHsphNd /wwvxJb/YMVhkTZlBlpFlwW3Z0KR4mh0k4OtJooIWJ3kVhxMBfyxrt/bz4dC2CyVih5I kHBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=LHZk0oeFahViP4bbbLTr0s/BLVfspCD/3jRr/l0gpEE=; fh=mGKSn6bTzTiM4MDLA1I1Y7WlX71TzvSVcq61488NLYY=; b=tZiQV1M0+uSYcoYBUirIi2XghmW2I1SnMtc+jXW9MsTwVbv5jtjW8GtHfNGvOUfR/s ZqWvJTMJ/+KEUqlUFy/vXJfDAyLJLuTNNvYP13hq1t9gNVe0quvgEHoqOA75mTHK8jMC t/yPfUHMYwNE+1n1wiAmG9KS2AkvrR3ZSl+kH9vwdHdlS4raguAP/h+ybwMyBMvFZkcs CrkENu09TFwSuW7mp1Ku4ItioA489bwD3TY1ouuRn40DnOL++JeBAuenJFGqZEePHv7/ hZD+l6yWnSsHt3UWUWnovHZVuduXVv5MWKVKAhuVVBF2kR8Bb9p0x0it0pKnmSCoeaRu qkEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JuMOJcFc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-72415-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x3-20020ac85383000000b0042dd20db0c4si7486069qtp.386.2024.02.19.22.33.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:33:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72415-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JuMOJcFc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-72415-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 829781C21005 for ; Tue, 20 Feb 2024 06:33:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E66FF51C47; Tue, 20 Feb 2024 06:33:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JuMOJcFc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12C2642054 for ; Tue, 20 Feb 2024 06:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708410786; cv=none; b=pfU0ctAkGpa4YMPT5y8OfLNrQq+VETw+rgidk9AGji1dJslRlHbnPheXOFc76eIN6lV/jOKi1oujlt1JhBkvSQXBbUKmIJuG56RyOAjCl3de4n4pcrSfVU2ycibdvaNKkIUqano4PSJZIeQ9dAL/Ysct9U/KIA1GO8Qf39VKSbg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708410786; c=relaxed/simple; bh=gZZeREXEUghP1MKgAgV1Z2A/YMLqIsmKYAK87mJddTs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GDViftRLop+P5Y2pPZTQ0eSe0YhyZST0v8Vtd9c/of/3yFsnvjUP1zGN3xCMxwrive3IXDRgxtJm4VqYXOkAqku8fDupBbRzLXNLZkX78JXUMbpBmygYTTc7gQ50/+I3XMecKyHyZxn22DsyVmG8f5vQWEII8LmvEduyi1JN9yU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JuMOJcFc; arc=none smtp.client-ip=10.30.226.201 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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