From patchwork Fri Jan 10 02:56:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ge Yang X-Patchwork-Id: 13933542 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 BC277E7719A for ; Fri, 10 Jan 2025 02:56:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B77C6B0098; Thu, 9 Jan 2025 21:56:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 167606B009A; Thu, 9 Jan 2025 21:56:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 055F46B009B; Thu, 9 Jan 2025 21:56:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A42BD6B0098 for ; Thu, 9 Jan 2025 21:56:21 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 28A18AF41E for ; Fri, 10 Jan 2025 02:56:21 +0000 (UTC) X-FDA: 82990028562.24.903BA2F Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.7]) by imf29.hostedemail.com (Postfix) with ESMTP id 6298A120004 for ; Fri, 10 Jan 2025 02:56:18 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=keh6RK6r; spf=pass (imf29.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.7 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736477779; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=nHRl3hxgJjJl2Y/XNG2RHkRgfQ40dcQ98WtLTQluhRs=; b=zhaDUfkC8JXOi+jCnV0z35bUYCrn68NBCLgB7LwKhAz/wxhH0tLPzF+geRVApD+XWN8RGM b5nYPZqPD+HXvB5Bzlm161DYoRx1Pw7RYvY2ikTI+V9YMCx8rMgkr+j776PrHuVDwJ5lqM nb8elNEjus8zGFDW8j9mNuQcZ/FvjeI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=keh6RK6r; spf=pass (imf29.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.7 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736477779; a=rsa-sha256; cv=none; b=J4vSxRUMtMASEConUO4oWNBRFtYi/ygHwwg9DcnscfUY6EyTKQ8MD9TT63i5eT4cC5QsQk FsCAu84QeTr6tbi3YrUpqFts0QV9iO/TiawfWj/9010UFs012llMMgW0sdBHbGUbj97Cgi py3b/7HTsXOsg+EUufs2vC7T98EyY3Q= 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-Originating-IP: [112.64.138.194] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOgnQG2eAh+5YvQAAsT X-Rspamd-Server: rspam05 X-Stat-Signature: 4xnkomwot6no88rmhezchafpc1ocdno8 X-Rspamd-Queue-Id: 6298A120004 X-Rspam-User: X-HE-Tag: 1736477778-789683 X-HE-Meta: U2FsdGVkX1/AZgt4nehMj0d7JwvJe7VUySI4T+Ao7UJ26oRmoc2Uh7HUS0YW66z3PC4L5zkFhzSHwxDYr9gnSdSIqPpGKFy6UDr6X/+gX0M7VCHEMMEMruoaHkmPFudW5+wDaYKEm26JZ8b87gfuczvtmVhIx9UAqN4QtzoGemSLut1fHiHseF4gsmX8dgWmK0kW6dg0ebBAkiCDhYOAoft24cg5HqHeaL0rpy+fdE+rbnSUZ1Lr80zi0BAAFe9Po3Vt4hRFO7NPeCmt7K0ZPwoRbQZnZHk8kQM8gw7mB3T5DY2M+xYz6hf8I4PCzup24rPtf017eUEktgnwhCZ/4lklk3x9WT5r64LrvsEDgS2eSZGfpco40FBjCnj0ixB5htCTVaD4J6Flu44TvWJHHDmvuLmkDkjnoSmk+fr+5+xQrsOkXO/2xMJMbqIK4QSpt0L3XTvC9lw3zNEz0FTOBrBHH4Nopf2+cDFNjQSJvd9Jsjn+/CwnC9iudgSP5p/Md830rICz5lQUOGzmbekz7NQqeuX2GgoFcTs1mO9oY3ZsSfqaPPZ8LHIo31b/Y/eIhxPTS9TUuSHoh6u3F3rsH+T7oJYHXXjw+APKv9NcXur/sByzGeXiU1y+nhMzRSbC5+7Ose/F1B3gGhoxXV7/uy+2WQXDceXnQUHxFLi1TG2GbYgN4bK7WOfaLMHnAsndfQQA4loQSQ/7uf7kwPfaP1ycWnlhO6ETP/AququXEkb1bbnBGjE7YKKehcJ9gtVO/cbVdXwhuQrtfzp2SRhrGThfQxmGoP/ZsHlwA/LTn77UF9ds1XW/H/bXgxXEJdAK/TxGXtIAmyn8dF329No2j5Q/iyH+EYdcUVmALbd1Teyb/jxvzMmMSyn/ebMPZqj5qyXOdovZujFjgz0NngWW1XkwJtDDBHxnafyf053AsfMWy+I6uGEGRlYHBb7R/FQKGCdjmudeWhICHNktyzd pG6j6TdB HoBFDzDXyP/zDyHuP4STj+NgOcjwedN11esUGZvMffzlvcq0dPCSMOT/yjZ+XVkkSlicT/cB1Eeow9JR9sF7soh4S7aOaO/6x2KJ1Exw2WYdiVghIs/uHpDyWR0nXeec14P8EICsOmitTXcuJ4f50bOL71oYBL9W95qtUjXuLst/LZWumUGJWjmlUVzsJZF4odEMWoUgH7Q2sKjvv4N0H+QZQPKevfNc45tC5ZcKBA+7cb2ac0/aUe9iNwMTF0HQFVfScHW9dkGduwrXUwig5aEUG96ArdpK2vWxBK7XiHv+K4RE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000074, 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: 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-yangge1116@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 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);