Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4749498ybh; Tue, 6 Aug 2019 17:32:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdmR9EydPXl4iB9wlGGZdSB1a8bm0zLIzK9IXPC948cMNj4h51qDlHjyMU3ngz/DQ7/zl4 X-Received: by 2002:a17:902:3341:: with SMTP id a59mr5542598plc.186.1565137948631; Tue, 06 Aug 2019 17:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565137948; cv=none; d=google.com; s=arc-20160816; b=rpMNw8px5XRGKvg4xVUkZ/X7AC12Rp9RaRyRFG1PW3zZ/+LYOPQDJ4ruP6ObnKohKB JtkXe2uAgJcWx/mPClvXFC2+RUM0effHWqR35fIJ5MTJb5unox/0jguKwK5XIDPAMyM3 /WfGe5CM+xVXzrDrjCOBYMemI730AASh3S6yUmv5ao9GZwedGvomGBy7voMrq0uCwN4Y nxduNrspye/tj3/PKZm9hHvdCpDrajlBDqb8AO8LslF86yI57tRbN7E03Xj7hixPMAhd lVIiXPfy5f8WFyHMEX1M3oVjgLrDlatZRxMH6D3BnL2nSj16urpC3nxN0bCu1wf4Gb5m BbxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=SySmh9v0GsDAOq2yi8gIRmrsRpj1/7GNlPLQ68dhFiA=; b=fiMv23W7fJ8sL+L6vVGeI5CWkz/k3uolwCEOL4Sp0R1pT9Le81DAjUbIAD9N1V+OLE fydJf4thZj8AzJ3vpbEockM2sSpOfi64EPnkF5LwMem4lA7RP9RVtgl6jcvLfExZLwzZ Q5CvSViAl22z4bGZ0UJe3Ym1rNV2CSh91p3XHeLTCY+50TF12O6WKf0+JMrFNba4DxLV awIw1Gv5CLNo+Oor+7/ksPEJvNxa1a9bjqULIR28rkcN2UWuDwUXybax3X/izw8sUmFt 3uB1J8Ge25hXTN0vXhHG6tmiwW9Do3qJ+9Ty5F5Rrn4mimnqaEXPrAXQJHiAAdZqJRB7 aZIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si11117124pgv.106.2019.08.06.17.32.13; Tue, 06 Aug 2019 17:32:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727877AbfHGAbe (ORCPT + 99 others); Tue, 6 Aug 2019 20:31:34 -0400 Received: from mga01.intel.com ([192.55.52.88]:58950 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbfHGAbd (ORCPT ); Tue, 6 Aug 2019 20:31:33 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 17:31:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,353,1559545200"; d="scan'208";a="176033856" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga007.fm.intel.com with ESMTP; 06 Aug 2019 17:31:31 -0700 Date: Wed, 7 Aug 2019 08:31:09 +0800 From: Wei Yang To: Vlastimil Babka Cc: Wei Yang , akpm@linux-foundation.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/mmap.c: refine data locality of find_vma_prev Message-ID: <20190807003109.GB24750@richard> Reply-To: Wei Yang References: <20190806081123.22334-1-richardw.yang@linux.intel.com> <3e57ba64-732b-d5be-1ad6-eecc731ef405@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3e57ba64-732b-d5be-1ad6-eecc731ef405@suse.cz> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 06, 2019 at 11:29:52AM +0200, Vlastimil Babka wrote: >On 8/6/19 10:11 AM, Wei Yang wrote: >> When addr is out of the range of the whole rb_tree, pprev will points to >> the biggest node. find_vma_prev gets is by going through the right most > >s/biggest/last/ ? or right-most? > >> node of the tree. >> >> Since only the last node is the one it is looking for, it is not >> necessary to assign pprev to those middle stage nodes. By assigning >> pprev to the last node directly, it tries to improve the function >> locality a little. > >In the end, it will always write to the cacheline of pprev. The caller has most >likely have it on stack, so it's already hot, and there's no other CPU stealing >it. So I don't understand where the improved locality comes from. The compiler >can also optimize the patched code so the assembly is identical to the previous >code, or vice versa. Did you check for differences? Vlastimil Thanks for your comment. I believe you get a point. I may not use the word locality. This patch tries to reduce some unnecessary assignment of pprev. Original code would assign the value on each node during iteration, this is what I want to reduce. The generated code looks different from my side. Would you mind sharing me how you compare the generated code? > >The previous code is somewhat more obvious to me, so unless I'm missing >something, readability and less churn suggests to not change. > >> Signed-off-by: Wei Yang >> --- >> mm/mmap.c | 7 +++---- >> 1 file changed, 3 insertions(+), 4 deletions(-) >> >> diff --git a/mm/mmap.c b/mm/mmap.c >> index 7e8c3e8ae75f..284bc7e51f9c 100644 >> --- a/mm/mmap.c >> +++ b/mm/mmap.c >> @@ -2271,11 +2271,10 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr, >> *pprev = vma->vm_prev; >> } else { >> struct rb_node *rb_node = mm->mm_rb.rb_node; >> - *pprev = NULL; >> - while (rb_node) { >> - *pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb); >> + while (rb_node && rb_node->rb_right) >> rb_node = rb_node->rb_right; >> - } >> + *pprev = rb_node ? NULL >> + : rb_entry(rb_node, struct vm_area_struct, vm_rb); >> } >> return vma; >> } >> -- Wei Yang Help you, Help me