From nobody Sun Feb 8 07:34:48 2026 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.9]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49F2B194A60 for ; Fri, 10 Jan 2025 02:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736477853; cv=none; b=aO7W88XLRSboMQX8p42WqFBNvGIfDeWglyAzI/r/aJIQbI7R+zqz15ZgrZ/ZfO1Cbbg84pRPNtCYhVKn9JeJQG+PfAOMkyTJyBK1UKoWQj34W2eHlYOVRRGWHNVnqR7PKA0ecqqrKOpBvLIR81ipjv4pBZdw4CQcVH3o4knNxDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736477853; c=relaxed/simple; bh=dgEpHOWNQu0meIXExwmE1RRFevGHrCEgMN6+WPPTQMM=; h=From:To:Cc:Subject:Date:Message-Id; b=M7pcDZXIaYEmJLsvZFutr41cY6lDeWTWsLk6lv0sL2t9aBK7nKnIXlZsZJI2sWn0OdaIsxluCiA4ux6GtfLzRUeOePxfhkZX56BEJJwSrUcDeRP0OE54/VOdIibnlFMlCCbakw6gh0AMhkuzmZexFMqgl8iFrBdZxvYT+jl7SCs= 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=keh6RK6r; arc=none smtp.client-ip=220.197.31.9 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="keh6RK6r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=nHRl3hxgJjJl2Y/XNG 2RHkRgfQ40dcQ98WtLTQluhRs=; b=keh6RK6r17/HfDbnmljU/Mq489DwnVxOmS IIlaubEpmECAOHifhJ7vEvLAzTfE72sJb137in3Ky6gBzBWA7aca3fQ1iHeThJfd KBdblIPhQw5asFtPUa1rGYDCviVM2uufmHFOG8Ik3Y1YuEu/V8Pak+LN0A+1E2dc M/oK3EfoA= Received: from hg-OptiPlex-7040.hygon.cn (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDHp+VHjIBnkuoMBA--.54732S2; Fri, 10 Jan 2025 10:56:08 +0800 (CST) From: yangge1116@126.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, david@redhat.com, baolin.wang@linux.alibaba.com, liuzixing@hygon.cn, yangge Subject: [PATCH] mm/hugetlb: prevent reuse of isolated free hugepages Date: Fri, 10 Jan 2025 10:56:06 +0800 Message-Id: <1736477766-23525-1-git-send-email-yangge1116@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: _____wDHp+VHjIBnkuoMBA--.54732S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFy7Gr4xAr1DCF1fZry7KFg_yoW8uryrpF Wvg3sxGrWDJr92kr47A3W5Ar1rZrWFvFWjgrWftrW3CFsxJas5G3yavw4qvw48urZ3GF4f Zr4kZF4kuF1UXaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRP739UUUUU= X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOgnQG2eAh+5YvQAAsT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Link: https://lore.kernel.org/lkml/1734503588-16254-1-git-send-email-yangge= 1116@126.com/ Fixes: 08d312ee4c0a ("mm: replace free hugepage folios after migration") 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 =20 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; =20 + 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); --=20 2.7.4