Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932832AbbLNVLl (ORCPT ); Mon, 14 Dec 2015 16:11:41 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:34777 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932377AbbLNVLf (ORCPT ); Mon, 14 Dec 2015 16:11:35 -0500 Date: Mon, 14 Dec 2015 23:11:32 +0200 From: "Kirill A. Shutemov" To: Oleg Nesterov Cc: yalin wang , akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, gang.chen.5i5j@gmail.com, mhocko@suse.com, kwapulinski.piotr@gmail.com, aarcange@redhat.com, dcashman@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC] mm: change find_vma() function Message-ID: <20151214211132.GA7390@node.shutemov.name> References: <1450090945-4020-1-git-send-email-yalin.wang2010@gmail.com> <20151214121107.GB4201@node.shutemov.name> <20151214175509.GA25681@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151214175509.GA25681@redhat.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2166 Lines: 67 On Mon, Dec 14, 2015 at 06:55:09PM +0100, Oleg Nesterov wrote: > On 12/14, Kirill A. Shutemov wrote: > > > > On Mon, Dec 14, 2015 at 07:02:25PM +0800, yalin wang wrote: > > > change find_vma() to break ealier when found the adderss > > > is not in any vma, don't need loop to search all vma. > > > > > > Signed-off-by: yalin wang > > > --- > > > mm/mmap.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/mm/mmap.c b/mm/mmap.c > > > index b513f20..8294c9b 100644 > > > --- a/mm/mmap.c > > > +++ b/mm/mmap.c > > > @@ -2064,6 +2064,9 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) > > > vma = tmp; > > > if (tmp->vm_start <= addr) > > > break; > > > + if (!tmp->vm_prev || tmp->vm_prev->vm_end <= addr) > > > + break; > > > + > > > > This 'break' would return 'tmp' as found vma. > > But this would be right? Hm. Right. Sorry for my tone. I think the right condition is 'tmp->vm_prev->vm_end < addr', not '<=' as vm_end is the first byte after the vma. But it's equivalent in practice here. Anyway, I don't think it's possible to gain anything measurable from this optimization. > > Not that I think this optimization makes sense, I simply do not know, > but to me this change looks technically correct at first glance... > > But the changelog is wrong or I missed something. This change can stop > the main loop earlier; if "tmp" is the first vma, For the first vma, we don't get anything comparing to what we have now: check for !rb_node on the next iteration would have the same trade off and effect as the proposed check. > or if the previous one is below the address. Yes, but would it compensate additional check on each 'tmp->vm_end > addr' iteration to the point? That's not obvious. > Or perhaps I just misread that "not in any vma" note in the changelog. > > No? > > Oleg. > -- Kirill A. Shutemov -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/