Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4500704pxy; Tue, 27 Apr 2021 06:34:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmz0idUIn8uho8xnyWpUQBi1hmR02pOhDG0CSzjbWlKzmC7wU60A5joJoQsWprxetQcy+H X-Received: by 2002:a17:90a:f2ce:: with SMTP id gt14mr8640801pjb.177.1619530471559; Tue, 27 Apr 2021 06:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619530471; cv=none; d=google.com; s=arc-20160816; b=qUCn7+MqnGqCEYmqRMmpRD9Phf+1uR6sdFGgHUXIafDJrq6k/Jh6Ln4UFR9fsTR1hY ovbdiKNHFBT5l0YAf1UQ8MqKnI7KkxyRjR13JJZNS+YsSr1VIbeiO3ukrRLFGdddBExQ 8EVLBddvw+dQ3dwaSval6k5T/2wx1lAKHdVwy/GGxSEgOQs8nWXof13r+P+H7wMenuTu ZAgIUcrufRRb7hToVHy6OhtsZQoavxUWpV9brUxDWRyEEDSopXjM1stD35eZZxzKQV+K tuG0CCYaYcmN6O8xAar1t+UsJWkvGXSdGKX4pHjO6i83yf1bG74HPwPdQYL67YyYVJQm s2DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UTGzL5qSubLNCb3Bw0JqV0/IUNMEp9+5CXMdnlwCyeM=; b=O6x0b4AcVlX8yG6NbILOYwYIfW7m4Muf30CxhK52lCU8lO+D2DpXjod1AWSDWOHC7M NeMj1pfKi5H/e+xEdaCMooXUlOuadk9P6Mad5oe3XUEL5SIDMgBr+wXuVJsf3TAgvymd C0xMKzg4d5J1wVvQtgKDAjCChQGTVEVHwGd1hNU5hH5B3YFuiViiJqE3h1mba4KeJLMS PeYTMVk3sAH4HMhHtSeCBRT2994z9TDiogxxUVf4wmnfP0q8d3L5ryPwDXWnMar2uoA+ Zy3MaQLL/2p8nYo4gJ1qRlld4J4XtSCdksLs98vCsAzfosrG+z3E9d8dn6SiZI1pBhbC KNzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o3si13728403plk.266.2021.04.27.06.34.17; Tue, 27 Apr 2021 06:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237219AbhD0Nde (ORCPT + 99 others); Tue, 27 Apr 2021 09:33:34 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17046 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237891AbhD0NdU (ORCPT ); Tue, 27 Apr 2021 09:33:20 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FV2fv5tX1zPtFQ; Tue, 27 Apr 2021 21:29:27 +0800 (CST) Received: from huawei.com (10.175.104.170) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Tue, 27 Apr 2021 21:32:26 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , Subject: [PATCH 5/5] mm/huge_memory.c: don't discard hugepage if other processes are mapping it Date: Tue, 27 Apr 2021 21:32:14 +0800 Message-ID: <20210427133214.2270207-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210427133214.2270207-1-linmiaohe@huawei.com> References: <20210427133214.2270207-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.170] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fixes: b8d3c4c3009d ("mm/huge_memory.c: don't split THP page when MADV_FREE syscall is called") 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 f652be6ecca3..d14fecb8cd00 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.23.0