Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1407332pxy; Thu, 29 Apr 2021 06:33:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK3PT8Dpusoy5Z8j6vtY9VxbS2x+UwCqCEzzrXtZsnWlpqiZphjRmqc/dF66RwS3ffF88F X-Received: by 2002:a17:906:499a:: with SMTP id p26mr3491196eju.380.1619703202634; Thu, 29 Apr 2021 06:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619703202; cv=none; d=google.com; s=arc-20160816; b=SsE8KDH6qlz/yUDjKqr8JuP31Kl8lmUgU5yXE6/YR39QUFMyGznzTYDXSMQq5rQH0O fxadBfIhR/4fNLEKDtvPFLK1Etm/+8uGi8OpP9MZ3lQ7QAnWqNsvTrNUGeF8VtUSTe/v wQm5ffjKG8IaPeGmUY0IXKFr28fG+vyQ7LfWguUTvzIqnd1BHnmKftOxtvWFHRsiIbiM g6sxKjVGu2bzc+JW8BKvqBo3wLxvL+QLXj4OWGTETzMWq8p2cJvCZScCTQ5RIvhQ6Ixr x0WfBPezItYIVPb6tRax1+ek0u6Xti0O2qCDuWdRgZBISPmizElD87ZMEisUjKQW8/EK pArA== 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=4ux+jl6Kx118y4sn2oZ0VbNi9JZlpKvVvOuzqrkuvu4=; b=cGqlG7OiOLaiWmik1PJVBohGIUqwqCwn5hVCO/8QYldQ7Cy2qhjGuMOno85FtnzPRg akCJs6AbRtvFLHtu0/Fb4revTqJ5SailpjnkSe6zzp/6mJKXjUUPxn6ygKwgMkj6c69a xY84JApKgpA5Ybs4Qudu44bmw5xZMpTBbOFNhuZgFI6pekn/RM5+OnHYh0N8Yt39FYH9 rr2SfFoNSEfb+cYY3liz187i1JZSr2knPZR8IncsQ2AjN25JCEX0+SvE0FxzbdxLEVFR GHhqWWOTTpTA/fBGaDd80UkBZ9XlbwI0ZL+gCP5h9QE8x5787/XIaa3yiuXKPgABrB1R fuNw== 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 n24si2788140eds.571.2021.04.29.06.32.58; Thu, 29 Apr 2021 06:33:22 -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 S237367AbhD2N17 (ORCPT + 99 others); Thu, 29 Apr 2021 09:27:59 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17050 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237130AbhD2N14 (ORCPT ); Thu, 29 Apr 2021 09:27:56 -0400 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-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") 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) != 1) + if (total_mapcount(page) != 1) goto out; if (!trylock_page(page)) -- 2.23.0