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=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 EA726C54FCB for ; Thu, 23 Apr 2020 18:16:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 820D420706 for ; Thu, 23 Apr 2020 18:16:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Fig2/kvT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 820D420706 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 E070E8E0005; Thu, 23 Apr 2020 14:16:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB79E8E0003; Thu, 23 Apr 2020 14:16:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA6588E0005; Thu, 23 Apr 2020 14:16:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id B26788E0003 for ; Thu, 23 Apr 2020 14:16:45 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 56932180AD817 for ; Thu, 23 Apr 2020 18:16:45 +0000 (UTC) X-FDA: 76739925570.27.sheep36_751ce6ac6ba47 X-HE-Tag: sheep36_751ce6ac6ba47 X-Filterd-Recvd-Size: 5957 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Apr 2020 18:16:44 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 03NIEYA7032414; Thu, 23 Apr 2020 18:16:33 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=MKCwxfrKZtKD/iXKDsf/z9pqCJrNluexp/lxkL1h/HU=; b=Fig2/kvTtlFzqhv1/E8NEanrORl2K5nptSSrDVwMEorPoEVK5GIKtZJFknLx7vNa6tNE wmiSBLUaQoGPzNgBFDD19mHjUH4CxHrfb+UYmSd7ShkaMFaGg0BhW9op8nFIvOPrDh3l +UqLTi6OwxqtcjqwmysWYh6sq0q7PuF2DjNGlCwVlnLWojIcJObRLDm/eM0d+L3+bLmQ WQwFXFKbTcyy6gFkGNH1UkUAWGzTfswx3xty2Fem9RIRGgquj6KIygEDRFUK86IQkR9L +K1v2bureF5FU/wpBNHhRKsEmNvsrdf1tgFLWv1PbZ0f0VbVKWR9BWXDIvpFCeRjzlKZ /A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 30ketdgep2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Apr 2020 18:16:33 +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 03NIBirt041590; Thu, 23 Apr 2020 18:14:32 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 30gb3w0yg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Apr 2020 18:14:32 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 03NIETe3012182; Thu, 23 Apr 2020 18:14:30 GMT Received: from [192.168.2.157] (/71.63.128.209) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 23 Apr 2020 11:14:29 -0700 Subject: Re: [PATCH] mm/hugetlb: avoid unnecessary check on pud and pmd entry in huge_pte_offset To: Li Xinhai , linux-mm@kvack.org Cc: Andrew Morton , Punit Agrawal , Longpeng , Jason Gunthorpe References: <1587646154-26276-1-git-send-email-lixinhai.lxh@gmail.com> From: Mike Kravetz Message-ID: Date: Thu, 23 Apr 2020 11:14:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <1587646154-26276-1-git-send-email-lixinhai.lxh@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=9600 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 adultscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004230143 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9600 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 spamscore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 priorityscore=1501 clxscore=1011 suspectscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004230143 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: Cc a few people who have looked at huge_pte_offset() recently. On 4/23/20 5:49 AM, Li Xinhai wrote: > When huge_pte_offset() is called, the parameter sz can only be PUD_SIZE > or PMD_SIZE. > If sz is PUD_SIZE and code can reach pud, then *pud must be none, or > normal hugetlb entry, or non-present (migration or hwpoisoned) hugetlb > entry, and we can directly return pud. > When sz is PMD_SIZE, pud must be none or present, and if code can reach > pmd, we can directly return pmd. > > So, after this patch, the code is simplified by first check on the > parameter sz, and avoid unnecessary checks in current code. > > Signed-off-by: Li Xinhai > Cc: Mike Kravetz > Cc: Andrew Morton > --- > mm/hugetlb.c | 24 +++++++++--------------- > 1 file changed, 9 insertions(+), 15 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index bcabbe0..e1424f5 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -5365,8 +5365,8 @@ pte_t *huge_pte_offset(struct mm_struct *mm, > { > pgd_t *pgd; > p4d_t *p4d; > - pud_t *pud, pud_entry; > - pmd_t *pmd, pmd_entry; > + pud_t *pud; > + pmd_t *pmd; > > pgd = pgd_offset(mm, addr); > if (!pgd_present(*pgd)) > @@ -5376,22 +5376,16 @@ pte_t *huge_pte_offset(struct mm_struct *mm, > return NULL; > > pud = pud_offset(p4d, addr); > - pud_entry = READ_ONCE(*pud); > - if (sz != PUD_SIZE && pud_none(pud_entry)) > - return NULL; > - /* hugepage or swap? */ > - if (pud_huge(pud_entry) || !pud_present(pud_entry)) > + if (sz == PUD_SIZE) > + /* must be pud_huge or pud_none */ > return (pte_t *)pud; > - > - pmd = pmd_offset(pud, addr); > - pmd_entry = READ_ONCE(*pmd); > - if (sz != PMD_SIZE && pmd_none(pmd_entry)) > + if (!pud_present(*pud)) > return NULL; > - /* hugepage or swap? */ > - if (pmd_huge(pmd_entry) || !pmd_present(pmd_entry)) > - return (pte_t *)pmd; > + /* must have a valid entry and size to go further */ > > - return NULL; > + pmd = pmd_offset(pud, addr); Can we get here with sz = PMD_SIZE and pud_none(*pud)? Would that be an issue for the pmd_offset() call? -- Mike Kravetz > + /* must be pmd_huge or pmd_none */ > + return (pte_t *)pmd; > } > > #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ >