Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4750571ybh; Tue, 6 Aug 2019 17:33:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGv0CsONq1tBl1japkHNxtpYEmx7e6I6jfhP45UoSK+cDxCxO1tiT5I4TTBhboYcQAi3R9 X-Received: by 2002:aa7:8a92:: with SMTP id a18mr6602986pfc.216.1565138025175; Tue, 06 Aug 2019 17:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565138025; cv=none; d=google.com; s=arc-20160816; b=irBPYo1Jw6HbdTR9UpTWi/juMrK8a17f8d1ksI7Amxzv4cd1JZkG8GBB3JbxEIYIQj ISXGsCsitGDDfr+SKlgb074rQQcQvYaFPH7jJ80sUdrI9yCGSiiuRhtxGomROcZyMW6N CZbZ8ECYBf7b7vKnYYcO0THH4nQwtJ3e6pENiLlDBpYdK7idQc2LAluxyaa9WHjDdHLU sMdG/ORSlzVfb7o9McO2yr+7iymvtM6EImCGuNMN83dutQw12kcGZNss+XrzAKNX9zCd P5wMQmFfvBtoVe9Ph2NJ0FQ56BRQzuJ+6MzqnczqSEJKwsEznvprDVA45UnfQro7D+XC CChA== 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=G19LaDcw47KOsTDKeBQJ44iiFM5SdGYklrtzM0JqbqM=; b=NsFOZ6+TDgo3JSRbW+4TB7CwMbCk/1AMYqN61+PxA8M6uWacyb96jIt2FpkfKS83z8 y23fa6YAbOWkfmwKmoEDHhaldns3OQUqNeeOELnFr469J9wUn8TGoRd1Hp40I8ZOY4eM 0aXoLEbrChK/L5y6v+yxreisnHQpJR1JIBpM/52FsHEv9eciiQz/P8IAoEITSe0H5pt4 hndbs6QCgNVQvZZBLQ5G9yAcQ1ipvptzG+qd9ZWIJbDGDAMtJlAOez9pmSApe31SmN3I Pa5Vc4n0Zmxo3/QvCGxVahKKFAzX5xAF/iFPMKufTfvDKSkjhhwyyQn9evnbFXudzHeb Y8OQ== 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 y7si6708633pgj.486.2019.08.06.17.33.29; Tue, 06 Aug 2019 17:33:45 -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 S1727598AbfHGAck (ORCPT + 99 others); Tue, 6 Aug 2019 20:32:40 -0400 Received: from mga01.intel.com ([192.55.52.88]:59046 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726381AbfHGAcj (ORCPT ); Tue, 6 Aug 2019 20:32:39 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 17:32:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,353,1559545200"; d="scan'208";a="185828104" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga002.jf.intel.com with ESMTP; 06 Aug 2019 17:32:37 -0700 Date: Wed, 7 Aug 2019 08:32:14 +0800 From: Wei Yang To: Balbir Singh Cc: Wei Yang , akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, 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: <20190807003214.GC24750@richard> Reply-To: Wei Yang References: <20190806081123.22334-1-richardw.yang@linux.intel.com> <20190806105822.GA25354@dev-dsk-sblbir-2a-88e651b2.us-west-2.amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190806105822.GA25354@dev-dsk-sblbir-2a-88e651b2.us-west-2.amazon.com> 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 10:58:22AM +0000, Balbir Singh wrote: >On Tue, Aug 06, 2019 at 04:11:23PM +0800, 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 >> 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. >> >> 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); > >Can rb_node ever be NULL? assuming mm->mm_rb.rb_node is not NULL when we >enter here > My bad, it should be *pprev = !rb_node ? NULL : rb_entry(rb_node, struct vm_area_struct, vm_rb); Thanks >Balbir Singh -- Wei Yang Help you, Help me