Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1564197rdb; Mon, 19 Feb 2024 23:05:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0SiC9Z4C4KMAhFNBYjtxLzrJurgKpg6QVxF5k/vnIoyyvsiq/KFDB5Fneu74hTj1LLoTpmYQPHky8igFfdA0rK2266st06WZLDL9Dkg== X-Google-Smtp-Source: AGHT+IHGu3qN+6xO5xHsTQftPHIyzRYM2iDFeAJlEGVu2GAoVLfs72N/0UDghoLyHA/7o0bXfY6s X-Received: by 2002:a05:6402:2b8f:b0:561:3704:329c with SMTP id fj15-20020a0564022b8f00b005613704329cmr17196308edb.8.1708412725509; Mon, 19 Feb 2024 23:05:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708412725; cv=pass; d=google.com; s=arc-20160816; b=qwIwidkH/NIdJL51F1niq5IRl3WMgmcaOEwhJVm+yFQcQCDnqsdfZ+LPxDXByY36hk cJI1sS8E0bt+xOLt4mkEhrFaCPJs7Hkeea+yCcvCA0OEOR0JB+xESwFIm0hxHHigNx84 1CLwJ+ebqDuD7jo8BNLuLbhw6ojPRwyh3RBErX/AoZe5PZ/EP19eF4/686vklCqHufzP Fmxi0i48bok9KkFEkYjGY7ygzOesVwT2f1Kc9P4vgWFhKaWfz5s3gPJ2VLVObb2Ky5kO 1oUx2He/LFoSP5KcJ+N1gDvlk4CL7k3R4gtr6c6BnTPGEkCwaptOxkinPgDv8WpxL3UK TEfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=KdOjHjiupR+ABzI1zHhISTUtJTjf45sXi6PmRiZ+npk=; fh=mGKSn6bTzTiM4MDLA1I1Y7WlX71TzvSVcq61488NLYY=; b=LJFWMaXWll4n07oL+/Wv6r85bXce9PCP+ItClKIl96CoPEYJ1jP8sHlNFGPGjPjmti 6eGRrNqms6mPHRQvymaDhl7WQRCXFuO9OmnTjXscEnz8EoyLA1cpu1CiZ8dgf7Wt8VQ6 3O3PY500KyiMecAhd8I70h0oAeEAyhOjGcd7Gc1xCuZUGWUWzuQcrMqAJgx1M3NYO/Q0 SAGEviJYkaZMVrArWTwAEOR0SMNK/XXLU3oJfeMv42sm/fXSQreE+9iCQG8gD/IxVWMO 7HW3+J4N7n8IOGUkZdclJgMWCVu0RqySt4eJ4ArpdxJVg03vGHEu0CHwk3dCUTDsHQYd ze9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zi6tPaWa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-72448-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72448-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d29-20020a056402401d00b0056477920953si1557298eda.296.2024.02.19.23.05.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 23:05:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72448-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Zi6tPaWa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-72448-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72448-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 46D5F1F22670 for ; Tue, 20 Feb 2024 07:05:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D1C25B202; Tue, 20 Feb 2024 07:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Zi6tPaWa" 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 5031F5A7BF for ; Tue, 20 Feb 2024 07:04:00 +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=1708412641; cv=none; b=PzJgwhlJQ+a+wSlDpyql5bxWpfHkaDNdXs8pnsRZKZXDsc9IkLqd7XskJxcF38vhXkPaUB7vfJ3HRI5r5dGdL2JPyfbsiPz/HDKthqfUFTOhnr9wExJF65AKMcpcJKyw0NQE9RpL4h4mXUnOasK9f3ocXaV3WsHOtHk+B3+/SqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708412641; c=relaxed/simple; bh=PMQoz8O5HTzQHK/8qIlXhgJEFRcEgbpMwCdJThDc+fw=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Z+by43Ip2Pm/jvBRnksY93J9U8WNIesaRRASb7crtoVbXONFhcMymIRuD4A5Ww3vS6s/5WobgmmU7vD6OxxiQkosSzhsRd2f9MIvpGRFgXXZJVNGMyognNqdrsu/25glfbTC4AI30zwGFkF/tFNALwsSB2/+4yv/fIviv1mh2CI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zi6tPaWa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61638C433C7; Tue, 20 Feb 2024 07:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708412640; bh=PMQoz8O5HTzQHK/8qIlXhgJEFRcEgbpMwCdJThDc+fw=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=Zi6tPaWauef5T/Nrx1WvQcsey8zBCfJYKhuNwG4sQVYWSgEn4RyMBl1F2VIw/qSHc TPvDCayTZeuLIBnW9CapdThhB5qgi9Wx6l+ub9jpClL9IhO0+nfGkGNAldSOLlk+SY Vu3n1T/jP9+re25D1PeOen5sX+lktNX7f6TBb/7jS7jFGiu+NwvldGNnBTijzy+wRl gLwNabtb+XH6AJmMeHNnZxc/cKi000RPpKfksdoi2faTxZucxAHLA9pR/JdiPLZceV PfZHT0G47zBC4gTe3NArvuVNU5Qj2TQKOMJXj+LjpIj5QYaC9uLIRxskAB5sEKsFi1 L/CbHRRFRQOCw== Message-ID: Date: Tue, 20 Feb 2024 12:33:51 +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 From: "Aneesh Kumar K.V" 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> <7097ff95-6077-4744-a770-b90d224c0c9b@kernel.org> In-Reply-To: <7097ff95-6077-4744-a770-b90d224c0c9b@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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. -aneesh