Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3542150pxj; Tue, 11 May 2021 06:52:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLISZZZWVtUL6M+1Hq0uOL0WMXCwSjStgWYKjS7zp5dBeAw77l/gsySYDA5yPm74l4NfUt X-Received: by 2002:a05:6402:16db:: with SMTP id r27mr34838013edx.375.1620741132690; Tue, 11 May 2021 06:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620741132; cv=none; d=google.com; s=arc-20160816; b=HpsSHvDp/NmdvLRWSX39V8LKrjq5J26IyFvwMXWkeqW/aXqsYRxY4q/Rtp8ZxGxB3M lYXhi+9BxTfB5TsxUeM2jr58qG0GBmmweYY3mI7oPl7ZLKC4hlyM+A7MLZ0mh+syxOcL Fsf2B9KSEBzDG5Gpd4ukMOfDQws9zY0+3Up4BcRki5ikL/eCqJSHOpppfnc7nfmtooUJ xQdxGscyM+6RjfGoF6m8LvTqvxouRAzVUlmj49fApQZmtzREypXKZDXdP74iahM69Z/l 71lt9s/RCfn8300WfqFDuAIJjqWUOBytAOApden60z603Q+P9yMO4n599002X44bw3Wi agZA== 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=y0DCpEw2twNdPYAY8v6FIK0kl/HHqd54orP38+HufFU=; b=IwtNzGb82p3TeJcVN2IGDeM1ojBfzaw7CZ5pYAkc93NG164bpL119NwkOU0VRfhd+9 ymRS1W3XjCNIC+sqrab40LF1Y3WBrfjqpkhvIvfZOCK7Yb49qEqU2kwHP/6uFSNRzPoQ ugLdFiFol2Al/X5LUog9fl3OvRZm8vxfD0MN0aim4CztjLFySsOIZAaDVNNYWlc7Kqx/ WRFKEyW/soBqDlsFc6L768B6nNZYzoo6TxYZT0iBZo1NEQCHToZXGox4lhLO2gOLl/z4 KMwj7GexwM/VgfW7PUj14CEAIVtmkBfmfH7hYGi6eqGIR5ZMDPgKbby9KFKuF+25uojw YZDg== 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 da5si3825077edb.538.2021.05.11.06.51.47; Tue, 11 May 2021 06:52:12 -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 S231771AbhEKNul (ORCPT + 99 others); Tue, 11 May 2021 09:50:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2632 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231718AbhEKNuZ (ORCPT ); Tue, 11 May 2021 09:50:25 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FffMR285FzPwhY; Tue, 11 May 2021 21:45:55 +0800 (CST) Received: from huawei.com (10.175.104.170) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Tue, 11 May 2021 21:49:06 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , Subject: [PATCH v3 5/5] mm/huge_memory.c: don't discard hugepage if other processes are mapping it Date: Tue, 11 May 2021 21:48:57 +0800 Message-ID: <20210511134857.1581273-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210511134857.1581273-1-linmiaohe@huawei.com> References: <20210511134857.1581273-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 b8e67332806f..24647fe076b8 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1610,7 +1610,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