From patchwork Sat Jan 11 10:18:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11328795 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 9956192A for ; Sat, 11 Jan 2020 10:19:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C3D7214D8 for ; Sat, 11 Jan 2020 10:19:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="r8paPz89" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C3D7214D8 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 727068E0005; Sat, 11 Jan 2020 05:19:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6D6308E0001; Sat, 11 Jan 2020 05:19:57 -0500 (EST) 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 5ECBD8E0005; Sat, 11 Jan 2020 05:19:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 48AD48E0001 for ; Sat, 11 Jan 2020 05:19:57 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id C4ADA180AD815 for ; Sat, 11 Jan 2020 10:19:56 +0000 (UTC) X-FDA: 76364957592.29.hose10_90fe3ca62f25c X-Spam-Summary: 2,0,0,6cab28b3982a87f3,d41d8cd98f00b204,lixinhai.lxh@gmail.com,::akpm@linux-foundation.org:kirill.shutemov@linux.intel.com:mike.kravetz@oracle.com:mhocko@kernel.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6119:6120:6261:6653:7514:7875:7901:7903:8957:9413:10004:11026:11232:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:12986:13069:13161:13229:13255:13311:13357:14096:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:21990:30054:30064:30070,0,RBL:209.85.167.66:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: hose10_90fe3ca62f25c X-Filterd-Recvd-Size: 4589 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Jan 2020 10:19:56 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id n12so3381751lfe.3 for ; Sat, 11 Jan 2020 02:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=y1L0tMBjXoXFmI1VPycwIuEVr1Zrme5NDBzFp9v0FoE=; b=r8paPz89O5W8URGHcnMut2hD/b6/F60f/C3P6jYGi21AuIA7sB0nZRAYgTugdOB5GB vVod/a6m7LhRtMF/989rsPD2aG5xlej3pq5x746OXkArobXgf2PQ/5nzvbI7pPuBvA4c O/9xCnuGLe4BGbhCQcCZGAsmsNDsSMIB0BR+QgWeSjPAD7+cMa8cvAOnEpEgHL1jiqyZ qneTaFWUS3GKj+tZXX78o/CdK7IpLKas27QO/nSYf4H8G9oXNp50P4cRZ3xM6XXxFOAC b7MLFV+InBW2sWVdAazPRsZUyLjsp2ZACraknwQcYZGIu5s0A7kKXF4lQw0qOuYeB/l/ HUZQ== 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=y1L0tMBjXoXFmI1VPycwIuEVr1Zrme5NDBzFp9v0FoE=; b=q+PpTsObrKiE4/NEBznS/AgkzjSCwvNh3gqYviL8YhzmgNEacPgMhNxDe9a0L2xq0r x4rR8mJKm5fBwwqOM+bh1URO9QGCRdql54RgaYfH4/x83Zfpn09BIPxgN6+l9BFdgQBd xndxm4vIEhlukaBCkX1AAs2hinG8jDA5seGFBKnqUs8/5pYXlcjjY5ksr0PREAjuvNUa wL+/FNO8C9QJtM/dWZ9c3awfA0aywL4A7fwSpJv1I00jKCjDQawzUv6rGjy3cwBLro5v Q3GFS54ycyGRMTTO/yaptBMbe62mp8akIOOT7pkWHf1zMIH0l/fgnc/a4QduVJw9OhWp MrTw== X-Gm-Message-State: APjAAAXsIT9TpUObpYFFlo3zDGJG30Z693x+wZxOGJqIyZ+uoD6BxWaO TeLFmn+KyCaMl+l1w3A+snR2uuZx X-Google-Smtp-Source: APXvYqxbuYtU1z0FAjLNdVJUyayLb9XDL7F3OuZH0IW/qGwBUTKgLij6IPEsg7ZwGGcH7dCeEXRwYQ== X-Received: by 2002:ac2:43a7:: with SMTP id t7mr4825642lfl.125.1578737994590; Sat, 11 Jan 2020 02:19:54 -0800 (PST) Received: from localhost.localdomain.localdomain ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id d4sm2425344lfn.42.2020.01.11.02.19.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Jan 2020 02:19:54 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, "Kirill A. Shutemov" , Mike Kravetz , Michal Hocko Subject: [PATCH v4] mm/page_vma_mapped.c: Explicitly compare pfn for normal, hugetlbfs and THP page Date: Sat, 11 Jan 2020 10:18:05 +0000 Message-Id: <1578737885-8890-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 check_pte, pfn of normal, hugetlbfs and THP page need be compared. The current implementation apply comparison as - normal 4K page: page_pfn <= pfn < page_pfn + 1 - hugetlbfs page: page_pfn <= pfn < page_pfn + HPAGE_PMD_NR - THP page: page_pfn <= pfn < page_pfn + HPAGE_PMD_NR in pfn_in_hpage. For hugetlbfs page, it should be page_pfn == pfn Now, change pfn_in_hpage to pfn_is_match to highlight that comparison is not only for THP and explicitly compare for these cases. Signed-off-by: Li Xinhai Cc: Kirill A. Shutemov Cc: Mike Kravetz Cc: Michal Hocko Acked-by: Kirill A. Shutemov Acked-by: Mike Kravetz --- mm/page_vma_mapped.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index eff4b45..719c352 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -52,12 +52,16 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw) return true; } -static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn) +static inline bool pfn_is_match(struct page *page, unsigned long pfn) { - unsigned long hpage_pfn = page_to_pfn(hpage); + unsigned long page_pfn = page_to_pfn(page); + + /* normal page and hugetlbfs page */ + if (!PageTransCompound(page) || PageHuge(page)) + return page_pfn == pfn; /* THP can be referenced by any subpage */ - return pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage); + return pfn >= page_pfn && pfn - page_pfn < hpage_nr_pages(page); } /** @@ -108,7 +112,7 @@ static bool check_pte(struct page_vma_mapped_walk *pvmw) pfn = pte_pfn(*pvmw->pte); } - return pfn_in_hpage(pvmw->page, pfn); + return pfn_is_match(pvmw->page, pfn); } /**