Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3787839ybh; Tue, 6 Aug 2019 01:20:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLc//13fn3x2IiwHHHtxbyCFXcjYnOMKoeVDAkqxW3zW7qSbr3TqBjLD0mW2hZoTgNCEYs X-Received: by 2002:a63:724f:: with SMTP id c15mr1976020pgn.257.1565079604638; Tue, 06 Aug 2019 01:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565079604; cv=none; d=google.com; s=arc-20160816; b=QYaocJU7+8vkTNkVNnvA/Q8pqkQeOANuPENO6px5aeRqaXwZwoG9u94O/o7/imWsvb QWqkhRp2NEddmPY1ro7gYH+l5Wyj7H28AhLz3wk+w+hBVV3Uxyp6PshstxsFDAvz2vlE d3F5hSpz3HrOahmRlWcih7ucQ7S0mEQqCQ4rlClV6bqqcKi0v/+rKF6B5qnquoXRA5T1 mzWIzf6Q76Ez4MHQMfzZM5gIxftC5Cu8pIAhzLM5VUeA1i/q6B2vbtb4wmnwt8VgoDUC b0wWsp3sTkjYgRVOIh0BO1RQQkjtK3OCBaDFRaTcTJpRIuMWH4AvsgrCu6fkRbVJrBgU w1DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=tKyFaqoYLiLE8zFE9yQm610ngJHuDZlGyPi6JHiIzME=; b=PSthVYDCuemTRbUQ+cTuDKar5RCsEVDwXiIUmCfD5yBfotLN3Av4kh+omUsnZ0/M8E 8N4kIL9CnCG+2gBZKn3Tk6lRrkSTXhxs2oZMC4+RNBQnzZwPGkwFjVuGXD4iBc20O82k YRqij3cE9uZipw6T1GGmm8LRqTD4VpMpehNxGqjx2K7FiyV0jQYU+1xKLHW/+K/hDyWk GNXSoh86DgWRbOHu04MRElC71+lxsXk0Ah0iNQ+DWWTw6TkQSQkXIbIi7FKRWwdvaQi7 MU+rqUAUeuFXM6s+VK4JaOoGXyxrQx9Pu5JA99j0MCIriTwiO34LV7e7+qGj5lgSkZCI DVzQ== 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 q2si14337343pjv.99.2019.08.06.01.19.48; Tue, 06 Aug 2019 01:20:04 -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 S1732045AbfHFITJ (ORCPT + 99 others); Tue, 6 Aug 2019 04:19:09 -0400 Received: from mga02.intel.com ([134.134.136.20]:35535 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728918AbfHFITJ (ORCPT ); Tue, 6 Aug 2019 04:19:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 01:11:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,352,1559545200"; d="scan'208";a="176561599" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga003.jf.intel.com with ESMTP; 06 Aug 2019 01:11:48 -0700 From: Wei Yang To: akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, kirill.shutemov@linux.intel.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] mm/mmap.c: refine data locality of find_vma_prev Date: Tue, 6 Aug 2019 16:11:23 +0800 Message-Id: <20190806081123.22334-1-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } return vma; } -- 2.17.1