From nobody Tue Dec 2 01:05:38 2025 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 DC4C42E0417 for ; Fri, 21 Nov 2025 19:28:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763753295; cv=none; b=GrM3QXe7BpVmlqewOR/xGxbDl7XGXnMV+paOlT/7voJEzk/JEOBXu6BPSb6/bSibEAL8As3RI6IEyNYJ/d3iUAbFtzMD1OOYxxtZfe3Q/dzb3L6/BX6wk0GM3HJ4Ss0hfu0n5aLHfQSMu4LRno0AJ9bGoTEitEoqinCt8nMTwnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763753295; c=relaxed/simple; bh=YEdwOnm9YIl7TDLwBGq/A83czaS9Rw7BLjoUMYfP6yw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WcPuYS9Owr3RrYNZxBQRiOcMPPeLwot35Kiud7Nc/AKNQ/K2sqg+OSh11AoUewfBU9MYBFHQIJYIiIyyaX0+GWFZuNf9Lq0Is8V/SmWRh/D/1V11ya19gfI4/hzY4Dp/1WtSM0CFAeXEmJjtocusszaNumMiQmzlNuVbRwfJNkM= 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=S8HcKapu; arc=none smtp.client-ip=209.85.222.173 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="S8HcKapu" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-8b2d56eaaceso236223185a.0 for ; Fri, 21 Nov 2025 11:28:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1763753291; x=1764358091; 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=RmkDvjDU7TRVcLAaWRGk7ehFgQyf069RSfjz3jOooEk=; b=S8HcKapuxUvfwNdxJRqk1XkbNDYMJq2k2o2qGftPTDENBXqKA960jfLW0eqOxgT0+f ZO7Corkv1nyQF2KfkLc1xqouo3Mgf+xGP9Z85mqRSwNMXk/Gsjaccheb1/mesAm/xbvC QcU0BAu6Spb6EfOZjNzoN/VbT1vwXdOKG+ePMBTreyO6dlxN8a6uzTxi0RgIG+AmLeVP 0RJ1qw8dHBKFSbEY/xcFLWUs9+kQGq9sFvm5cuZGwVPd/yB5GyZcIckMeCleU+a1WF1E 6cMTf3A7UoZl0hpzY3npqMuMgumzuykLgS+I587aMqT1jy7aV/Ql0KZjpueS1wK8xYWP jzQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763753291; x=1764358091; 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=RmkDvjDU7TRVcLAaWRGk7ehFgQyf069RSfjz3jOooEk=; b=s5pbeV3bMFOvngQK3WdY9mSETJVzSV+aHd1GubQS3TT4hs2AqTV/optiXA3tf/hPmH E24zokSxBqRlQrCNK+XHnsC6krBv5FhnNkZgKdzyNcwfZOaHX+yhKOonqw1rtn6OAhIM 6hlUIsw8ACIRhAIylcHDjgM19j4bSx09fJHtgA6q9cS6tGwbnIJ/b3KniYi6yp458dQx NurhaLjPMMpV1GaaTCpXTDiwOsiMO59KWwbjauIkbe2qP0obDAoiqsIl8aliDjoemhAp TMoNfFX58y/SWfLWPe/QWXkSN8Ko8kT8FibyMJwiCLiGBIYg/rmRj9f3pstati6Mrw9P RvnQ== X-Forwarded-Encrypted: i=1; AJvYcCVnlN0HzgZXV6orNveMcy+GcP7Qn59WqPAwK9/K4sugZPdfUuffAWDI5qGrvBYzv6YB63O0uAhjkjrmKQ4=@vger.kernel.org X-Gm-Message-State: AOJu0YxCY/zpO3B4jkOPDCobm4MRPMxqMp7+Hj64zNp0pmHEa/GN2tZK +DII1oCapaZQwMSndGRlCvrCaPJ0ezg83fP5r8RPQj0vYgtXYfm3l2ll7yxUGakjVqA= X-Gm-Gg: ASbGncuILWCgVG/PKFYfTGYtGmKyCoUzjxmWpOC4LlHF36KGFeiWmyc4nwol9Fa5VGY BLc7yG4xSvwppvAHvuqelFOWmcQblv9Oe3wQXf1A5DNzFEtCrfZC48pbYfpkk3twVWKUCUMaeCN I8BEXeieXDg6Woi2zsYuXsJkuG6+RS0f4Nm6dlFUTbEM5HDhBhzJ3ZERNSH11ZmH7BtLmq3/kp3 oA+m/zgsMm96XWAv4+lJa4VGeZDfBXJ6CoIL3yYN2rneOOhY4a42S9K2SB9VyiQhlYkZXsyUO3F j6aH4GFU/SYxx73US5eu8ISXK1rxk3qJeB8OAR/B3Sy+V7OYZpXZzKU+UEa/gOydz7HhcBDk/6c vwlRGDc/JCuONKJ4xx+3Vre0oI+bricLrH1MTB8dj6g2famZw6MNTQNiT6ZPQYrF/a3m2GSYKsg VE/fGi7f0wAbQQW4AcM1aFiZ3PxKfWAbC/FTSN1lAdbmoWMcGsuOQA9Kh+7888GtkEVm8qwGWdo e4= X-Google-Smtp-Source: AGHT+IGOwz+Ob3Ojd8jzT+Htqg0f5uBZ2/mLq7SGDY02ShxixMShiy5UBT0QeyT32i05L1pHTAu4Ew== X-Received: by 2002:a05:620a:46a0:b0:8b2:6a4f:ba70 with SMTP id af79cd13be357-8b33d46a386mr406791385a.76.1763753291490; Fri, 21 Nov 2025 11:28:11 -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-8b3295ef333sm423134485a.49.2025.11.21.11.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 11:28:10 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: kernel-team@meta.com, vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, linux-kernel@vger.kernel.org, David Hildenbrand , Mel Gorman , Alexandru Moise <00moses.alexander00@gmail.com>, David Rientjes Subject: [PATCH v2] mm, hugetlb: implement movable_gigantic_pages sysctl Date: Fri, 21 Nov 2025 14:27:46 -0500 Message-ID: <20251121192746.256051-1-gourry@gourry.net> X-Mailer: git-send-email 2.51.1 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=20 commit d6cb41cc44c6 ("mm, hugetlb: remove hugepages_treat_as_movable sysctl= ") This sysctl provides some flexibility between multiple 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. 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 Cc: Alexandru Moise <00moses.alexander00@gmail.com> Suggested-by: David Rientjes Signed-off-by: Gregory Price Link: https://lore.kernel.org/all/20180201193132.Hk7vI_xaU%25akpm@linux-fou= ndation.org/ --- Documentation/admin-guide/sysctl/vm.rst | 17 +++++++++++++++++ include/linux/hugetlb.h | 3 ++- mm/hugetlb.c | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) --- v2: changelog updates diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-= guide/sysctl/vm.rst index b325bfbc2611..fe3982604b1f 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 @@ -623,6 +624,22 @@ 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 hugepages 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 may make features like +memory hotremove more unreliable, as migrating gigantic pages is more +difficult due to needing larger amounts of phyiscally contiguous memory. + + 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 eb21619206af..451ede7b97dd 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -172,6 +172,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; extern struct list_head huge_boot_pages[MAX_NUMNODES]; =20 @@ -916,7 +917,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.c b/mm/hugetlb.c index 5b77fef5c4fd..c6363dad1e92 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -54,6 +54,8 @@ #include "hugetlb_cma.h" #include =20 +int movable_gigantic_pages; + int hugetlb_max_hstate __read_mostly; unsigned int default_hstate_idx; struct hstate hstates[HUGE_MAX_HSTATE]; @@ -5208,6 +5210,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 static void __init hugetlb_sysctl_init(void) --=20 2.51.1