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=-19.4 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,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 89AF9C11F6A for ; Mon, 12 Jul 2021 07:18:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76B8F611ED for ; Mon, 12 Jul 2021 07:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245616AbhGLHTl (ORCPT ); Mon, 12 Jul 2021 03:19:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:56038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238348AbhGLGzP (ORCPT ); Mon, 12 Jul 2021 02:55:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CD732608FE; Mon, 12 Jul 2021 06:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072746; bh=G2sJa6UZKKGBaLxneStt71HMtkc4ii35pZFPLbeCQ/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LaBocDrFBgTkE93tH7nPM62afm/KUNKVFgmdQzl0CDMH0iRXvXkPB3m2gfNYyHE/x ZL9zwlGJWrRVhCs6Y3l35Ah+Oxyif6HOo/FpwA73WWrMcYgXYvDyoLjEWvKDjniG6K 8FOj9I1dJzm6cpbUamCKt4mVaz/J4o4tHzGbBtNs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Shi , Miaohe Lin , Alexey Dobriyan , "Aneesh Kumar K . V" , Anshuman Khandual , David Hildenbrand , Hugh Dickins , Johannes Weiner , "Kirill A. Shutemov" , Matthew Wilcox , Minchan Kim , Ralph Campbell , Rik van Riel , Song Liu , William Kucharski , Zi Yan , Mike Kravetz , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 565/593] mm/huge_memory.c: dont discard hugepage if other processes are mapping it Date: Mon, 12 Jul 2021 08:12:05 +0200 Message-Id: <20210712060956.925981697@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin [ Upstream commit babbbdd08af98a59089334eb3effbed5a7a0cf7f ] If other processes are mapping any other subpages of the hugepage, i.e. in 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 still mapping it. Link: https://lkml.kernel.org/r/20210511134857.1581273-6-linmiaohe@huawei.com Fixes: b8d3c4c3009d ("mm/huge_memory.c: don't split THP page when MADV_FREE syscall is called") Reviewed-by: Yang Shi Signed-off-by: Miaohe Lin Cc: Alexey Dobriyan Cc: "Aneesh Kumar K . V" Cc: Anshuman Khandual Cc: David Hildenbrand Cc: Hugh Dickins Cc: Johannes Weiner Cc: Kirill A. Shutemov Cc: Matthew Wilcox Cc: Minchan Kim Cc: Ralph Campbell Cc: Rik van Riel Cc: Song Liu Cc: William Kucharski Cc: Zi Yan Cc: Mike Kravetz Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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 07c664c47a4f..9fe622ff2fc4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1604,7 +1604,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) != 1) + if (total_mapcount(page) != 1) goto out; if (!trylock_page(page)) -- 2.30.2