From patchwork Thu Jul 25 01:16:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13741489 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 B7CEAC3DA61 for ; Thu, 25 Jul 2024 01:17:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0BEB6B008C; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C986B6B0092; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC2C36B0096; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 729BF6B0083 for ; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 271FA1C231F for ; Thu, 25 Jul 2024 01:16:58 +0000 (UTC) X-FDA: 82376510916.08.032FD76 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf07.hostedemail.com (Postfix) with ESMTP id 6AE1340005 for ; Thu, 25 Jul 2024 01:16:55 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@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=1721870192; 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:in-reply-to:references:references; bh=RWqMgZyrRRYuSifWPheEHa5dyRQQyTJsFvhVB6xAx7k=; b=r8iCmh+VB7wafsRtQZEDSiF6SRjBaVPAxmhPo4qJcEZCORvbiVxuLGLpltkSly0NoyKl5l KJyNqMZ3IyI+r3iH7jxg9mUkjlxfE0tRrp6cn2f8rdppTcDYxHmb+cpgbY2WcdNcxvijEH V32oBBIdU4dhPl5gW8NyLocKR2yyXt8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721870192; a=rsa-sha256; cv=none; b=Pmk5RdCkqxSCof7PFxxcGqNWmADNeo//MFATQFR0RrgUUXZ1NZo7W8GYen9kXhgkVjVqQT azzRB9biWhD219guiCcpL2EhR8Ys9g+J9mH2OoLw6/iRpgYLp/lpui/wiUIcTMAe3ZTB2j 8fWPkT/ctCQz6uNaoltr3AnO+HrAQA8= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WTtJc3vj1zxTw7; Thu, 25 Jul 2024 09:16:48 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id B30F9140121; Thu, 25 Jul 2024 09:16:51 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 25 Jul 2024 09:16:51 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH 2/4] mm: memory_hotplug: check hwpoisoned page firstly in do_migrate_range() Date: Thu, 25 Jul 2024 09:16:45 +0800 Message-ID: <20240725011647.1306045-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> References: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 6AE1340005 X-Stat-Signature: imfy619smziu76ccrf4fne86nb8f89c6 X-HE-Tag: 1721870215-951339 X-HE-Meta: U2FsdGVkX18RSUhjPjoiZXz0v+7vFZxCp+AUVgz2pF8AfxDw+98OkY9XkiPyc+ovBGskuV6HxjxNcAU2zB5IlPtsRhLAi9z8HlyUbvfDsa10/+wSwxMIXhUjEPV2mJQC+e0hcDlZsYfEQNnNgayr2nmGjGsTdiMJxdgOKPO9MrgUHfrzw2f+bcH/xvO3L5sD+wonNVbHF5RwZgCYf15cR7oaJcGWQTGRm8/JWKVqcDyctspHh9XT8mYMq3EGyjqcsyNWJ0VRLTWUEBSuYSXj4iSsOftpZGgO9X/WWKX5eyeKHqSmlGgY+WWPoTxIRHoi4hfIIv6tk5Z1ld+Tp/3w6h9ROEJHnJpoF0RbcEfpAmo3qHUr24/eKpl84zCxCFO3PsoErzTM5gZWZnAO+l1i32zo7+bPjAf0jBp0Oi9cnQE9b2rzsz1DKhg1FZYYqEoJ0+lmngXyeKF6YYYl3o/HB3WMHV4cH0SvBfp6TrWShMZm+mNrK+fOfu3A05Vp0qcAbzed+9o+KtfE865VTn/BAaPsUd/t/Axup8kPjsFzbUPLo3+7evIvzaLHRxA2SZsokv8I+ONcA0BJ3d5dQZJ6MV3K4Vuko6xflZn7vi5IDqdDc/RQbWzJ2ZnOKq0/4P0DNVuFfxA9LFywxWd5+93d0Z+atC/6Wgnj+uhXuiXpysuxClKYiWBq55KZCsZ4uVGzIBPlOhT7uEECYVN6tvjBTLy8uv007sRVCN/Ln+1+1LnfBJJUa6SC1uJ6P/5wRAykBLt5Uwg5IK/lHSWUOyRn3fflG7FdTq5DwwtMv+Zo3iIwMC7TSlZwkUBl01d8gtQt+imub4Dvc8NdrIMs4EftxxYbJPSYpgypv2p0/BvJ5CgrMhViCzmfsjBxLdZ+kSA2XvF32Smc8I8XUq6F1b/RgD6f/XQPEhhmQEaU2jE9EAFBNc6vh6bRNOTSJaiqrFTPBFCkWp8xZ0Tcbu1Pbs3 s5G4vjCQ 4PiIqsx8c6EaTuklJeW1E8PALfqo7oS4lrdj0YFvc9XOnZ/fiEgIipVDhwBp3QNRAFGFH2XRUqIIKtBLHFsQTV0XlfobAsliKx8ttYFlfiLTYv4XzJ97O+qBXdhA9Cw/qLtY0JbgKRNrto1iizKVleTFIeeNT7/ssJdy8lQO+bHgIgoHnj7T0WvmplIJSCxYu86i5kC05gyH+dlW0LeCXg4IHykFGwsZTs9x/wfsdH7GcHOMkSsZq1FP//fH/zFFuzXkbB+uGPrAw6yk= 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: The commit b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") don't handle the hugetlb pages, the dead loop still occur if offline a hwpoison hugetlb, luckly, after the commit e591ef7d96d6 ("mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage"), the HPageMigratable of hugetlb page will be clear, and the hwpoison hugetlb page will be skipped in scan_movable_pages(), so the deed loop issue is fixed. However if the HPageMigratable() check passed(without reference and lock), the hugetlb page may be hwpoisoned, it won't cause issue since the hwpoisoned page will be handled correctly in the next movable pages scan loop, and it will be isolated in do_migrate_range() and but fails to migrated. In order to avoid the unnecessary isolation and unify all hwpoisoned page handling, let's unconditionally check hwpoison firstly, and if it is a hwpoisoned hugetlb page, try to unmap it as the catch all safety net like normal page does. Signed-off-by: Kefeng Wang --- mm/memory_hotplug.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 66267c26ca1b..ccaf4c480aed 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1788,28 +1788,33 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) folio = page_folio(page); head = &folio->page; - if (PageHuge(page)) { - pfn = page_to_pfn(head) + compound_nr(head) - 1; - isolate_hugetlb(folio, &source); - continue; - } else if (PageTransHuge(page)) - pfn = page_to_pfn(head) + thp_nr_pages(page) - 1; - /* * HWPoison pages have elevated reference counts so the migration would * fail on them. It also doesn't make any sense to migrate them in the * first place. Still try to unmap such a page in case it is still mapped - * (e.g. current hwpoison implementation doesn't unmap KSM pages but keep - * the unmap as the catch all safety net). + * (keep the unmap as the catch all safety net). */ - if (PageHWPoison(page)) { + if (unlikely(PageHWPoison(page))) { + folio = page_folio(page); + if (WARN_ON(folio_test_lru(folio))) folio_isolate_lru(folio); + if (folio_mapped(folio)) - try_to_unmap(folio, TTU_IGNORE_MLOCK); + unmap_posioned_folio(folio, TTU_IGNORE_MLOCK); + + if (folio_test_large(folio)) + pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1; continue; } + if (PageHuge(page)) { + pfn = page_to_pfn(head) + compound_nr(head) - 1; + isolate_hugetlb(folio, &source); + continue; + } else if (PageTransHuge(page)) + pfn = page_to_pfn(head) + thp_nr_pages(page) - 1; + if (!get_page_unless_zero(page)) continue; /*