Re: [PATCH] kernel/fork: declare max_threads __read_mostly
From: Lorenzo Stoakes
Date: Sat Jul 11 2026 - 05:26:50 EST
On Tue, 07 Jul 2026 17:23:54 +0800, JianChunfu <jansef.jian@xxxxxxxxxxxx> wrote:
> [...]
> after patch:
> hachbench -g 100 500 1000 2000
> 0.823 4.487 11.107 32.987
>
> Above data are the average values obtained from multiple tests, and
> there was indeed some fluctuation in the data during the tests.
Seems nice though you do wonder if there's other factors at play on the
delta.
>
> Signed-off-by: JianChunfu <jansef.jian@xxxxxxxxxxxx>
It does seem nr_threads is very rarely written too so read mostly is valid,
and given observed improvement even if there's noise this seems legit so:
>
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index f0e2e131a9a5..516faec8efb8 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -143,7 +143,7 @@
> unsigned long total_forks; /* Handle normal Linux uptimes. */
> int nr_threads; /* The idle threads do not count.. */
>
> -static int max_threads; /* tunable limit on nr_threads */
> +static int max_threads __read_mostly; /* tunable limit on nr_threads */
>
> #define NAMED_ARRAY_INDEX(x) [x] = __stringify(x)
>
Cheers, Lorenzo
Reviewed-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
--
Lorenzo Stoakes <ljs@xxxxxxxxxx>