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=-17.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,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 469E9C433DB for ; Mon, 4 Jan 2021 03:55:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BDCF22151B for ; Mon, 4 Jan 2021 03:55:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDCF22151B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CE8D46B00C1; Sun, 3 Jan 2021 22:55:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C9BB16B00C2; Sun, 3 Jan 2021 22:55:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8A876B00C3; Sun, 3 Jan 2021 22:55:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 9EEF06B00C1 for ; Sun, 3 Jan 2021 22:55:25 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 66DA01EE6 for ; Mon, 4 Jan 2021 03:55:25 +0000 (UTC) X-FDA: 77666727810.12.duck56_1f03590274cd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 43CE31800DCB2 for ; Mon, 4 Jan 2021 03:55:25 +0000 (UTC) X-HE-Tag: duck56_1f03590274cd X-Filterd-Recvd-Size: 7080 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Jan 2021 03:55:24 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 1043nicx125797; Mon, 4 Jan 2021 03:55:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=glK9y+Tb1VQprUWXtxiOYYGOLtymJpXU26y2SPfT4is=; b=zvjHmrdh706xGz71I5oZqoiY3AOASlOtUQ6cBjdIe2Tmi8LrSHA9xRh5cHFoU+jx0g90 mZ0CG+KtU+JxjdF5byEBDVGyJ/eZ+8AU5efOodw5XmB7zNAy3hZTUhPuPmZrhkCrNK+Q kzKAdO2FRC4qIsJe3FyuXpeFl9Rn9TsfBpTbHBpG837hSQcrbKkMTHNGQu3jyLQKsV0b eTKS9DUbhXiPNPW4z3fjiQ3gsFX+fJOqeSDZKqyME8nvY6SBUV2Zc56MmVstgAJrZLEw Si6oDe5CbUpLBLkfZCd+jvY1u1njhT8hOkg5z8IjyknxLVgCUmO0bTSBhWO0jJTjjPiE 6g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 35tgskjh4f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 04 Jan 2021 03:55:21 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 1043oJka036229; Mon, 4 Jan 2021 03:55:21 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 35uafbpwxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 04 Jan 2021 03:55:21 +0000 Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 1043tJCD018709; Mon, 4 Jan 2021 03:55:20 GMT Received: from [192.168.2.112] (/50.38.35.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 03 Jan 2021 19:55:19 -0800 Subject: Re: [PATCH] mm/hugetlb.c: fix unnecessary address expansion of pmd sharing To: Li Xinhai , linux-mm@kvack.org Cc: akpm@linux-foundation.org, Peter Xu References: <20201229042125.2663029-1-lixinhai.lxh@gmail.com> <2b6534f5-2ffa-6325-6af1-8c067ba9c0bc@oracle.com> <2d8a7726-b7fb-3dc8-e7bc-54a67d28db24@oracle.com> <2a95c320-4408-2603-f266-8e111a2f1620@gmail.com> From: Mike Kravetz Message-ID: <049fb8f0-73c8-b296-7670-7b60fdcc092a@oracle.com> Date: Sun, 3 Jan 2021 19:55:18 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <2a95c320-4408-2603-f266-8e111a2f1620@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9853 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101040022 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9853 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 malwarescore=0 phishscore=0 impostorscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101040022 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 1/2/21 3:56 AM, Li Xinhai wrote: > > > On 1/1/21 1:56 AM, Mike Kravetz wrote: >> On 12/29/20 1:20 PM, Mike Kravetz wrote: >>> On 12/28/20 8:21 PM, 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 >>> >>> Thank you. That does indeed fix an issue in the current code. >>> >>> Reviewed-by: Mike Kravetz >> >> Upon further thought, this patch also expands the passed range when not >> necessary. Consider the example (start, end) = (1G-6M, 1G-4M), and >> (vm_start, vm_end) = (1G, 1G-2M). This patch would adjust the range to >> (1G, 1G-4M). However, no adjustment should be performed as no sharing >> is possible. >> > correct, my previous patch did not fully fix the issue. > > Above example maybe typo for vm_start, vm_end. The issue didn't fixed by my patch would be with another example, > (vm_start, vm_end) = (1G-8M, 1G+2M), (start, end) = (1G-6M, 1G-4M), end should not be adjusted to 1G, although after adjust it still below vm_end. > Sorry, I did incorrectly write that example. It should have read: Consider the example (start, end) = (2G-6M, 2G-4M), and (vm_start, vm_end) = (2G, 2G-2M). This patch would adjust the range to (2G, 2G-4M). However, no adjustment should be performed as no sharing is possible. >> Below is proposed code to address the issue. I'm not sending a formal >> patch yet as I would like comments on the code first. It is not a critical >> issue and any fix can wait a bit. > Now, this fully fixed the issue. > > One thing to be sure is that the (start, end) as input parameter must already within vma's range, although the range_in_vma test() can cover the out of range cases. > > Reviewed-by: Li Xinhai Thanks for taking a look. I believe the only case where your patch produced incorrect results is when the range was within a vma that was smaller than PUD_SIZE. Do you agree? If that is the case, then how about just adding the following to your patch? I think this is simpler and faster than the 'range_in_vma' checking I proposed. diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 49990c0a02a3..716d1e58a7ae 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5261,7 +5261,9 @@ void adjust_range_if_pmd_sharing_possible(struct vm_area_struct *vma, { unsigned long a_start, a_end; - if (!(vma->vm_flags & VM_MAYSHARE)) + /* Quick check for vma capable of pmd sharing */ + if (!(vma->vm_flags & VM_MAYSHARE) || + (vma->vm_start - vma->vm_end) < PUD_SIZE) return; /* Extend the range to be PUD aligned for a worst case scenario */