summaryrefslogtreecommitdiff
path: root/mm/hugetlb.c
diff options
context:
space:
mode:
authorThomas Prescher <thomas.prescher@cyberus-technology.de>2025-02-27 23:45:06 +0100
committerAndrew Morton <akpm@linux-foundation.org>2025-03-17 00:05:36 -0700
commit71f745688985c59eee41ffe88497a9e62774a9bf (patch)
tree08e146053b20def4578cc7b9975b264550bc1500 /mm/hugetlb.c
parentc34b3eceeac64d59f8b475046501faa5d8daa5a4 (diff)
mm: hugetlb: add hugetlb_alloc_threads cmdline option
Add a command line option that enables control of how many threads should be used to allocate huge pages. [akpm@linux-foundation.org: tidy up a comment] Link: https://lkml.kernel.org/r/20250227-hugepage-parameter-v2-2-7db8c6dc0453@cyberus-technology.de Signed-off-by: Thomas Prescher <thomas.prescher@cyberus-technology.de> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Muchun Song <muchun.song@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/hugetlb.c')
-rw-r--r--mm/hugetlb.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index edb846452791..486365cb2ece 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -85,6 +85,7 @@ static unsigned long __initdata default_hstate_max_huge_pages;
static bool __initdata parsed_valid_hugepagesz = true;
static bool __initdata parsed_default_hugepagesz;
static unsigned int default_hugepages_in_node[MAX_NUMNODES] __initdata;
+static unsigned long hugepage_allocation_threads __initdata;
static char hstate_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
static int hstate_cmdline_index __initdata;
@@ -3607,8 +3608,6 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h)
.numa_aware = true
};
- unsigned int num_allocation_threads = max(num_online_cpus() / 4, 1);
-
job.thread_fn = hugetlb_pages_alloc_boot_node;
job.start = 0;
job.size = h->max_huge_pages;
@@ -3629,9 +3628,13 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h)
* | cascade lake 192 cpus | 39s | 20s | 11s | 10s | 9s |
* +-----------------------+-------+-------+-------+-------+-------+
*/
+ if (hugepage_allocation_threads == 0) {
+ hugepage_allocation_threads = num_online_cpus() / 4;
+ hugepage_allocation_threads = max(hugepage_allocation_threads, 1);
+ }
- job.max_threads = num_allocation_threads;
- job.min_chunk = h->max_huge_pages / num_allocation_threads;
+ job.max_threads = hugepage_allocation_threads;
+ job.min_chunk = h->max_huge_pages / hugepage_allocation_threads;
padata_do_multithreaded(&job);
return h->nr_huge_pages;
@@ -5000,6 +5003,28 @@ void __init hugetlb_bootmem_alloc(void)
__hugetlb_bootmem_allocated = true;
}
+/*
+ * hugepage_alloc_threads command line parsing.
+ *
+ * When set, use this specific number of threads for the boot
+ * allocation of hugepages.
+ */
+static int __init hugepage_alloc_threads_setup(char *s)
+{
+ unsigned long allocation_threads;
+
+ if (kstrtoul(s, 0, &allocation_threads) != 0)
+ return 1;
+
+ if (allocation_threads == 0)
+ return 1;
+
+ hugepage_allocation_threads = allocation_threads;
+
+ return 1;
+}
+__setup("hugepage_alloc_threads=", hugepage_alloc_threads_setup);
+
static unsigned int allowed_mems_nr(struct hstate *h)
{
int node;