[PATCH v2 09/12] cgroup/cpuset: Introduce CPUSet-driven dynamic housekeeping (DHM)

From: Qiliang Yuan

Date: Mon Apr 13 2026 - 03:48:58 EST


Currently, subsystem housekeeping masks are generally static and can
only be configured via boot-time parameters (e.g., isolcpus, nohz_full).
This inflexible approach forces a system reboot whenever an orchestrator
needs to change workload isolation boundaries.

This patch introduces CPUSet-driven Dynamic Housekeeping Management (DHM)
by exposing the `cpuset.housekeeping.cpus` control file on the root cgroup.
Writing a new cpumask to this file dynamically updates the housekeeping
masks of all registered subsystems (scheduler, RCU, timers, tick, workqueues,
and managed IRQs) simultaneously, without restarting the node.

At the cpuset and isolation core level, this change implements:
1. `housekeeping_update_all_types(const struct cpumask *new_mask)` API inside
`isolation.c` to safely allocate, update, and replace all enabled hk_type masks.
2. The `cpuset.housekeeping.cpus` attribute in `dfl_files` for the root cpuset.
3. Hooking the write operation to iterate over enabled housekeeping types
and invoke `housekeeping_update_notify()` (the DHM notifier chain) to
push these configuration changes live into individual kernel subsystems.

Signed-off-by: Qiliang Yuan <realwujing@xxxxxxxxx>
---
include/linux/sched/isolation.h | 12 ++++++++++++
kernel/cgroup/cpuset-internal.h | 1 +
kernel/cgroup/cpuset.c | 36 ++++++++++++++++++++++++++++++++++++
kernel/sched/isolation.c | 38 ++++++++++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+)

diff --git a/include/linux/sched/isolation.h b/include/linux/sched/isolation.h
index aea1dbc4d7486..299167f627895 100644
--- a/include/linux/sched/isolation.h
+++ b/include/linux/sched/isolation.h
@@ -48,6 +48,8 @@ extern void __init housekeeping_init(void);

extern int housekeeping_register_notifier(struct notifier_block *nb);
extern int housekeeping_unregister_notifier(struct notifier_block *nb);
+extern int housekeeping_update_notify(enum hk_type type, const struct cpumask *new_mask);
+extern int housekeeping_update_all_types(const struct cpumask *new_mask);

#else

@@ -86,6 +88,16 @@ static inline int housekeeping_unregister_notifier(struct notifier_block *nb)
{
return 0;
}
+
+static inline int housekeeping_update_notify(enum hk_type type, const struct cpumask *new_mask)
+{
+ return 0;
+}
+
+static inline int housekeeping_update_all_types(const struct cpumask *new_mask)
+{
+ return 0;
+}
#endif /* CONFIG_CPU_ISOLATION */

static inline bool housekeeping_cpu(int cpu, enum hk_type type)
diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-internal.h
index fd7d19842ded7..3ab437f54ecdf 100644
--- a/kernel/cgroup/cpuset-internal.h
+++ b/kernel/cgroup/cpuset-internal.h
@@ -60,6 +60,7 @@ typedef enum {
FILE_EXCLUSIVE_CPULIST,
FILE_EFFECTIVE_XCPULIST,
FILE_ISOLATED_CPULIST,
+ FILE_HOUSEKEEPING_CPULIST,
FILE_CPU_EXCLUSIVE,
FILE_MEM_EXCLUSIVE,
FILE_MEM_HARDWALL,
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 1335e437098e8..5df19dc9bfa89 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -3201,6 +3201,30 @@ static void cpuset_attach(struct cgroup_taskset *tset)
mutex_unlock(&cpuset_mutex);
}

+/*
+ * DHM interface: root cpuset allows updating global housekeeping cpumask.
+ */
+static ssize_t cpuset_write_housekeeping_cpus(struct kernfs_open_file *of,
+ char *buf, size_t nbytes, loff_t off)
+{
+ cpumask_var_t new_mask;
+ int retval;
+
+ if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
+ return -ENOMEM;
+
+ buf = strstrip(buf);
+ retval = cpulist_parse(buf, new_mask);
+ if (retval)
+ goto out_free;
+
+ retval = housekeeping_update_all_types(new_mask);
+
+out_free:
+ free_cpumask_var(new_mask);
+ return retval ?: nbytes;
+}
+
/*
* Common handling for a write to a "cpus" or "mems" file.
*/
@@ -3290,6 +3314,9 @@ int cpuset_common_seq_show(struct seq_file *sf, void *v)
case FILE_ISOLATED_CPULIST:
seq_printf(sf, "%*pbl\n", cpumask_pr_args(isolated_cpus));
break;
+ case FILE_HOUSEKEEPING_CPULIST:
+ seq_printf(sf, "%*pbl\n", cpumask_pr_args(housekeeping_cpumask(HK_TYPE_DOMAIN)));
+ break;
default:
ret = -EINVAL;
}
@@ -3428,6 +3455,15 @@ static struct cftype dfl_files[] = {
.flags = CFTYPE_ONLY_ON_ROOT,
},

+ {
+ .name = "housekeeping.cpus",
+ .seq_show = cpuset_common_seq_show,
+ .write = cpuset_write_housekeeping_cpus,
+ .max_write_len = (100U + 6 * NR_CPUS),
+ .private = FILE_HOUSEKEEPING_CPULIST,
+ .flags = CFTYPE_ONLY_ON_ROOT,
+ },
+
{ } /* terminate */
};

diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 0462b41807161..a92b0bb41de3a 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -27,6 +27,7 @@ enum hk_flags {
#define HK_FLAG_KERNEL_NOISE (HK_FLAG_TICK | HK_FLAG_TIMER | HK_FLAG_RCU | \
HK_FLAG_MISC | HK_FLAG_WQ | HK_FLAG_KTHREAD)

+static DEFINE_MUTEX(housekeeping_mutex);
static BLOCKING_NOTIFIER_HEAD(housekeeping_notifier_list);

DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
@@ -196,6 +197,43 @@ int housekeeping_update_notify(enum hk_type type, const struct cpumask *new_mask
}
EXPORT_SYMBOL_GPL(housekeeping_update_notify);

+int housekeeping_update_all_types(const struct cpumask *new_mask)
+{
+ enum hk_type type;
+ struct cpumask *old_masks[HK_TYPE_MAX] = { NULL };
+
+ if (cpumask_empty(new_mask) || !cpumask_intersects(new_mask, cpu_online_mask))
+ return -EINVAL;
+
+ if (!housekeeping.flags)
+ static_branch_enable(&housekeeping_overridden);
+
+ mutex_lock(&housekeeping_mutex);
+ for_each_set_bit(type, &housekeeping.flags, HK_TYPE_MAX) {
+ struct cpumask *nmask = kmalloc(cpumask_size(), GFP_KERNEL);
+
+ if (!nmask) {
+ mutex_unlock(&housekeeping_mutex);
+ return -ENOMEM;
+ }
+
+ cpumask_copy(nmask, new_mask);
+ old_masks[type] = housekeeping_cpumask_dereference(type);
+ rcu_assign_pointer(housekeeping.cpumasks[type], nmask);
+ }
+ mutex_unlock(&housekeeping_mutex);
+
+ synchronize_rcu();
+
+ for_each_set_bit(type, &housekeeping.flags, HK_TYPE_MAX) {
+ housekeeping_update_notify(type, new_mask);
+ kfree(old_masks[type]);
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(housekeeping_update_all_types);
+
void __init housekeeping_init(void)
{
enum hk_type type;

--
2.43.0