Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1557539rdb; Mon, 19 Feb 2024 22:45:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXwnM0ss0Yjl4ZbyQlXmanIMCzSAeVrLfrgHiBiZzWfPZyYMchj52gv34vumV3J/3kC6Yhz9xtj7Lf7g211Oog+TXo1jCrnmduwCxk7bw== X-Google-Smtp-Source: AGHT+IFk5uh9VyuUYMm1kbQpeM/pq1OkDIkjnNkGP+8DKSJKeu87qULzEA4bSguhQD0iRUPjb5yj X-Received: by 2002:a05:6a20:9590:b0:19e:9ca7:7c94 with SMTP id iu16-20020a056a20959000b0019e9ca77c94mr21523189pzb.9.1708411507206; Mon, 19 Feb 2024 22:45:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708411507; cv=pass; d=google.com; s=arc-20160816; b=bb1VkURiAC+bjKLyEoSJ8FxZzF6aoIB2rUr+Z6/GswRtFbglZdblH+Dbes2Ez6Sn13 mlzmoe8QuItnIOycyrBb+ldpDaoFEReihoy1xFRJJIavQfrj7To3Tmosa2cPEVPkTQXt gAnuhzil8eTAOnvKhGRhHEJTFwgYlif+3ZAGKSv61q2vbouQJ0YnCB2xi1sTND9++NkG MDzoQINsyyg6scz1O5EtHxhn66fZn8tBflrroBClCk+YLvloRn9z7iZE4j8Sw2ykvbjx Y1QW46G65zRaT2se+BC7deKUzeIrDaqSLeUQT+WISSklIwB8R0H64VOyGEcJe6VKXTyL t+1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=/fORlfG/7fZ3d6+JBtFGDwuKFFIjJHHi7ulGr6I7Z4I=; fh=BMrqFqRQ2WHGRnmRu53LS5i9efVVQsAAbh8qxjUt2yo=; b=vXK/Opas/WHEyMv4Umaz1IcBLUeKE1t0UJkjLcAOzWQ56MZ7KlvJCxk47mJMtb17l0 wsJ7V2u/COU/he1UHrPPc53s4g6EPo1W/BhqK9sxd0NyX92vXpCzobKd5NsyaMtE1w17 f6BcM/9FDOPs0PnlihBnAUAQqh6y91VZWYFHETNtfOuf0TAWA8/NgA6ANLjJ1XuV1WCz d1VDl9LJNijrqPhLt6ZpNqfGeCcYbjvXB16yHdyeftLFGi3v8BGk3HaiSbrTgmlfdqWz S3tOsGM72/Ynw2R+w1UWXmJaQmfjraEbREa/p3XIKn1L5s6Nhet+cPT3VhVGBY9YpJWC Ja0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ahNPY3Aw; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-72407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l15-20020a62be0f000000b006e0f5035c4fsi5733805pff.127.2024.02.19.22.45.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:45:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ahNPY3Aw; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-72407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 57F3228542E for ; Tue, 20 Feb 2024 06:27:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D56C59159; Tue, 20 Feb 2024 06:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ahNPY3Aw" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 09CCD59149 for ; Tue, 20 Feb 2024 06:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708410426; cv=none; b=lKCaCbxJBBvr2hhDKAY6sThCooKPB2s8FzSa3gLGqLxxh0WAQhWhSauUrLRnJqj7yb0IC14mR6SR+PSB8GC73u7IjTxZr1444MS3NEoaT7a93OqE1gSbKYfHQAoWeOLGryXZPdhvyLudRqiVyxnYpOx4MNJcmwTFwXptDNAQ6FE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708410426; c=relaxed/simple; bh=KjbpEsZcL6BLoOczV14V5gdnm8XEq0JhlG2bKfRK0nA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=N8NDgOyr9WxlvFQP7UEf5UX50vyBJNYiuVh5vJEqXYyER3Ga2FzhFlSqYzXwOI8szo4tkK7GabdlQVYN7g4AvHpWcGK4JyJz+FiRY0BFdSZp6qhUmEEhkBPE3yInJXK04tu73t8Ld0wBp3VKPGpQHUQ4sfHJ9mjH3/Oout/ix6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ahNPY3Aw; arc=none smtp.client-ip=198.175.65.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708410425; x=1739946425; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=KjbpEsZcL6BLoOczV14V5gdnm8XEq0JhlG2bKfRK0nA=; b=ahNPY3AwbFpLa1SEt8FpZlVYc7uXRENmfD3+JEIXDWf4YbT9jwaw1BFU D2FrjcrVC+uY0viMwO70++sif4yJBDndP5PXktGBalm/MPicDfIRvmrRd vJl7f7GXjOUL+0rNQiZ2PB/aavaJjOFub3QCjjppHz2KnP/VchcE6TssA rMreKARDjUm9W6aotACujfOsbW1Qo0Nq8Va9j0noPb20SejPKb9VlYq1q UvVT3qGWlBdEb5d/EZN30av/izDfKJ2U49yYOmXOe2PpSup4fIu9vgg/0 sd3G8Nu3yGiaJsaiB5mTk6EE2kJJBZCRmFq17QcwTHpmPh5cvH6NcrEde A==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="2401599" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="2401599" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2024 22:27:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="27842144" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2024 22:26:59 -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: <21f343fa-84a7-4539-91e2-6fc963dbfb62@kernel.org> (Aneesh Kumar K. V.'s message of "Tue, 20 Feb 2024 09:40:00 +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> Date: Tue, 20 Feb 2024 14:25:03 +0800 Message-ID: <87frxnps8w.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii "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. -- Best Regards, Huang, Ying