Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6253172ybh; Wed, 7 Aug 2019 20:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyv/6WH9LU5Vkv4iQ/exxgyFAI88/PgxtdTMh1awlkB784NLLzGByWfr6P8+qSJ9Ty3stQR X-Received: by 2002:a17:902:4c:: with SMTP id 70mr11315746pla.308.1565234900210; Wed, 07 Aug 2019 20:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565234900; cv=none; d=google.com; s=arc-20160816; b=voEf1GcO99fWfHph/vgyb6KOr+x8rTyzVkXbpgfcdRT5EBlsdmJggV3rVg5IT68M0A 5iapL7QC+9kHydSo98loigVRj4Zrx1I0bR2DsZgFdgZKnJknfZuJrsMgrvC6AKBA+l+I 0iSk0AxxyB02RrGQ3Ups0A54p1q7TRM6/2Wx1DM1NqhSj9rEGgIvf6wHOyGyYZ3szUs4 0iSi1zkjDDea1j02W1gbo5NptRImnI6XIToKN5OwBda6CWk9UdvN7dhTZm9yJMDbI8fq W2dB4rh6TWDlnX7IX/oEx42pXq7w35bvSvXXRpSlwJ15NmDxk+zxxERM9c9JOouJYtmU JESw== 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=ONx/jxyWsZmRyfYnFleBGFMIPyzgXzQefflrM1Nbgvc=; b=We1Q4hU5t0LCI5W/qkg9HgD1lO9xfZmketnoS8uhhKNuznG72a2kbW4hs7WuwJUgGG uWcNMlLqtyWUJ2/SLnhjMQhTcuPzd0C1/cfX+jWEhXcOqBSneXuD0126hlOKIzsb1bV7 vs3qZ4o5EQVviVymNJ3SIQLpOO9mmKSVJ4/UlyZQ9UnqSq7PAU4grj4iIhz4pFmcoU5J pPr/YBKtIY1RGFknx+Ye5G5KambK9hJDgEaE0318N4OACM56AcT0cbxsFq8qcWqBQ5K+ zolubwU++IGpHIH28dzJjQsyAUlLmdcivgxshUUtA1ev+ZPuBMdCsd1lN0dSpOJzBRRj 6gVQ== 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 a130si41556957pfa.7.2019.08.07.20.28.04; Wed, 07 Aug 2019 20:28:20 -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 S1730699AbfHHD1C (ORCPT + 99 others); Wed, 7 Aug 2019 23:27:02 -0400 Received: from mga04.intel.com ([192.55.52.120]:48657 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbfHHD1C (ORCPT ); Wed, 7 Aug 2019 23:27:02 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2019 20:27:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,360,1559545200"; d="scan'208";a="203426188" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga002.fm.intel.com with ESMTP; 07 Aug 2019 20:27:01 -0700 Date: Thu, 8 Aug 2019 11:26:38 +0800 From: Wei Yang To: Michal Hocko Cc: Wei Yang , Vlastimil Babka , akpm@linux-foundation.org, 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: <20190808032638.GA28138@richard> Reply-To: Wei Yang References: <20190806081123.22334-1-richardw.yang@linux.intel.com> <3e57ba64-732b-d5be-1ad6-eecc731ef405@suse.cz> <20190807003109.GB24750@richard> <20190807075101.GN11812@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190807075101.GN11812@dhcp22.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 Wed, Aug 07, 2019 at 09:51:01AM +0200, Michal Hocko wrote: >On Wed 07-08-19 08:31:09, Wei Yang wrote: >> 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. > >Is there any measurable difference (on micro benchmarks or regular >workloads)? I wrote a test case to compare these two methods, but not find visible difference in run time. While I found we may leverage rb_last to refine the code a little. @@ -2270,12 +2270,9 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr, if (vma) { *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); - rb_node = rb_node->rb_right; - } + struct rb_node *rb_node = rb_last(&mm->mm_rb); + *pprev = !rb_node ? NULL : + rb_entry(rb_node, struct vm_area_struct, vm_rb); } return vma; Not sure this style would help a little in understanding the code? >-- >Michal Hocko >SUSE Labs -- Wei Yang Help you, Help me