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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 EC286C43461 for ; Thu, 29 Apr 2021 13:27:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 981A961445 for ; Thu, 29 Apr 2021 13:27:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 981A961445 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8E49B6B0070; Thu, 29 Apr 2021 09:27:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 748696B0075; Thu, 29 Apr 2021 09:27:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43B7F6B0073; Thu, 29 Apr 2021 09:27:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 047796B0072 for ; Thu, 29 Apr 2021 09:27:11 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A5DF63634 for ; Thu, 29 Apr 2021 13:27:11 +0000 (UTC) X-FDA: 78085480662.27.4310C2C Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf07.hostedemail.com (Postfix) with ESMTP id 43253A000381 for ; Thu, 29 Apr 2021 13:27:10 +0000 (UTC) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FWGRf6T3qzPvbj; Thu, 29 Apr 2021 21:23:58 +0800 (CST) Received: from huawei.com (10.175.104.170) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 29 Apr 2021 21:26:59 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , Subject: [PATCH v2 5/5] mm/huge_memory.c: don't discard hugepage if other processes are mapping it Date: Thu, 29 Apr 2021 21:26:48 +0800 Message-ID: <20210429132648.305447-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210429132648.305447-1-linmiaohe@huawei.com> References: <20210429132648.305447-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.104.170] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 43253A000381 X-Stat-Signature: rmobwfujwksb5jw6g15e81zdrjzwnmc9 X-Rspamd-Server: rspam02 Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=szxga05-in.huawei.com; client-ip=45.249.212.191 X-HE-DKIM-Result: none/none X-HE-Tag: 1619702830-395993 Content-Transfer-Encoding: quoted-printable 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: If other processes are mapping any other subpages of the hugepage, i.e. i= n pte-mapped thp case, page_mapcount() will return 1 incorrectly. Then we would discard the page while other processes are still mapping it. Fix it by using total_mapcount() which can tell whether other processes are stil= l mapping it. Fixes: b8d3c4c3009d ("mm/huge_memory.c: don't split THP page when MADV_FR= EE syscall is called") Reviewed-by: Yang Shi Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index af30338ac49c..87b0241394f4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1607,7 +1607,7 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, = struct vm_area_struct *vma, * If other processes are mapping this page, we couldn't discard * the page unless they all do MADV_FREE so let's skip the page. */ - if (page_mapcount(page) !=3D 1) + if (total_mapcount(page) !=3D 1) goto out; =20 if (!trylock_page(page)) --=20 2.23.0