From nobody Mon Feb 9 09:08:12 2026 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED18B27A469 for ; Sun, 21 Dec 2025 12:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766321805; cv=none; b=FDVR/qoo8yyhkIQPegqsJuMHc/kqMH748AWPfVS3Y4lCDi/Jz2oWCXohvZWTcS0B7TqzqglDMINPLluIr2WPHM08i6hfnOfmIbz+MhffykxH3jeeLjG1GZkVorlX68jdpJW2MCXsDp+E6sOK2AlgMiwbTBOuPIpdMMQiaqQpciY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766321805; c=relaxed/simple; bh=P+vDLRN5bA/R1fQ89+MCNxM2c5px2Px7tk5h5VBNQok=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RJhIepdAns28jEZ2gc6QCq2IKFO1gbRPXIqfCX+kGAYKJytWKVGjlIoTxfcxUOSHgDRHXwB+vhIlJ0vkOt5yldWVA0hNEil3m0pdnw1dHSj1INjRWUNetUC4iYPYm8sY21Quk3xbcMYEiLSdBNDbScdtheV3m2PzjlnDz8PCoPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=FkBs/Ks0; arc=none smtp.client-ip=209.85.222.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="FkBs/Ks0" Received: by mail-qk1-f193.google.com with SMTP id af79cd13be357-8b2ec756de0so320980085a.3 for ; Sun, 21 Dec 2025 04:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1766321802; x=1766926602; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0Ivv8/3ACbIKOnDf+l354pCkgSIU4HYGFindxr8g4Hs=; b=FkBs/Ks0WBKX8bMZLStBeXFxwcJbtKYkt1tMqVS4YkjNfLo1GoNJNTQ81FvQmId78L NmQK77Cx++cZJrQTiM267aUvC6WnnAKJM5rwm3oFURNH+83v4cf4zS1tHmDf8MutCE2b TYcblsV423ZNxgMMm9pIKJa5pf/ufTWGABWbwfwvieodTsQlcNwiTWYypsM3AU3ipqiP XhanSLILeA7UJYZBsDFx1nlOPMaO8FbJ1oEmHr0Hr8FOtszkS9u96CfNbfB0H4cU3f6b FTZXxCfMAnMf57pd5jxH8tJwxuXCT7mB1kLl+ENrx+qpMLNjvz3h5tBxjWBJF0FluSOY OFkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766321802; x=1766926602; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0Ivv8/3ACbIKOnDf+l354pCkgSIU4HYGFindxr8g4Hs=; b=G71+tFnGTF7ZmDgUUNDmZghtNqZ1C23iGRLn22tvIecTCugwf60mTbqEFnKiPS7ypC DqrHtu9YBLObFrCqoOqNmaiWCLydtwQyQ3gDQPO52ou37hIWGENSDHNY9SGAd/Lp8U9O lT3ftJmff7Ub8K+SSjAxRJWKt4foMimJuMg4t2UwQehBzLYiehiWNa9CAmcSgNdAg6di m3DYGlCSne3kF3a+xK6kO9X3wIvDgUX8gQYJzkyKlkS9KEoKsB07H6zm6AUpcpielnAA XHb362ZnChvj1ty7JVkKZJjanzjJsRze1iNGTwqZfVNnRvoaXRgifYeJQEvLWNTzOMH+ +Asw== X-Gm-Message-State: AOJu0Yz8Lblp9zdacqHk5MczNgf8pAgT0IA8zTjARkV15rre/RlKKMqc wGS9CfRqxbNMvVT6HrOX0w5xTyMCOjMqd1wmzuZ4EOQE+nUNru71UsTrqcM56naJuY8= X-Gm-Gg: AY/fxX7lIi3lSQbRXIZBjnYCYuY+lP/y/dn0hLCzjtho9k1SmGk0rvUUWuQ/SMjcW4n H2090uTltRvpR+dnC+Fim7eA1OHm+XunKaW5eOblkNyGDBkmleL66lldu4VBli5yjzI5aBdoet1 pURcFue2B57VKI2k5HoffOuPjxsHUWVAKiiKlauVQH46D1fYJgZm8TC5A5g3EPFs6gkVHqT8iMp NSP3xqLCc0sk1rr4mRsjRHBOMl5omgUkS5OtD6QS9y7k7qpjFtvBBpfeoLMPOC2pj40zqYjMVoF osEuqj1U5oWdZj6PgXQ4JlxFnPQl31WK2cHJIR9EEYIumOluHzqPI4SiefYQ1rGjTp7q4Wt0FtB 2dvnStHog7OLp/SwTiKVDYUm1pz8uglNiooKbguifKqx2zZ42YaMJxjnYrtAzMnLSQ25EQLlCFF ItuwNOF3+mbjSJ+6+wV7VSnBcLfQMsFbDzPzJQFvpKnanh8WB9LlT3KXC9Yoix4jydJMBlITmGp Dt0e+cKwwTuww== X-Google-Smtp-Source: AGHT+IE0BrkfD+Cy9oYJoP0dF/V6XgbZIAfAJdoj4kHZiMOQbZ89Gxxq8Q27csX/VrtUN9ShpMHINQ== X-Received: by 2002:a05:620a:190a:b0:8b2:eea5:32f8 with SMTP id af79cd13be357-8c08f6763bamr1307185985a.34.1766321801715; Sun, 21 Dec 2025 04:56:41 -0800 (PST) Received: from gourry-fedora-PF4VCD3F.lan (pool-96-255-20-138.washdc.ftas.verizon.net. [96.255.20.138]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c0968935b5sm619955385a.19.2025.12.21.04.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Dec 2025 04:56:41 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kernel-team@meta.com, david@kernel.org, osalvador@suse.de, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, muchun.song@linux.dev, hannes@cmpxchg.org, gourry@gourry.net, David Hildenbrand , Mel Gorman , David Rientjes Subject: [PATCH v5] mm, hugetlb: implement movable_gigantic_pages sysctl Date: Sun, 21 Dec 2025 07:56:03 -0500 Message-ID: <20251221125603.2364174-1-gourry@gourry.net> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reintroduces a concept removed by: commit d6cb41cc44c6 ("mm, hugetlb: remove hugepages_treat_as_movable sysctl= ") This sysctl provides flexibility between ZONE_MOVABLE use cases: 1) onlining memory in ZONE_MOVABLE to maintain hotplug compatibility 2) onlining memory in ZONE_MOVABLE to make hugepage allocate reliable When ZONE_MOVABLE is used to make huge page allocation more reliable, disallowing gigantic pages memory in this region is pointless. If hotplug is not a requirement, we can loosen the restrictions to allow 1GB gigantic pages in ZONE_MOVABLE. Since 1GB can be difficult to migrate / has impacts on compaction / defragmentation, we don't enable this by default. Notably, 1GB pages can only be migrated if another 1GB page is available - so hot-unplug will fail if such a page cannot be found. However, since there are scenarios where gigantic pages are migratable, we should allow use of these on movable regions. When not valid 1GB is available for migration, hot-unplug will retry indefinitely (or until interrupted). For example: echo 0 > node0/hugepages/..-1GB/nr_hugepages # clear node0 1GB pages echo 1 > node1/hugepages/..-1GB/nr_hugepages # reserve node1 1GB page ./alloc_huge_node1 & # Allocate a 1GB page on node1 ./node1_offline & # attempt to offline all node1 memory echo 1 > node0/hugepages/..-1GB/nr_hugepages # reserve node0 1GB page In this example, node1_offline will block indefinitely until the final step, when a node0 1GB page is made available. Note: Boot-time CMA is not possible for driver-managed hotplug memory, as CMA requires the memory to be registered as SystemRAM at boot time. Additionally, 1GB huge pages are not supported by THP. Cc: David Hildenbrand Cc: Mel Gorman Cc: Michal Hocko Suggested-by: David Rientjes Signed-off-by: Gregory Price Link: https://lore.kernel.org/all/20180201193132.Hk7vI_xaU%25akpm@linux-fou= ndation.org/ Acked-by: David Hildenbrand (Red Hat) Acked-by: David Rientjes --- v5: build fixes, clean allconfig build with intel/klp. Sorry about the careless churn Andrew, should be clean now. .../admin-guide/mm/memory-hotplug.rst | 14 ++++++++-- Documentation/admin-guide/sysctl/vm.rst | 28 +++++++++++++++++++ include/linux/hugetlb.h | 3 +- mm/hugetlb_sysctl.c | 11 ++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/memory-hotplug.rst b/Documentatio= n/admin-guide/mm/memory-hotplug.rst index 33c886f3d198..6581558fd0d7 100644 --- a/Documentation/admin-guide/mm/memory-hotplug.rst +++ b/Documentation/admin-guide/mm/memory-hotplug.rst @@ -612,8 +612,9 @@ ZONE_MOVABLE, especially when fine-tuning zone ratios: allocations and silently create a zone imbalance, usually triggered by inflation requests from the hypervisor. =20 -- Gigantic pages are unmovable, resulting in user space consuming a - lot of unmovable memory. +- Gigantic pages are unmovable when an architecture does not support + huge page migration and/or the ``movable_gigantic_pages`` sysctl is fals= e. + See Documentation/admin-guide/sysctl/vm.rst for more info on this sysctl. =20 - Huge pages are unmovable when an architectures does not support huge page migration, resulting in a similar issue as with gigantic pages. @@ -672,6 +673,15 @@ block might fail: - Concurrent activity that operates on the same physical memory area, such= as allocating gigantic pages, can result in temporary offlining failures. =20 +- When an admin sets the ``movable_gigantic_pages`` sysctl to true, gigant= ic + pages are allowed in ZONE_MOVABLE. This only allows migratable gigantic + pages to be allocated; however, if there are no eligible destination gig= antic + pages at offline, the offlining operation will fail. + + Users leveraging ``movable_gigantic_pages`` should weigh the value of + ZONE_MOVABLE for increasing the reliability of gigantic page allocation + against the potential loss of hot-unplug reliability. + - Out of memory when dissolving huge pages, especially when HugeTLB Vmemmap Optimization (HVO) is enabled. =20 diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-= guide/sysctl/vm.rst index 4d71211fdad8..d2e13413e16e 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -54,6 +54,7 @@ Currently, these files are in /proc/sys/vm: - mmap_min_addr - mmap_rnd_bits - mmap_rnd_compat_bits +- movable_gigantic_pages - nr_hugepages - nr_hugepages_mempolicy - nr_overcommit_hugepages @@ -624,6 +625,33 @@ This value can be changed after boot using the /proc/sys/vm/mmap_rnd_compat_bits tunable =20 =20 +movable_gigantic_pages +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This parameter controls whether gigantic pages may be allocated from +ZONE_MOVABLE. If set to non-zero, gigantic pages can be allocated +from ZONE_MOVABLE. ZONE_MOVABLE memory may be created via the kernel +boot parameter `kernelcore` or via memory hotplug as discussed in +Documentation/admin-guide/mm/memory-hotplug.rst. + +Support may depend on specific architecture. + +Note that using ZONE_MOVABLE gigantic pages make memory hotremove unreliab= le. + +Memory hot-remove operations will block indefinitely until the admin reser= ves +sufficient gigantic pages to service migration requests associated with the +memory offlining process. As HugeTLB gigantic page reservation is a manual +process (via `nodeN/hugepages/.../nr_hugepages` interfaces) this may not be +obvious when just attempting to offline a block of memory. + +Additionally, as multiple gigantic pages may be reserved on a single block, +it may appear that gigantic pages are available for migration when in real= ity +they are in the process of being removed. For example if `memoryN` contains +two gigantic pages, one reserved and one allocated, and an admin attempts = to +offline that block, this operations may hang indefinitely unless another +reserved gigantic page is available on another block `memoryM`. + + nr_hugepages =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 019a1c5281e4..5c190b22108e 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -171,6 +171,7 @@ bool hugetlbfs_pagecache_present(struct hstate *h, =20 struct address_space *hugetlb_folio_mapping_lock_write(struct folio *folio= ); =20 +extern int movable_gigantic_pages __read_mostly; extern int sysctl_hugetlb_shm_group __read_mostly; extern struct list_head huge_boot_pages[MAX_NUMNODES]; =20 @@ -924,7 +925,7 @@ static inline bool hugepage_movable_supported(struct hs= tate *h) if (!hugepage_migration_supported(h)) return false; =20 - if (hstate_is_gigantic(h)) + if (hstate_is_gigantic(h) && !movable_gigantic_pages) return false; return true; } diff --git a/mm/hugetlb_sysctl.c b/mm/hugetlb_sysctl.c index bd3077150542..e74cf18ad431 100644 --- a/mm/hugetlb_sysctl.c +++ b/mm/hugetlb_sysctl.c @@ -8,6 +8,8 @@ =20 #include "hugetlb_internal.h" =20 +int movable_gigantic_pages; + #ifdef CONFIG_SYSCTL static int proc_hugetlb_doulongvec_minmax(const struct ctl_table *table, i= nt write, void *buffer, size_t *length, @@ -125,6 +127,15 @@ static const struct ctl_table hugetlb_table[] =3D { .mode =3D 0644, .proc_handler =3D hugetlb_overcommit_handler, }, +#ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION + { + .procname =3D "movable_gigantic_pages", + .data =3D &movable_gigantic_pages, + .maxlen =3D sizeof(int), + .mode =3D 0644, + .proc_handler =3D proc_dointvec, + }, +#endif }; =20 void __init hugetlb_sysctl_init(void) --=20 2.52.0