Skip to content

Commit 71f7456

Browse files
tpressureakpm00
authored andcommitted
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>
1 parent c34b3ec commit 71f7456

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,15 @@
18821882
Documentation/admin-guide/mm/hugetlbpage.rst.
18831883
Format: size[KMG]
18841884

1885+
hugepage_alloc_threads=
1886+
[HW] The number of threads that should be used to
1887+
allocate hugepages during boot. This option can be
1888+
used to improve system bootup time when allocating
1889+
a large amount of huge pages.
1890+
The default value is 25% of the available hardware threads.
1891+
1892+
Note that this parameter only applies to non-gigantic huge pages.
1893+
18851894
hugetlb_cma= [HW,CMA,EARLY] The size of a CMA area used for allocation
18861895
of gigantic hugepages. Or using node format, the size
18871896
of a CMA area per node can be specified.

Documentation/admin-guide/mm/hugetlbpage.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,17 @@ hugepages
145145

146146
It will allocate 1 2M hugepage on node0 and 2 2M hugepages on node1.
147147
If the node number is invalid, the parameter will be ignored.
148+
hugepage_alloc_threads
149+
Specify the number of threads that should be used to allocate hugepages
150+
during boot. This parameter can be used to improve system bootup time
151+
when allocating a large amount of huge pages.
148152

153+
The default value is 25% of the available hardware threads.
154+
Example to use 8 allocation threads::
155+
156+
hugepage_alloc_threads=8
157+
158+
Note that this parameter only applies to non-gigantic huge pages.
149159
default_hugepagesz
150160
Specify the default huge page size. This parameter can
151161
only be specified once on the command line. default_hugepagesz can

mm/hugetlb.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static unsigned long __initdata default_hstate_max_huge_pages;
8585
static bool __initdata parsed_valid_hugepagesz = true;
8686
static bool __initdata parsed_default_hugepagesz;
8787
static unsigned int default_hugepages_in_node[MAX_NUMNODES] __initdata;
88+
static unsigned long hugepage_allocation_threads __initdata;
8889

8990
static char hstate_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
9091
static int hstate_cmdline_index __initdata;
@@ -3607,8 +3608,6 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h)
36073608
.numa_aware = true
36083609
};
36093610

3610-
unsigned int num_allocation_threads = max(num_online_cpus() / 4, 1);
3611-
36123611
job.thread_fn = hugetlb_pages_alloc_boot_node;
36133612
job.start = 0;
36143613
job.size = h->max_huge_pages;
@@ -3629,9 +3628,13 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h)
36293628
* | cascade lake 192 cpus | 39s | 20s | 11s | 10s | 9s |
36303629
* +-----------------------+-------+-------+-------+-------+-------+
36313630
*/
3631+
if (hugepage_allocation_threads == 0) {
3632+
hugepage_allocation_threads = num_online_cpus() / 4;
3633+
hugepage_allocation_threads = max(hugepage_allocation_threads, 1);
3634+
}
36323635

3633-
job.max_threads = num_allocation_threads;
3634-
job.min_chunk = h->max_huge_pages / num_allocation_threads;
3636+
job.max_threads = hugepage_allocation_threads;
3637+
job.min_chunk = h->max_huge_pages / hugepage_allocation_threads;
36353638
padata_do_multithreaded(&job);
36363639

36373640
return h->nr_huge_pages;
@@ -5000,6 +5003,28 @@ void __init hugetlb_bootmem_alloc(void)
50005003
__hugetlb_bootmem_allocated = true;
50015004
}
50025005

5006+
/*
5007+
* hugepage_alloc_threads command line parsing.
5008+
*
5009+
* When set, use this specific number of threads for the boot
5010+
* allocation of hugepages.
5011+
*/
5012+
static int __init hugepage_alloc_threads_setup(char *s)
5013+
{
5014+
unsigned long allocation_threads;
5015+
5016+
if (kstrtoul(s, 0, &allocation_threads) != 0)
5017+
return 1;
5018+
5019+
if (allocation_threads == 0)
5020+
return 1;
5021+
5022+
hugepage_allocation_threads = allocation_threads;
5023+
5024+
return 1;
5025+
}
5026+
__setup("hugepage_alloc_threads=", hugepage_alloc_threads_setup);
5027+
50035028
static unsigned int allowed_mems_nr(struct hstate *h)
50045029
{
50055030
int node;

0 commit comments

Comments
 (0)