From patchwork Thu Jan 16 06:16:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wupeng Ma X-Patchwork-Id: 13941322 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 8F42CE77188 for ; Thu, 16 Jan 2025 06:24:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1D266B0089; Thu, 16 Jan 2025 01:24:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC4926B0092; Thu, 16 Jan 2025 01:24:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99F3C6B008C; Thu, 16 Jan 2025 01:24:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 50FCE6B0092 for ; Thu, 16 Jan 2025 01:24:37 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 063321C7447 for ; Thu, 16 Jan 2025 06:24:37 +0000 (UTC) X-FDA: 83012326194.03.DB4DC6C Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf13.hostedemail.com (Postfix) with ESMTP id A3C1720006 for ; Thu, 16 Jan 2025 06:24:32 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737008674; a=rsa-sha256; cv=none; b=o5g7CFN5OtzAsZiOr87zCGvjozkBPVHzfvDOhofkOS367f8o99GqCPfP/jZye1lycit5AC qkRV3vhnultTpP3a5NyOX/MrxSbenrzXKsqXYeWgASho5ThPYmFWl1ljVnQxiEE14nlylS WPha4YPGK73TAPEJjve1m1cg7NKrYCU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737008674; 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=rEhJdON/GMmNwJBgscv8EQf63kvckFtv/7gMUDhX93c=; b=2Cr+CU/FKA5tMrE/qIiHHWnXH0hreCXPFkxw+KbKKG//IlUTzO+FVQ7ILiIZHgKh4RbVtJ dNKTcVfI1yLZVdierOeek41hMyDAOqvEh5lhY0M1YZw1Tla5FlvAwFgcYkQZfkp9C+iFf7 p7RJRN278P3wqbRBB1jkPopN25ZmUOs= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4YYXp52GlWz22lDB; Thu, 16 Jan 2025 14:22:05 +0800 (CST) Received: from kwepemg100017.china.huawei.com (unknown [7.202.181.58]) by mail.maildlp.com (Postfix) with ESMTPS id C7C83140109; Thu, 16 Jan 2025 14:24:28 +0800 (CST) Received: from huawei.com (10.175.124.71) by kwepemg100017.china.huawei.com (7.202.181.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 16 Jan 2025 14:24:27 +0800 From: Wupeng Ma To: , , , , , CC: , , Subject: [PATCH v2 3/3] mm: memory-hotplug: check folio ref count first in do_migrate_rang Date: Thu, 16 Jan 2025 14:16:57 +0800 Message-ID: <20250116061657.227027-4-mawupeng1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116061657.227027-1-mawupeng1@huawei.com> References: <20250116061657.227027-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.71] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemg100017.china.huawei.com (7.202.181.58) X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A3C1720006 X-Stat-Signature: 645u4q9fcrhee8ojfesy6qkbkwfnw5rb X-Rspam-User: X-HE-Tag: 1737008672-447814 X-HE-Meta: U2FsdGVkX19AYPMuqEhAMAO7icJ2a4Ma1hvxSkU4MYmXuW5+Utp3bxqou/rIKrUavu5X9loYxWWIIdqMRvOgWJsfdXchVy6LTCgamQYyADfXFK5zN0ZUkDQgkcmmBscsguRrjM8e+CKZPCXbt2I7gk70V3sHqqadZCwf7Ix6w6REpYwpfV8p4TlQ908KWGb0lTVBDvSNWhV/nOwzh8n1hIUM/9wMXRLgT7mqswiZS9Wlm8AAE30R/vccg1K+11PESVn6oNwmyi5iGyw2Slr5XzvePkSuvr1lkXkgiho37lBTMaU/+IfvvsgMKmPvgp5+SzmRceYZL+iCNZPvECil5EkArkUMUxVseqduSJ11/OdkYqCCSWB1MNBbVXX+eCU4qxFQfOQVULzgiAVMqjtrE3THzVt0rzLqL670Yk9OcZKXWDawSZ9gb064Ws9Qmfl8JODUyc0jF6Lk96L0kyhOBMLxPkdxR2enAkYfcJk3NDSg6yY1DdN1id6ZxLV2HoY8IsGq4Y4hsNq21oAYuhLBlHQkeLw22QPEEAubWKZftFWsxbA6Cxpvzvvh46qom0L0ZIK8YffxlxeKCoF2Cs8/78oJdzxHBLlELLByLBhkEmo8fZI150ncumiDbW/hdCGmVh3IBP5UIzoFzb21SzhF9HIdHJrv14teGLNaercbRpVLbt8MSr6pZoZ97Z8dkAmc3T/1yCcRdL0AzyeC06jM1MFR05Q2qS4/G40jfLIFdO37PcWmRD0ekPFKjRBFGEH+PWPb83Xz9BoROBkjUmSIZS/byqe6Ne05hNNr684HMjorZVEBrIP4zk1IxWcgdy/ri5GvmL5fx/gC6RaVQLd8detxyVnasamyliDP/MhV/1XPp79oxbC4fJ/3WDIoezzB360dKfG5BF7+r/pfRncRch2+T3sHskxoWp2VJDKHuhspWWiYigP+U0RGyW8eg+2qaVhY6EVKVSvkEdIDVWL 4Aspbc57 AHEo1l/gqKs6Lbx6RmOOnieQ/aHGUPEyX60L90Wxgvxy2Df0RtSp1NIuPQ1z2RVKO1XV2PG3Vd7A7c9P2KquMtEh0FWyGbLyHggokUia72+skjSAySG4y8Tx22jtE9tulCWr9tu2u0hGAe83/Pkg3LUETTNqr8oHBBhhrjtgWsAeR5Ru69xfa7TSQ5tNTznxwTmHm9OWokjS3wE60lT5N1vUparrIoyRRXhOKIIB86XmCc+SFXjZ/8cf4E/TeKTcZiHVW2sIZXjdMfOI= 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: From: Ma Wupeng If a folio has an increased reference count, folio_try_get() will acquire it, perform necessary operations, and then release it. In the case of a poisoned folio without an elevated reference count (which is unlikely for memory-failure), folio_try_get() will simply bypass it. Therefore, relocate the folio_try_get() function, responsible for checking and acquiring this reference count at first. Signed-off-by: Ma Wupeng --- mm/memory_hotplug.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 2815bd4ea483..3fb75ee185c6 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1786,6 +1786,9 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) page = pfn_to_page(pfn); folio = page_folio(page); + if (!folio_try_get(folio)) + continue; + /* * No reference or lock is held on the folio, so it might * be modified concurrently (e.g. split). As such, @@ -1795,12 +1798,6 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) if (folio_test_large(folio)) pfn = folio_pfn(folio) + folio_nr_pages(folio) - 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 - * (keep the unmap as the catch all safety net). - */ if (folio_test_hwpoison(folio) || (folio_test_large(folio) && folio_test_has_hwpoisoned(folio))) { if (WARN_ON(folio_test_lru(folio))) @@ -1811,12 +1808,9 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) folio_unlock(folio); } - continue; + goto put_folio; } - if (!folio_try_get(folio)) - continue; - if (unlikely(page_folio(page) != folio)) goto put_folio;