From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.7]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 819B224B231 for ; Sat, 11 Jan 2025 08:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736583445; cv=none; b=t0BZ8xzA7Pxp4QuYmvmQId8mEm38EZQjQxqdS5jj6Wb5Jd/6iMAew/wCu5WEsECxA4Pok9k+piiEPjS09KnWjTwXQfpfHPYS24sXaiEWQEsYct5+wyA4XK4EA41Hcgpnt710K6C8Lnqm7rfyOXqt/1dFP6Q1eVS0RWXGYflm3P0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736583445; c=relaxed/simple; bh=80oVXtBTdzTvcm8xROqIeB+cri8d73Nc+ofSh3m1ETA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Rza90ZNlIzzFDAHkxOAMP72IUx4udDjnvRmykHxpeh9VMfhq/oHYqjbhLZbaGdSfZdKu2ugjCmCt6Qjt9r18STqH5X2AnmRHShkgdfYSe/ddBrkUOMBGoVpZl7jBYLynlrdi5Va1+0bXRVZU2n7mK9fYo2cgK/RsAk0mPG9otyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=CVHWSgKf; arc=none smtp.client-ip=117.135.210.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="CVHWSgKf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=WiMeNFYNuhkWLcB+A2Ex1NBx2fnAWdmFhuPEsmqviqY=; b=CVHWSgKfLJGEi49SETNePoDZsDoypHt+IYSU5Zwec8zVNCrtTcu26vTTfPMz7l cep0s/I1fxPNeTPdfJ8ITspOD3igBR0uxSO/Pr5pWjvy5F+gev+SPglRi7s7zsEL qcFBMVrlIxH21buzsiR00mBAndzLptsNmSJ2YRyId8DxE= Received: from [172.19.20.199] (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD3t98qJYJnGNAhBA--.10417S2; Sat, 11 Jan 2025 16:00:42 +0800 (CST) Message-ID: <0215484e-974a-4f4d-ba1e-595d1894c732@126.com> Date: Sat, 11 Jan 2025 16:00:42 +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 Subject: Re: [PATCH] mm/hugetlb: prevent reuse of isolated free hugepages To: David Hildenbrand , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, baolin.wang@linux.alibaba.com, liuzixing@hygon.cn References: <1736477766-23525-1-git-send-email-yangge1116@126.com> From: Ge Yang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD3t98qJYJnGNAhBA--.10417S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCryxZw4DJFy8Ar1DtFWDJwb_yoW5ZF1DpF W8Ga45GrWDJr9IkFn7Z3Z0yr1FyrWFqFW0qF1ftF13CFn8XryfKrW29wn09w48ZrZ3GF4F vr4DuFWkuF1UZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j5J5rUUUUU= X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOhfRG2eCDLL0dgABs- 在 2025/1/10 16:14, David Hildenbrand 写道: > On 10.01.25 03:56, yangge1116@126.com wrote: >> From: yangge >> >> When there are free hugetlb folios in the hugetlb pool, during the >> migration of in-use hugetlb folios, new folios is allocated from >> the free hugetlb pool. After the migration is completed, the old >> folios are released back to the free hugetlb pool. However, after >> the old folios are released to the free hugetlb pool, they may be >> reallocated. When replace_free_hugepage_folios() is executed later, >> it cannot release these old folios back to the buddy system. >> >> As discussed with David in [1], when alloc_contig_range() is used >> to migrate multiple in-use hugetlb pages, it can lead to the issue >> described above. For example: >> >> [huge 0] [huge 1] >> >> To migrate huge 0, we obtain huge x from the pool. After the migration >> is completed, we return the now-freed huge 0 back to the pool. When >> it's time to migrate huge 1, we can simply reuse the now-freed huge 0 >> from the pool. As a result, when replace_free_hugepage_folios() is >> executed, it cannot release huge 0 back to the buddy system. >> >> To slove the proble above, we should prevent reuse of isolated free >> hugepages. > > s/slove/solve/ > s/proble/problem/ > >> >> Link: https://lore.kernel.org/lkml/1734503588-16254-1-git-send-email- >> yangge1116@126.com/ >> Fixes: 08d312ee4c0a ("mm: replace free hugepage folios after migration") > > The commit id is not stable yet. > > $ git tag --contains  08d312ee4c0a > mm-everything-2025-01-09-06-44 > next-20250110 > > > We should squash this into the original fix. Can you resend the whole > thing and merge the patch descriptions? > ok, thanks. >> Signed-off-by: yangge >> --- >>   mm/hugetlb.c | 4 ++++ >>   1 file changed, 4 insertions(+) >> >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >> index 9a55960..e5f9999 100644 >> --- a/mm/hugetlb.c >> +++ b/mm/hugetlb.c >> @@ -48,6 +48,7 @@ >>   #include >>   #include "internal.h" >>   #include "hugetlb_vmemmap.h" >> +#include >>   int hugetlb_max_hstate __read_mostly; >>   unsigned int default_hstate_idx; >> @@ -1273,6 +1274,9 @@ static struct folio >> *dequeue_hugetlb_folio_node_exact(struct hstate *h, >>           if (folio_test_hwpoison(folio)) >>               continue; >> +        if (is_migrate_isolate_page(&folio->page)) >> +            continue; >> + >>           list_move(&folio->lru, &h->hugepage_activelist); >>           folio_ref_unfreeze(folio, 1); >>           folio_clear_hugetlb_freed(folio); > > Sorry for not getting back to your previous mail, this week was a bit > crazy. > > This will work reliably if the huge page does not span more than a > single page block. > > Assuming it would span multiple ones, we might have only isolated the > last etc. pageblock. For the common cases it might do, but not for all > cases unfortunately (especially not gigantic pages, but I recall we skip > them during alloc_contig_pages(); I recall some oddities on ppc even > without gigantic pages involved). > > One option would be to stare at all involved pageblocks, although a bit > nasty ... let me think about this. >