From patchwork Thu Apr 23 12:49:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11505591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EC7A14DD for ; Thu, 23 Apr 2020 12:49:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DF5A920781 for ; Thu, 23 Apr 2020 12:49:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YHaYkAMv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF5A920781 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1687B8E0005; Thu, 23 Apr 2020 08:49:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1186A8E0003; Thu, 23 Apr 2020 08:49:42 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0067B8E0005; Thu, 23 Apr 2020 08:49:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id D8B468E0003 for ; Thu, 23 Apr 2020 08:49:41 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8C83C180AD81A for ; Thu, 23 Apr 2020 12:49:41 +0000 (UTC) X-FDA: 76739101362.07.bead48_1a6051f0d1860 X-Spam-Summary: 2,0,0,db194de6f8e6a210,d41d8cd98f00b204,lixinhai.lxh@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1431:1437:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:4321:5007:6119:6120:6261:6653:7514:7901:7903:8603:9413:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13255:14096:14181:14394:14687:14721:21063:21080:21444:21451:21627:21666:21990:30012:30054:30064:30070,0,RBL:209.85.208.196:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: bead48_1a6051f0d1860 X-Filterd-Recvd-Size: 4630 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Apr 2020 12:49:40 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id n6so6029112ljg.12 for ; Thu, 23 Apr 2020 05:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=iEl7H6dv1etank6GF5wXq/s5nSw0TfVnwUik2/uvphs=; b=YHaYkAMvtKv/pRAn8AIEGlkWbUAss/lEyDtWThfrD5fstMwDOjfiYDmiQ1rU11hw4y mMHP3RzWk5PMazlEd+mzl/ncQ6F1zqQaBrUBWE5toCdTtM7t9raAxDYzLBlWnU73Q/xD arBHcSVhixcQ9x7GI5goIfy0A9YScdTWgVbWTswmEPUWzuOhNeL7sti+SdnKmQ91U7hy wM/Wc9+YC24vPqTZagmRrU3aaerEYjIMYn5xJQ16FfwHrFhpxcOArW0CzmtzUTQvf31X RFz2Np/w40YItyQ50NzFOEFg32cQfWJdR7am1UicwO86Uh7Dhazls7ZUrilVGeEHqBuX kt1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iEl7H6dv1etank6GF5wXq/s5nSw0TfVnwUik2/uvphs=; b=a450FkXzAFgOr4ubf1NtwxzEPQBG9kgWzaY+tU2igOuA/HDyCCw0Qe2dDdDNuKc4Xl cqE9KJg5VeYNjaTDfqpBKsZtYOvfPWjhpY9XkznbJWRjRRIRF/jXVPlY2eVMH6KHbv02 O+DFhP/tlG2rtpjPY+Aiy8WnYRwqQPdx1/OX4jgf1ktfBj09dy4q3BTddMvTgfD6tkW7 l5t7dazpPrkS7M3U7AYhQsK35PRUchvwbTBqVyw1cRRiRGl+kLUmTUkG79qknk5LXMyA 5iRO5s9ipdI0PVX04KkOyMQoUmyCbeRvCYvKDwnqNDqw/rPnv8rCyWjla0Ea6SEIGA8c dL4w== X-Gm-Message-State: AGi0PuZ20xglw/742VVL8YEKu11ZC1Bn/bavdQZoJ98fO6EjnAe3kaW4 ILrdcq+Ht7nyKcktqhyBE/b2RXJr X-Google-Smtp-Source: APiQypKSXe/+mhVCKVq+i2Hw6YViBPNyYSZGD2J6aSDWcAjajA99ZhAOj+F6eb6i4+GlU9s7ZHcSFg== X-Received: by 2002:a2e:361a:: with SMTP id d26mr2257630lja.171.1587646178523; Thu, 23 Apr 2020 05:49:38 -0700 (PDT) Received: from localhost.localdomain.localdomain ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id o18sm1750431lfb.13.2020.04.23.05.49.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2020 05:49:37 -0700 (PDT) From: Li Xinhai To: linux-mm@kvack.org Cc: Mike Kravetz , Andrew Morton Subject: [PATCH] mm/hugetlb: avoid unnecessary check on pud and pmd entry in huge_pte_offset Date: Thu, 23 Apr 2020 12:49:14 +0000 Message-Id: <1587646154-26276-1-git-send-email-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 1.8.3.1 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: 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); + /* must be pmd_huge or pmd_none */ + return (pte_t *)pmd; } #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */