From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E6C62260C for ; Mon, 20 Jan 2025 06:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737354747; cv=none; b=uhaawkiKahYDpK4OqqORBBiriOSlI0ni0bZOKN6G+0kpJYSTSGt5fqUjU9BzX9OblOlCyfT8IYf+VmlITBEjhOSATcK9FcXxESB0z5TAJpBuoGcB08mHrp6D3DVXuwCK+jqWMdWNhyn/1YumbwnVJFESQpG7fM38Y93nmer+cxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737354747; c=relaxed/simple; bh=w5M75OOK3s1CpRu0u4X7fVBa8J1x4NtGxS4E8lzpxzM=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=FliBH94asc0L4mysWap8qnxzKrAm4hEF8KEusZvUYJpJ6KR3euaDy64c1exu+6ZRfpjx5FG4EF0tbImz/0hktcZFCs5WNzitETE/X4UFIPQTy/grlgxb9/0SnyQaQFKtInZkKvDYNlDcN02kdddfNm4Ty9lrdm72NT5Nab2fcs0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Yc0mL06Zxz1kyq1; Mon, 20 Jan 2025 14:29:06 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 3E5591402DA; Mon, 20 Jan 2025 14:32:22 +0800 (CST) Received: from [10.173.127.72] (10.173.127.72) by kwepemd200019.china.huawei.com (7.221.188.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 20 Jan 2025 14:32:21 +0800 Subject: Re: [PATCH v2 3/3] mm: memory-hotplug: check folio ref count first in do_migrate_rang To: Wupeng Ma CC: , , , , , , References: <20250116061657.227027-1-mawupeng1@huawei.com> <20250116061657.227027-4-mawupeng1@huawei.com> From: Miaohe Lin Message-ID: <3b993af4-1fe2-b250-5d07-5840f1ad530d@huawei.com> Date: Mon, 20 Jan 2025 14:32:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20250116061657.227027-4-mawupeng1@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200019.china.huawei.com (7.221.188.193) On 2025/1/16 14:16, Wupeng Ma wrote: > 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; Will it be necessary to move this check above folio_test_hwpoison trunk too? Thanks. .