[PATCH 4/4] sched/isolation: don't alloc twice for housekeeping.cpumasks

From: alexs
Date: Thu Apr 10 2025 - 05:26:29 EST


From: Alex Shi <alexs@xxxxxxxxxx>

The variable housekeeping.cpumasks[type] will be alloced twice if
nohz_full and isolcpus are both setup in cmdline, that shouldn't to do
so. Just alloc once is enough and save a bit memory.

Signed-off-by: Alex Shi <alexs@xxxxxxxxxx>
Cc: Valentin Schneider <vschneid@xxxxxxxxxx>
Cc: Ben Segall <bsegall@xxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Cc: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
---
kernel/sched/isolation.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index e93776740725..44ab46b31f6b 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -103,10 +103,10 @@ void __init housekeeping_init(void)
static void __init housekeeping_setup_type(enum hk_type type,
cpumask_var_t housekeeping_staging)
{
+ if (cpumask_empty(housekeeping.cpumasks[type]))
+ alloc_bootmem_cpumask_var(&housekeeping.cpumasks[type]);

- alloc_bootmem_cpumask_var(&housekeeping.cpumasks[type]);
- cpumask_copy(housekeeping.cpumasks[type],
- housekeeping_staging);
+ cpumask_copy(housekeeping.cpumasks[type], housekeeping_staging);
}

static int __init housekeeping_setup(char *str, unsigned long flags)
--
2.47.1