From patchwork Tue Oct 15 01:45:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13835665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9607CCFC505 for ; Tue, 15 Oct 2024 01:47:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F0A36B00A9; Mon, 14 Oct 2024 21:47:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A0966B00AA; Mon, 14 Oct 2024 21:47:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 169856B00AB; Mon, 14 Oct 2024 21:47:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EB9096B00A9 for ; Mon, 14 Oct 2024 21:47:10 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 28E2CAC10A for ; Tue, 15 Oct 2024 01:46:54 +0000 (UTC) X-FDA: 82674148536.14.6B22CC2 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf18.hostedemail.com (Postfix) with ESMTP id 6DCBE1C0003 for ; Tue, 15 Oct 2024 01:47:05 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728956686; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=2zrkgtWEMGiWAuEbtsjuLU0YmbVDpR7AookL+dNXk9o=; b=Z+ChIUtIOJQYdNrY9TR48E3M8NhN87JpJMRdq4EwjpojYIz03zbeCXBcRO9pFjyiXrH7Lb NB1Cc1OuFLdb8ciFAKoH3/LirYZIIsoXXtG6OJGf8Ko+9nQ6mvVHDaTHTSf5SdqV82+rW+ H6QAVgqzOq0F5P8FuWOHs8H7Qs8d540= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728956686; a=rsa-sha256; cv=none; b=VQ9JJhAZbvdMIgKMfsMrtNUWHuGiiJFEOBWDt0Wk6ujlrkxNEG/H2L5O34a8afaTcB1Lg1 LbNtFJYK1/8c/7t6SOVYGTH/9P8UNprYiKTZQpBsXde1maU3zj6JucriCI/5pSvHYVceeh hCywG3vXJsPDtjzadz8ZlF2XUijaB3I= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4XSH4G5bb6z1gx1K; Tue, 15 Oct 2024 09:45:50 +0800 (CST) Received: from kwepemg200013.china.huawei.com (unknown [7.202.181.64]) by mail.maildlp.com (Postfix) with ESMTPS id CA82E1A0188; Tue, 15 Oct 2024 09:47:03 +0800 (CST) Received: from huawei.com (10.175.113.32) by kwepemg200013.china.huawei.com (7.202.181.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 15 Oct 2024 09:47:03 +0800 From: Liu Shixin To: Andrew Morton , Naoya Horiguchi , Muchun Song CC: , , , Liu Shixin Subject: [PATCH] mm/swapfile: skip HugeTLB pages for unuse_vma Date: Tue, 15 Oct 2024 09:45:21 +0800 Message-ID: <20241015014521.570237-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemg200013.china.huawei.com (7.202.181.64) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6DCBE1C0003 X-Stat-Signature: qr4w5ds5jwbimc9ds1s7fm1d81xm3afo X-HE-Tag: 1728956825-969898 X-HE-Meta: U2FsdGVkX1+oOLTN/83KUaJ/ICZaOTBjrEkif7/SNQLTYiDt1G3obxAVd5kbYHwAsd7dv/VVN2lm9nERLZ2/56ZgO9Y7z5DAXfMXaH1iKN5nzCTqWq7Bkvdfqr8L1Xh7iLC6FTmx+XtN4vLdn23Tok/1PgibY42MoBnbZ8lX18BAZwKdP9Rmi5CRpovWVh9TYdyHUKu1ZDp9ff8YEOkIe+36lMc3cYF/ap4+RPdHUzc4FC6P0TeExxKxRH7lvX7armcBrhZUz7OSCAAQUueYc6lVakzHC/1X0CNMLOPZSVjsHe/tua6Fr+2wMXvzy9Jcfhz1Pl3TNYWHmjelTYztAVE+k99hhNk1SpXj3LQOI8fdz0eJka5EcMZIDw5mTnB92kYI78Lh5kId09mjdX8+Gckh47EhErpMV4yzLCzne01lRtLCERdeNnyzHyTKQQ+6fldTt5PeWEh8pcW7YlImhu8NY4DZadWbxBIWOWiyBicRnkLRNfwd0iYwkdtho3oEYjKABDL3zhgup9+ZXWz0s0IOtPcKTaQFsnvfnzA4rmvbtis6kPXHlgElDTl8S8ouNuDgG/uyp002enYyy1nB+hPYRPd75kZIviIwe1TKgntW81VJyW7+YamGHEgmyVYGGzH3S/7FVVnX1v7MfTh1pW/kn72yPwIUKdJQg4ScRU4aXw2XaWFlSs16hUHwJ9ceIpdZAHhOpTx/TjJEdQSngwMJcroL41S9HLIN+TlgzBssE2UYVYXOojL3EHTb6PLQDLfDNmqGegY7ktviAg45ykDUY0EQzJB1Y6RHzLQhtAVX2stYcD6oh0NvJ2dvFcZRqeX5R0H1atrkpDI2RDjKUA3YugTQquGSS7DxmSu5tWtE7WlUNdv0D3HVXdbTsSJZ0mqdsb8KNUUAJv1/fIiZiJh1T4P9dpd3kbhHD87bmMCvC/JgN1gInKKS8muPECCHIOGkfuenEQFISJP+11Z LVj2oaEm y8HHAtyHMiLyL5dBkuURSADmPJe+JK8lUvOE1ALLp36N90lvb9TMCrjyHbXrMMBysk0KFRx3ROlqcokD11PPoGOCyigr0oPIBqJJ6Of2bg5H+ASiPc0NQ1BgWWxllpUYAG8u22gLnu8+K22ISJnpzkJqiXil4n8HGVbLqWLOVrHs3ardM4k2BDvzLOtCIPT6LhLzoVlDeoiVe9+pqJH5Lw0W73L6A006pGc4stRgVBfQclQWSbS4u6jDXgMq+IrM6cRI0 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: List-Subscribe: List-Unsubscribe: I got a bad pud error and lost a 1GB HugeTLB when calling swapoff. The problem can be reproduced by the following steps: 1. Allocate an anonymous 1GB HugeTLB and some other anonymous memory. 2. Swapout the above anonymous memory. 3. run swapoff and we will get a bad pud error in kernel message: mm/pgtable-generic.c:42: bad pud 00000000743d215d(84000001400000e7) We can tell that pud_clear_bad is called by pud_none_or_clear_bad in unuse_pud_range() by ftrace. And therefore the HugeTLB pages will never be freed because we lost it from page table. We can skip HugeTLB pages for unuse_vma to fix it. Fixes: 0fe6e20b9c4c ("hugetlb, rmap: add reverse mapping for hugepage") Signed-off-by: Liu Shixin Acked-by: Muchun Song --- mm/swapfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 0cded32414a1..f4ef91513fc9 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2312,7 +2312,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned int type) mmap_read_lock(mm); for_each_vma(vmi, vma) { - if (vma->anon_vma) { + if (vma->anon_vma && !is_vm_hugetlb_page(vma)) { ret = unuse_vma(vma, type); if (ret) break;