From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 188713988E3 for ; Mon, 13 Apr 2026 07:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776066301; cv=none; b=Sfk7rWOLM6Y+9tQIeP5r82uGA02uNdk80sO3qzbQSWs6IRBC5mCW/Cajjx5xqEoch/pdiSba0s91PQ5VZ4Jozi7ZHBZw8/nWrJ5jK1FmQLCvdNofhbV3W5UAalBeLdoFuddFM68rl9VXvmFeGP0n+d0qJ8+QoSvd1qrerKdL69Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776066301; c=relaxed/simple; bh=eaKGgV2EnLtxmq33JJLj/dYzBmiozYO1bQPRfgQi93o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bSgenZJVNWc/VXtvV4CnSlhcydruAtseeO2iqfPZDQQG63gFe2mS0UzqKIkAvpysirjzHEkIENwJZuVwzmWcomHhWVnM4Se2f1Q0J9YQb/I88MYwncRl+7j72KrwkuAIsUSut8upaksR3K8twJlzfYyYBWpzEb8e0COLxsHIi5E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aumniG8d; arc=none smtp.client-ip=74.125.82.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aumniG8d" Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-1274204434bso2278215c88.1 for ; Mon, 13 Apr 2026 00:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776066299; x=1776671099; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3n2Y5xzqBT13fCT8NafM8IZJKMHdw2LLWT217qys08w=; b=aumniG8dlLVXg4rH0KFGoI/yqlxJ2pTZsIJyhFG/2/0ZYbHVpzdvawnZLMKqgJPS7V odyDq73wFRieT9I7d5MGNwUE0XMGnx5XTW5UN8kQ/px2v+CjIfKZ8SmEr7TbQrWIhdoi yjkEwS9UxhQxtr918L0qTINsLWtPNAY3ywmZvDTFLVwXM7iKxFZCIhbdg2zfe3T56Lvu //L2v93Ai5TDGIyh0Zfq5cDiUPv1UfA6fEvQ6s19w4hVRmyNWEgp0JkQqYmcRM91gXFp r3f+ayi7BGBrWoWZbPF8Zbc9hPj65KfLwqrBhoC1RW9Dm4oIh3Pf/y5YeJORwFyFnuLl PmJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776066299; x=1776671099; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=3n2Y5xzqBT13fCT8NafM8IZJKMHdw2LLWT217qys08w=; b=TBHQUFbWLnbsxU7hTo8GQkY8WuaIuzn2Jo95BwEywE5Ect1MDxLnZh04/maQ7xVgm0 Gv8N7OXobYh1ENdWJnZHoo+mc2tZ+2w3KZOjcRApb9enmyK5C0V44DeNSFbd3fEkXP1n DgKCz0SuRljD8YugarCJC3fyuGmKayQj+m4zbPBA74sqPvp1JDxQfovCo4WN54++/OtZ 94wzPltld4yoJDRAqt45tLGssmQ5uu1ITRa0QhFnPIhznojWfMIm19utn3MtF+QVE8CT wAts/Zs8te823jGkiKIp6PGCagdd16d/eElCMTV48sDpW4Das+TDdNpouyjXrOGeib8Q Qpyw== X-Forwarded-Encrypted: i=1; AFNElJ9AlRCj2/UJcTl6Xdr8j2KNeTaMrK+sBh7Y7dQFUSzWbEEf3gKfeGVj/zZNL/bsP/31arKH0K4RXJs=@vger.kernel.org X-Gm-Message-State: AOJu0YyJQVDq6/KyQKSTboY3RrblUpjH2nGUQp3QtZNXO1k3aDY/5aZz p+lGmpb849AMHWIbEjFaE68f2Dr2Q0zFASXov+iY/JlxcsUyTDfo0vYD X-Gm-Gg: AeBDietkKKhKqrZRWJtPf8D2u4e9UIQDVLFAC9gEQk1ukckljpXZ3He9xCzSA0jfovn dQGfgtAeupQ8aLycVEcR7afx9rW9pc5bT5tclA+1bmJjTuIEzmvJTBPqqdv7QJeVJwAR2a3FZ6x Ig/aczaWX5uYc7c4hFSr1OclC6EsNpZkqP3YEKwOMP5LLqNMs6OlMouN0Su/i78ZZA6XGM+wJtk iDlmONuWf6hXeYBZuj/ymbaY+K0QqU6sf+qLF9wX9xEmKI3qW7iJ+VjVTAkwVi0AYeR0SUA4L8C wcYId7WBj8nBSHg8j87QpZ+88QujrITYDmpq2C5mYJ9w+F5fmguqB4h9YRo89pBpUMw7P00U/04 gSXK4eNt6Ob7IkgtQ3IklMnMNrqy5ckN9rel8MZjbrU0gxlppDXkiVqftDIbuCPv2gq/yotlGsg SEyB1pPUgXZ0JiLN2r X-Received: by 2002:a05:7022:e1d:b0:119:e569:f874 with SMTP id a92af1059eb24-12c35300841mr5317906c88.17.1776066298973; Mon, 13 Apr 2026 00:44:58 -0700 (PDT) Received: from wujing. ([74.48.213.230]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12c347fa2c9sm12884610c88.15.2026.04.13.00.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 00:44:58 -0700 (PDT) From: Qiliang Yuan Date: Mon, 13 Apr 2026 15:43:15 +0800 Subject: [PATCH v2 09/12] cgroup/cpuset: Introduce CPUSet-driven dynamic housekeeping (DHM) Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260413-wujing-dhm-v2-9-06df21caba5d@gmail.com> References: <20260413-wujing-dhm-v2-0-06df21caba5d@gmail.com> In-Reply-To: <20260413-wujing-dhm-v2-0-06df21caba5d@gmail.com> To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Ingo Molnar , Thomas Gleixner , Tejun Heo , Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Waiman Long , Chen Ridong , =?utf-8?q?Michal_Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan , Shuah Khan Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Qiliang Yuan X-Mailer: b4 0.13.0 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 --- 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