Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1570692rdb; Mon, 19 Feb 2024 23:24:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVaqYeyOSD0vZgAT/t4ZXEqX9U11518NRNDvzP0nCOjpY1tsXcS2KUVh1pKcnSyLKFtAULV8XkaKwIgyNUWwnj3P75ck2qiOUM69Yh9xw== X-Google-Smtp-Source: AGHT+IG2gAT78KblxXCpp78v06/r58HcrStl/KJ52LItDVwJggZBWZtl/D3UmUH+wAXmvW5HJjE8 X-Received: by 2002:a0d:ec0c:0:b0:604:727c:695 with SMTP id q12-20020a0dec0c000000b00604727c0695mr11241894ywn.42.1708413866492; Mon, 19 Feb 2024 23:24:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708413866; cv=pass; d=google.com; s=arc-20160816; b=vGuWVxF2+ltYfZ4dRoAmUgecFu4iVRuOQWqc1VpGAvGQ4RZKr/Oyg+CS/AcKLRkiIQ fjJGvboRtwdFdV1XE3V5yF3rcxQ8dsRtW9KFEAIkfpg4das+XHTSVCPK+Qeg20AR/+lW PGFQidqGFgjINOT7SDcp2FK/WMrViJTo8E0L5wkUCnfefusIrxmEjkeR2ETU1UNgTT9X sLKqTnehMmR5YjYiAfkAGtkzfhfYwUuHPSPFwnNcWyhDJ7NGkCI5pKVIIwoH8r8bpJjT +J3gYJaoB81vitr+qya5mE2SROAdxazsCGR8H7jIqtifhAxPvmSM0aGFbjK772xz79HT 4a1A== 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=QRjkKZgBGi7a/EqceLg0R+IBVCqd7uZtpjflkCSGEXk=; fh=BMrqFqRQ2WHGRnmRu53LS5i9efVVQsAAbh8qxjUt2yo=; b=a5AHohw+70WKkdM2Qbk9MVaso4DVsrDbzYiAtEBzBhyodbekjJbV2Klzri857Arvr7 mXaGUocB4lFNs/kYmB6tRqxcZ+kmv47JBfqgQz3vifAydkQiq+pedJ5qp6Dx7ZXsjczX NFq/9KNAqp+GI8NCAsL+FpirAdI15qHIgGPRzEOvaXI7lcPKSVysfVB5J2slf1Jrcelp nzRXDQw9VmdMkXVXlyrIDujFSbyQ8i2xd+m+lRvlDxtVUF9l3QzYpajK8RfZ5+T54s2B reNYvVkXklDFRBHOcTVHDX7pdPYpgRqMu9k94mC/Pj+593dQ+ZP0l2d1B2zmlS4b1oGl t57A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mp6J7VeG; 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-72467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72467-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i23-20020ac84897000000b0042bf3ea8991si7687977qtq.320.2024.02.19.23.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 23:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mp6J7VeG; 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-72467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72467-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C53B1C21A78 for ; Tue, 20 Feb 2024 07:24:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E67955B5CE; Tue, 20 Feb 2024 07:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Mp6J7VeG" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 9AEC45B5AF for ; Tue, 20 Feb 2024 07:24:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708413851; cv=none; b=YDNRus/VGwM/aifzOcPfmqYRaM3eoW6VK0e6yFRpwokBWlcRIwPpElxLPYthdfEgGk2mqTXnc957HD9kl6exwWNsaCwbGAuVRWrU9YkQFVyqseHt8kixahgPBnPt95eMBhbp+RtFEeibZkbnDxWbXMU/JeSkZ4k6L1pcCyN9zsY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708413851; c=relaxed/simple; bh=RtNRRa18GwhwVog0vEFc0loPHQWu4i5Y/0NbpjoyX9w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=CnH87wY3UMYGl92ATAoGf9IbIdQf74e23FMZWVJZtL+Bfo8KEQ4cktg+qqUF84/mEu8mYzyoqRTZYwHhzWz+xyYvFF7IRri5y1qTKklI1yBC55wKQrkcoBabksSUALMTKcKqx0UBkVTSShjLhfxKOQQ6YlKayAaF57soemOrodA= 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=Mp6J7VeG; arc=none smtp.client-ip=192.198.163.7 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=1708413848; x=1739949848; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=RtNRRa18GwhwVog0vEFc0loPHQWu4i5Y/0NbpjoyX9w=; b=Mp6J7VeGQc7ulZzo+fH/nTbOZCiJb6nE5UIbRKPTYK2ULoJDMkGJH0Bh 69pbxgJ7PkNJmFYMtqEZoc5qzaS96s5+YoEEgLlNcYg9HdrtVMjkTS5F7 HnSdmXVfK2KfXsNomD1bB8mcwjebtu3bKfe+90+s9kVFHc1PF0dM5EMOT CEHE9JdJc7VaYo8Lu+JiS++DOVXWsyYaB7/58JRD/apfVAl8sKPfEQHbR XKY7wBpBA3V4oIdQWb2r0co+QnkmbEGHKMkA6rw/JY+UQPssYuIx6p8Dp bP8ps0pcRQaCa94yn6DZlq6aKJFKUHaFe+Yf93ei3yfGcA6byDbIGNMYl w==; X-IronPort-AV: E=McAfee;i="6600,9927,10989"; a="27947376" X-IronPort-AV: E=Sophos;i="6.06,172,1705392000"; d="scan'208";a="27947376" 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) 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 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