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 D6149C48BC3 for ; Tue, 20 Feb 2024 07:24:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 573296B007D; Tue, 20 Feb 2024 02:24:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 523F86B007E; Tue, 20 Feb 2024 02:24:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C4136B0082; Tue, 20 Feb 2024 02:24:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 296BE6B007D for ; Tue, 20 Feb 2024 02:24:12 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EFFD31405BC for ; Tue, 20 Feb 2024 07:24:11 +0000 (UTC) X-FDA: 81811343502.27.CAA2225 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by imf06.hostedemail.com (Postfix) with ESMTP id CD3F218001A for ; Tue, 20 Feb 2024 07:24:09 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Xy63vRmX; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.7 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708413850; a=rsa-sha256; cv=none; b=JR4LRtdsBPObNGR0LMOTGQ+7MsPh9nkkKTnwejO+VZwmvgSzhazGFXB4kXZtUieAQjFbwB hmcDxmda+toTIDzlMingnInkos1palBDlYqgldf6X03iUBuXLTRrnCJirPhNpFV3xYsxyn ZSlUxlFMnKSnQ6UmlJgYEd555TC4IAE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Xy63vRmX; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf06.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.7 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708413850; 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=QRjkKZgBGi7a/EqceLg0R+IBVCqd7uZtpjflkCSGEXk=; b=JOhfQLTw9VOaFkUdVNkPWzcBIPbnFRmzCZcDS7zKkd5N/vbdVsFl/WLH2005ejwaeuEGBv HZRG7Q9UJOqCe5c1+YtPvD+k71cWalE8pbjE2DgqEYOiBjRiyjCgHx1n+T7KuIcPYUEUis hL7Z+RF+mZqGXUNZBHWuKivrk92HqPc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708413850; x=1739949850; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=RtNRRa18GwhwVog0vEFc0loPHQWu4i5Y/0NbpjoyX9w=; b=Xy63vRmXtuBxAvl3rSa3I5D7pLlzbuyF61semwOr7B5tX1Ah8+Btj5aD QOtfbjl4OD97ZeiD50nhiwlFE7RIPkEKJ8WEALhAGLUU6682Pplm+KJc/ yJcH4akHmloR28krExaef1GD9N17kKwUNuIf9qGvbRa2cqJVJaYfRMWru 1DFGiSBnnZtrWhCqnCQx1O1w4jgRZO28FI8aiJMU1ZRJwP2wT4i8Okn2Z vj7e8VQxxb8KAwLD3JEuSBNfMUaXQ/0CT5Uibz6h+//Rp5nquLGt1w7tM 2ATRhn6vs2HgY0snWboIunapcnJ7LAvnCn5uB/slnErYPesz44U7S4rhf w==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="27947382" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="27947382" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2024 23:24:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="42184372" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2024 23:24:02 -0800 From: "Huang, Ying" To: "Aneesh Kumar K.V" 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 Subject: Re: [PATCH 1/3] mm/mempolicy: Use the already fetched local variable In-Reply-To: (Aneesh Kumar K. V.'s message of "Tue, 20 Feb 2024 12:33:51 +0530") 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> <7097ff95-6077-4744-a770-b90d224c0c9b@kernel.org> Date: Tue, 20 Feb 2024 15:22:07 +0800 Message-ID: <8734tnppls.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CD3F218001A X-Stat-Signature: q87t59shedjtaf5gm97g9stfkjqye5s9 X-HE-Tag: 1708413849-612891 X-HE-Meta: U2FsdGVkX1/FoO2vzTKcKlmxrl0LYGJUXOqnvt8ZubTjuu2uQNraQh/8YQZKJJkbhU7+E/94J+mlTAdIP9JjctFTzG9Dd3e0yYzflI48Ewaq4ltX2cbi6EE79d/tb0it2+AaxUxty6tasVBb/gPB/vw16onKCM2FNkZykd8lWUSjG6Jhge2FvJz4a7ffAbFgSEb56JamJRa8kIGwjcfzMjwpX+gTdRRxPN0pYDbRcIeZ5i8vCBxj9QVKqNokDnjGVyb2GtDnVXtPVXFyn/nVd+HN+icU9NnAcDKZwcMcsuEgTuRam0sMP40QC/TmqxoB9unVqREkiVhKVVuh6qIXbjjDSSpYbxkgWoizWYldvt0OSukCgXcAs2ZW9ffo8fMDtgvRWCDSHsjHcrAVC9tcDscqbsAYgh68pDQGQg8oi+L0EXAVnvWuJUhq95rFQUVvY0arDOOVXft7fVJ5KYVy5ZZbtdvskq1fW2fxObdMcXaR3RP7ScQSAwWwcXCFNN4DFOJ0mBK+c0TQLfAhYKAlCeIM8NJNhgHxfGgwdZNc3xK9XzSoJov2sbGEvE02gTGLhIi1BZVRqsLagw9mY+mCKWsfhdg+7v3J/5CoK8gb6U0JiVCenU1h4xP4BMVFYLvoJUXrBgIvDithXQ1UKQAjJYyummyN4f+7oKa/2y1HH8w1d6BD3hH9jKqyhaanbe/ixYatn387kD5ixmB5CQysjxFkupkL1QeWI/wFen4FEI68L3sFPnIggn8Ktl3C5GUMZb4MvqUI3bqx9TjNrxVZfvkogPmiB3D2deEA6xesSQjT+ETBbvE0df+dgLlujPQB0J8ULP9/KZvUuV37bZGFlg1myLKWSqkveYQbFDgYFKDEgML2dPSWsDHxxIOqFq980kFFadmCiXDhS6EhMOVzHtuIcsdBwvScyUxWy7q6j9w3a9gtkL+YjEk9RV4qkO0/EkRCpRhOfpQfjp5pu8m Oa8KzpPs AYJ06M8ObSQ5+9SXR0NBT+4Bg6vewFmZkBYxilYUca7YXN0MHlD9zSJk7q42e9uPw3nZ1N+c+KeehJ6taX+7PRNFKMlmYItsKl/GAdVthX1X2jCnvtCctDHkUU0k0gc7p8qGhe/I+e6ZeMRqoKG1Oa5NBFvlYBvKigKdcxEXF0wKTH6qi0jfnOW4M0Zj2fm15pAULvdvjw236r3wY6uGh/YHA5l159ROC6QIEKv8bpcHuoes= 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: "Aneesh Kumar K.V" writes: > On 2/20/24 12:02 PM, Aneesh Kumar K.V wrote: >> 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; >> } >> >> > > One of the problem with the above change will be the need to make sure smp processor id remaining stable, which > I am not sure we want in this function. With that we can end up with processor id not related to the numa node id > we are using. This isn't an issue now, because mpol_misplaced() are always called with PTL held. And, we can still keep thiscpu local variable. -- Best Regards, Huang, Ying