From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 CCEE219D06B for ; Mon, 20 Jan 2025 09:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364272; cv=none; b=gSIciLfF/zyyD+EC9fqQtEP85sTUU8IktKLQmA34rbMaub5CbOzUNJLMCMfaefxG+UksLvJI+kLCc6Kih5KgBWRzRG2h+B25XOnT9NY+UJlb/8eij+PCVVEcqIdY95LlZrEdV0jzB5OjWj1ggnRqQoeLihJJDAPeZ+2kY2UU3Go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737364272; c=relaxed/simple; bh=7t09WLVZ+hu3FdSl0ukwFu/Zz6gfrs5hT0Y+BpLEevk=; h=Message-ID:Date:MIME-Version:CC:Subject:To:References:From: In-Reply-To:Content-Type; b=QPmN5RYPXfJ2SRdsDmHHuDU5NTeRdrlim36Hs5ejOHpTkBaRQ5KBtvrCBcKglpqfrh8VCdwhsEPfXYWQrRKUnTFdq0fCRHlGVE2KKNHg4QJ9D6M0pK/nfQL9NEDLLps0gu41N2+woNWE6Yo5nc4r56ehnS8zNHHbgfIYVOzWBoI= 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.187 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.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Yc4Hh2KbCzbnqn; Mon, 20 Jan 2025 17:08:00 +0800 (CST) Received: from kwepemg100017.china.huawei.com (unknown [7.202.181.58]) by mail.maildlp.com (Postfix) with ESMTPS id F411A1401F4; Mon, 20 Jan 2025 17:11:07 +0800 (CST) Received: from [10.174.178.120] (10.174.178.120) 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; Mon, 20 Jan 2025 17:11:07 +0800 Message-ID: <5e2314ac-078b-444b-8142-057a005bbe07@huawei.com> Date: Mon, 20 Jan 2025 17:11:06 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird CC: , , Subject: Re: [PATCH v2 3/3] mm: memory-hotplug: check folio ref count first in do_migrate_rang To: , , , , , References: <20250116061657.227027-1-mawupeng1@huawei.com> <20250116061657.227027-4-mawupeng1@huawei.com> <7ff8de59-f91e-4d39-8b6a-2f135b2a2397@redhat.com> From: mawupeng In-Reply-To: <7ff8de59-f91e-4d39-8b6a-2f135b2a2397@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemg100017.china.huawei.com (7.202.181.58) On 2025/1/20 16:01, David Hildenbrand wrote: > On 16.01.25 07: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; >> + > > I would only move it in front of the folio_test_hwpoison() check for now. Note that with this patch as is the comment below would be wrong Thanks for notice this. Move it in front of the folio_test_hwpoison() do seems better. > >>           /* >>            * No reference or lock is held on the folio, so it might > > ^ > > I would move this patch before the current #2, so the folio_lock() looks less weird. > Ok, will be done. Thanks.