Message ID | 9c3f7b743477560d1c5b12b8c111a584a2cc92ee.1708097962.git.donettom@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-69718-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp194951dyc; Fri, 16 Feb 2024 23:33:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNMFrv4/pDZCJ48XdS8mmLVEHRbgfB3c9ws2NFQdoiJwFQNCCeoOLD85vGhEpF5laGVeOu1mQVvVq007sqFhgquM5j5A== X-Google-Smtp-Source: AGHT+IEMuKOSmPC7mT0Aw/K3CEU1c3u2acQp7rV/MJfDRAehOwIMLcuVScktmW3Ue9OQc+LFDmK6 X-Received: by 2002:a17:906:b785:b0:a3d:6160:fcca with SMTP id dt5-20020a170906b78500b00a3d6160fccamr5344730ejb.69.1708155203114; Fri, 16 Feb 2024 23:33:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708155203; cv=pass; d=google.com; s=arc-20160816; b=PP+sJekULraZa2mBp/JD7/RnHNZmJSUiUgIDgVtx1kovvhdOjVqTpyRnUp7HFoVsTZ FRQ7BAVI1iLcLsm5SwWY90DQWTkkCUB5JjHjcCsRsJIb6NXiFYAH8HjjvKFKEeR/w8yi d7ZcwbB7/0E/lumuI+DrroJ8tdEwINyChesC2jJdMeWGEss+3bCiRcI3WP4e9MYmL4ES I43hOR4AacVZrixL6jDkXZIjGKHcEzE2AwDiDIQzK2M5gcNeUiWDpRLWcoZZMXI6tCv7 9u82NIhyZNBwNn5kpvp4iGn7ev9/FFuYeXZa1SL8/gYLEiizM0M2x/c6zsYeDewGbnpu /muQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=JMT3nuMNp6lUin7O78tqTAkdQ8dhNushNKvFxaKIJGA=; fh=FFcNRKX/cmmdEO/4OCJX4rYOGTYmFqpwDil6Wds3ioM=; b=oqkGvejqya75AehkCIGShB3TUInjx/+W8OI8yivuauW0LFwJ6rqXUCNj7fpiLRZckP WtycjHAGPiyGeCstmxQpUX/xwfjp9bL1EZeKjjrM1VWAxK4+WkWcftU2Mzpxq1npTXHv 7U1vVKcucYteUHkzaprT1SoqoIEnN7aE7m0GRXo70trnuWR+8OWb0VCePYcEEzs1KJaC xY6Slexq5PUPRxt+gtJofww8qEq9PUjp4PXu5aN7nugJKmTJHtrUwLfRV2R2XMd63RXh IgZ131VwkWR72c9nCRT6N5UZnOzV5nCu1vb9V0p1qtUUplCcQrzd/YQ5HAgZ9ZNCO3+9 EluQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HixjXUQy; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-69718-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69718-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h17-20020a170906261100b00a3d9436a68csi646609ejc.396.2024.02.16.23.33.22 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 23:33:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69718-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=HixjXUQy; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-69718-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69718-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.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 am.mirrors.kernel.org (Postfix) with ESMTPS id B624D1F222B1 for <ouuuleilei@gmail.com>; Sat, 17 Feb 2024 07:33:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 513C91D6A7; Sat, 17 Feb 2024 07:32:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="HixjXUQy" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 25AC71CD2A for <linux-kernel@vger.kernel.org>; Sat, 17 Feb 2024 07:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708155162; cv=none; b=Hq4Bb5vQmVrJfiMw+apWoU/FgxY+VhWPhob3ZyVJEjUYlTgN384A7svL3gQM9jBf4dxw1I7EylcDQOvSmriaaEPT8nHuHo1lKPOpZbJfPWLw6srfOXLLJ1ilHpsikvS2AP3lW3C2ipDGVaQ/XzjeH8enCja/VkZRDAkx1YF65Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708155162; c=relaxed/simple; bh=syzmM7eUW3w//SDCJMEcCcBIvXx2NkPHU3sbMpurQzU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=l9EjVtrs054TPLDoG0WAb8tWBLDf7jKmbvK8SzjvXCkOt2KoAcbcRsw+YSCYUrzeCNSHd/l46rYJwlPsgUYkxnJVBaumpNqiXi3aHS7mKmla43BuNDeoZkgimyIdN3Ljo7cN994YSUXXNuA2Qq5pnAw3sivs67BIYotiPPmg9jc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=HixjXUQy; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41H7AiHE020961; Sat, 17 Feb 2024 07:31:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=JMT3nuMNp6lUin7O78tqTAkdQ8dhNushNKvFxaKIJGA=; b=HixjXUQyKmHu24W/4DHsxhCHLYc/8h9qS3qNDFTbYmNNTm2gYc+dMzVk8q5zHTSdSkVl uSN5Bg/Hui39aiOklBpz/fC+NIchMhpNqMWXimJsGInUlpxwDm7D4b8buwKg8P3luPvT 6o9dO60g8+2Tc+hiKeChPN02e/Ximz3hR1kCJmqLGdOHUGzk4ex1qFt97nIatHyEqh9r 6KnEpPibprbboseZ2E0PKOG6kddssOV2LvOSlkNukyyZQATJN6Uz+Jt/3E3Vh3dlseeh 4R8E5haMZ1gBoqm2SUYNbsvUA23BHFs+JAFQ573JVnVQjIVxS4mIVseyU2PFEZ7MqPdg 1g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3waq8h0s0g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 07:31:46 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41H7U7ia027144; Sat, 17 Feb 2024 07:31:45 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3waq8h0ryy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 07:31:45 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41H623IR004247; Sat, 17 Feb 2024 07:31:44 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6kv10tun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Feb 2024 07:31:43 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41H7Vdn423986786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 17 Feb 2024 07:31:42 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D65542004E; Sat, 17 Feb 2024 07:31:39 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B043420040; Sat, 17 Feb 2024 07:31:36 +0000 (GMT) Received: from ltczz402-lp1.aus.stglabs.ibm.com (unknown [9.53.171.174]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Sat, 17 Feb 2024 07:31:36 +0000 (GMT) From: Donet Tom <donettom@linux.ibm.com> To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Aneesh Kumar <aneesh.kumar@kernel.org>, Huang Ying <ying.huang@intel.com>, Dave Hansen <dave.hansen@linux.intel.com>, Mel Gorman <mgorman@suse.de>, Ben Widawsky <ben.widawsky@intel.com>, Feng Tang <feng.tang@intel.com>, Michal Hocko <mhocko@kernel.org>, Andrea Arcangeli <aarcange@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Rik van Riel <riel@surriel.com>, Johannes Weiner <hannes@cmpxchg.org>, Matthew Wilcox <willy@infradead.org>, Mike Kravetz <mike.kravetz@oracle.com>, Vlastimil Babka <vbabka@suse.cz>, Dan Williams <dan.j.williams@intel.com>, Hugh Dickins <hughd@google.com>, Kefeng Wang <wangkefeng.wang@huawei.com>, Suren Baghdasaryan <surenb@google.com> Subject: [PATCH 1/3] mm/mempolicy: Use the already fetched local variable Date: Sat, 17 Feb 2024 01:31:33 -0600 Message-Id: <9c3f7b743477560d1c5b12b8c111a584a2cc92ee.1708097962.git.donettom@linux.ibm.com> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DMqtCxbRPBcpizXWL_iXGokDYCRMYDlh X-Proofpoint-ORIG-GUID: ALbNl9CNixSrLoK-j4d-SrAX7YQwG9Md X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-17_04,2024-02-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 priorityscore=1501 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402170058 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791130550258738314 X-GMAIL-MSGID: 1791130550258738314 |
Series |
[1/3] mm/mempolicy: Use the already fetched local variable
|
|
Commit Message
Donet Tom
Feb. 17, 2024, 7:31 a.m. UTC
Avoid doing a per cpu read and use the local variable thisnid. IMHO this also makes the code more readable. Signed-off-by: Aneesh Kumar K.V (IBM) <aneesh.kumar@kernel.org> Signed-off-by: Donet Tom <donettom@linux.ibm.com> --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Sat, 17 Feb 2024 01:31:33 -0600 Donet Tom <donettom@linux.ibm.com> wrote: > Avoid doing a per cpu read and use the local variable thisnid. IMHO > this also makes the code more readable. > > ... > > --- 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?
On 2/19/24 03:08, Andrew Morton wrote: > On Sat, 17 Feb 2024 01:31:33 -0600 Donet Tom <donettom@linux.ibm.com> wrote: > >> Avoid doing a per cpu read and use the local variable thisnid. IMHO >> this also makes the code more readable. >> >> ... >> >> --- 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. Thanks Donet Tom >
On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom <donettom@linux.ibm.com> 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?
On 2/20/24 6:51 AM, Andrew Morton wrote: > On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom <donettom@linux.ibm.com> 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(). -aneesh
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org> writes: > On 2/20/24 6:51 AM, Andrew Morton wrote: >> On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom <donettom@linux.ibm.com> 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
On 2/20/24 11:55 AM, Huang, Ying wrote: > "Aneesh Kumar K.V" <aneesh.kumar@kernel.org> writes: > >> On 2/20/24 6:51 AM, Andrew Morton wrote: >>> On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom <donettom@linux.ibm.com> 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
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" <aneesh.kumar@kernel.org> writes: >> >>> On 2/20/24 6:51 AM, Andrew Morton wrote: >>>> On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom <donettom@linux.ibm.com> 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. -aneesh
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org> 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" <aneesh.kumar@kernel.org> writes: >>> >>>> On 2/20/24 6:51 AM, Andrew Morton wrote: >>>>> On Mon, 19 Feb 2024 14:04:23 +0530 Donet Tom <donettom@linux.ibm.com> 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
On Tue 20-02-24 15:22:07, Huang, Ying wrote: [...] > This isn't an issue now, because mpol_misplaced() are always called with > PTL held. And, we can still keep thiscpu local variable. yes, this is the case but it would be better if we made that assumption official by lockdep_assert_held
Michal Hocko <mhocko@suse.com> writes: > On Tue 20-02-24 15:22:07, Huang, Ying wrote: > [...] >> This isn't an issue now, because mpol_misplaced() are always called with >> PTL held. And, we can still keep thiscpu local variable. > > yes, this is the case but it would be better if we made that assumption > official by lockdep_assert_held > How about this folded into this patch? 2 files changed, 12 insertions(+), 4 deletions(-) mm/memory.c | 6 ++++-- mm/mempolicy.c | 10 ++++++++-- modified mm/memory.c @@ -4879,9 +4879,11 @@ static vm_fault_t do_fault(struct vm_fault *vmf) return ret; } -int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, +int numa_migrate_prep(struct folio *folio, struct vm_fault *vmf, unsigned long addr, int page_nid, int *flags) { + struct vm_area_struct *vma = vmf->vma; + folio_get(folio); /* Record the current PID acceesing VMA */ @@ -4893,7 +4895,7 @@ int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, *flags |= TNF_FAULT_LOCAL; } - return mpol_misplaced(folio, vma, addr); + return mpol_misplaced(folio, vmf, addr); } static vm_fault_t do_numa_page(struct vm_fault *vmf) modified mm/mempolicy.c @@ -2495,18 +2495,24 @@ static inline bool mpol_preferred_should_numa_migrate(int exec_node, int folio_n * Return: NUMA_NO_NODE if the page is in a node that is valid for this * policy, or a suitable node ID to allocate a replacement folio from. */ -int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, +int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, unsigned long addr) { struct mempolicy *pol; pgoff_t ilx; struct zoneref *z; int curnid = folio_nid(folio); + struct vm_area_struct *vma = vmf->vma; 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; + /* + * Make sure ptl is held so that we don't preempt and we + * have a stable smp processor id + */ + lockdep_assert_held(vmf->ptl); pol = get_vma_policy(vma, addr, folio_order(folio), &ilx); if (!(pol->flags & MPOL_F_MOF)) goto out; [back]
Aneesh Kumar K.V <aneesh.kumar@kernel.org> writes: > Michal Hocko <mhocko@suse.com> writes: > >> On Tue 20-02-24 15:22:07, Huang, Ying wrote: >> [...] >>> This isn't an issue now, because mpol_misplaced() are always called with >>> PTL held. And, we can still keep thiscpu local variable. >> >> yes, this is the case but it would be better if we made that assumption >> official by lockdep_assert_held >> > > How about this folded into this patch? > > 2 files changed, 12 insertions(+), 4 deletions(-) > mm/memory.c | 6 ++++-- > mm/mempolicy.c | 10 ++++++++-- > > modified mm/memory.c > @@ -4879,9 +4879,11 @@ static vm_fault_t do_fault(struct vm_fault *vmf) > return ret; > } > > -int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, > +int numa_migrate_prep(struct folio *folio, struct vm_fault *vmf, > unsigned long addr, int page_nid, int *flags) > { > + struct vm_area_struct *vma = vmf->vma; > + > folio_get(folio); > > /* Record the current PID acceesing VMA */ > @@ -4893,7 +4895,7 @@ int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma, > *flags |= TNF_FAULT_LOCAL; > } > > - return mpol_misplaced(folio, vma, addr); > + return mpol_misplaced(folio, vmf, addr); > } > > static vm_fault_t do_numa_page(struct vm_fault *vmf) > modified mm/mempolicy.c > @@ -2495,18 +2495,24 @@ static inline bool mpol_preferred_should_numa_migrate(int exec_node, int folio_n > * Return: NUMA_NO_NODE if the page is in a node that is valid for this > * policy, or a suitable node ID to allocate a replacement folio from. > */ > -int mpol_misplaced(struct folio *folio, struct vm_area_struct *vma, > +int mpol_misplaced(struct folio *folio, struct vm_fault *vmf, > unsigned long addr) > { > struct mempolicy *pol; > pgoff_t ilx; > struct zoneref *z; > int curnid = folio_nid(folio); > + struct vm_area_struct *vma = vmf->vma; > 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; > > + /* > + * Make sure ptl is held so that we don't preempt and we > + * have a stable smp processor id > + */ > + lockdep_assert_held(vmf->ptl); > pol = get_vma_policy(vma, addr, folio_order(folio), &ilx); > if (!(pol->flags & MPOL_F_MOF)) > goto out; > > [back] > LGTM, Thanks! -- Best Regards, Huang, Ying
diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 10a590ee1c89..8478574c000c 100644 --- 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);