From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4EBE0C433DB for ; Wed, 30 Dec 2020 18:42:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AAA6D20782 for ; Wed, 30 Dec 2020 18:42:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAA6D20782 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B0E388D00AB; Wed, 30 Dec 2020 13:42:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABDBC8D00A4; Wed, 30 Dec 2020 13:42:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AC9D8D00AB; Wed, 30 Dec 2020 13:42:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id 8295A8D00A4 for ; Wed, 30 Dec 2020 13:42:16 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 39479180AD801 for ; Wed, 30 Dec 2020 18:42:16 +0000 (UTC) X-FDA: 77650818672.11.iron47_4f10827274a7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 1129A180F8B80 for ; Wed, 30 Dec 2020 18:42:16 +0000 (UTC) X-HE-Tag: iron47_4f10827274a7 X-Filterd-Recvd-Size: 5292 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Dec 2020 18:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609353734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=z76dveQAkwEZ9/SbysrE4hP7PWAnMugEd3yDIGB+IuA=; b=fWel30qa8LLnUw/M+Lc9Mu7zhqIGfBXYIRJVWC5+GIfcpTtjWKpKzpwMTu7arudd92A46h MxvNnfvUJ9VpPa9COttjBN3T+C/lo29tI+tKLmqr+YqIZTZd3a510IqeqO/+9vXCEXTbQ9 IFkoed1R1GyMw0YwdFRcXBUwrjMcHaY= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-5bKg6VQwP3m64Qmb2B1k1g-1; Wed, 30 Dec 2020 13:42:12 -0500 X-MC-Unique: 5bKg6VQwP3m64Qmb2B1k1g-1 Received: by mail-qt1-f197.google.com with SMTP id h7so10099047qtn.21 for ; Wed, 30 Dec 2020 10:42:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=z76dveQAkwEZ9/SbysrE4hP7PWAnMugEd3yDIGB+IuA=; b=coQNMsWzkkoS1Advm8c7F1ezcDnt6jJW8CHmxmD2r9HJFpv0gut9TQ/xQJRLuJVZTO 2yl4vDiTm+Har3k6KxiGbMiauA0Ethx3fCxDG4RCj7KAj4V1co0a6nT7sEODEU4cNDV+ e6M1E8BfLpo+ULqnSi2y5oDpGrikuuLD+JJcUcV0XlXtpet3mYx/ce3tZ5Vmgxd0co6D ob7G/4WnC0sZ2wcZZWFve2nnBl00LIX1mBakjVUTEhiW4ZsSR0EHad/EuAQgcvP3TvuY /ULeyo/IfUuG/BbtCOKhju2RDZxQmCjrm1VY4BaO0X43isbnJpKejA/V/zgho8UHkHQV VdMg== X-Gm-Message-State: AOAM532me1rgSSCFzgKlnrZpvgBKgQsjzveXakKUVQoKGixxfqImABMr qoY34gcuGNdjnp1uBICHV3tl2qWUY8wdycTqqt7tGrga7TseeoxVIEqmN/YJwIldzRMTjJNUajP pKKSLfprTk30= X-Received: by 2002:aed:3b13:: with SMTP id p19mr54640897qte.302.1609353732416; Wed, 30 Dec 2020 10:42:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/4qIFtXJoMoaZ6tZbQYJ8rSB8ni+owvNxh9zsuOWSEjUTySX1SCuq3UpGV4carVL8eN9SnQ== X-Received: by 2002:aed:3b13:: with SMTP id p19mr54640877qte.302.1609353732189; Wed, 30 Dec 2020 10:42:12 -0800 (PST) Received: from xz-x1 ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id 17sm29770767qtu.23.2020.12.30.10.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 10:42:11 -0800 (PST) Date: Wed, 30 Dec 2020 13:42:19 -0500 From: Peter Xu To: Li Xinhai Cc: linux-mm@kvack.org, akpm@linux-foundation.org, Mike Kravetz Subject: Re: [PATCH] mm/hugetlb.c: fix unnecessary address expansion of pmd sharing Message-ID: <20201230184219.GB6605@xz-x1> References: <20201229042125.2663029-1-lixinhai.lxh@gmail.com> MIME-Version: 1.0 In-Reply-To: <20201229042125.2663029-1-lixinhai.lxh@gmail.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Dec 29, 2020 at 12:21:25PM +0800, Li Xinhai wrote: > The current code would unnecessarily expand the address range. Consider > one example, (start, end) = (1G-2M, 3G+2M), and (vm_start, vm_end) = > (1G-4M, 3G+4M), the expected adjustment should be keep (1G-2M, 3G+2M) > without expand. But the current result will be (1G-4M, 3G+4M). Actually, > the range (1G-4M, 1G) and (3G, 3G+4M) would never been involved in pmd > sharing. > > After this patch, if pud aligned *start across vm_start, then we know the > *start and vm_start are in same pud_index, and vm_start is not pud > aligned, so don't adjust *start. Same logic applied to *end. > > Fixes: commit 75802ca66354 ("mm/hugetlb: fix calculation of adjust_range_if_pmd_sharing_possible") > Cc: Mike Kravetz > Cc: Peter Xu > Signed-off-by: Li Xinhai > --- > mm/hugetlb.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index cbf32d2824fd..d1e9ea55b7e6 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -5249,11 +5249,16 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, > a_end = ALIGN(*end, PUD_SIZE); > > /* > - * Intersect the range with the vma range, since pmd sharing won't be > - * across vma after all > + * If the PUD aligned address across vma range, then it means the > + * vm_start/vm_end is not PUD aligned. In that case, we must don't > + * adjust range because pmd sharing is not possbile at the start and/or > + * end part of vma. > */ > - *start = max(vma->vm_start, a_start); > - *end = min(vma->vm_end, a_end); > + if (a_start >= vma->vm_start) > + *start = a_start; > + > + if (a_end <= vma->vm_end) > + *end = a_end; > } Looks correct, thanks. Reviewed-by: Peter Xu -- Peter Xu