On 2026/4/21 11:03, Waiman Long wrote:
> By making sure that isolated_hk_cpus matches isolated_cpus at boot time,
> we can more accurately determine if calling housekeeping_update()
> is needed by comparing if the two cpumasks are equal. The
> update_housekeeping flag still have a use in cpuset_handle_hotplug()
> to determine if a work function should be queued to invoke
> cpuset_update_sd_hk_unlock() as it is not supposed to look at
> isolated_hk_cpus without holding cpuset_top_mutex.
>
Currently, isolated_hk_cpus is updated within the cpuset_mutex critical section
(before mutex_unlock(&cpuset_mutex)) in cpuset_update_sd_hk_unlock. Therefore, I
think update_housekeeping can now be removed.
> Signed-off-by: Waiman Long <[email protected]>
> ---
> kernel/cgroup/cpuset.c | 36 ++++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index a4eccb0ec0d1..1b0c50b46a49 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1339,26 +1339,29 @@ static void cpuset_update_sd_hk_unlock(void)
> __releases(&cpuset_mutex)
> __releases(&cpuset_top_mutex)
> {
> + update_housekeeping = false;
> +
> /* force_sd_rebuild will be cleared in rebuild_sched_domains_locked() */
> if (force_sd_rebuild)
> rebuild_sched_domains_locked();
>
> - if (update_housekeeping) {
> - update_housekeeping = false;
> - cpumask_copy(isolated_hk_cpus, isolated_cpus);
> -
> - /*
> - * housekeeping_update() is now called without holding
> - * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex
> - * is still being held for mutual exclusion.
> - */
> - mutex_unlock(&cpuset_mutex);
> - cpus_read_unlock();
> - WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus,
> BIT(HK_TYPE_DOMAIN)));
> - mutex_unlock(&cpuset_top_mutex);
> - } else {
> + if (cpumask_equal(isolated_hk_cpus, isolated_cpus)) {
> + /* No housekeeping cpumask update needed */
> cpuset_full_unlock();
> + return;
> }
> +
> + cpumask_copy(isolated_hk_cpus, isolated_cpus);
> +
> + /*
> + * housekeeping_update() is now called without holding
> + * cpus_read_lock and cpuset_mutex. Only cpuset_top_mutex
> + * is still being held for mutual exclusion.
> + */
> + mutex_unlock(&cpuset_mutex);
> + cpus_read_unlock();
> + WARN_ON_ONCE(housekeeping_update(isolated_hk_cpus,
> BIT(HK_TYPE_DOMAIN)));
> + mutex_unlock(&cpuset_top_mutex);
> }
>
> /*
> @@ -3692,10 +3695,11 @@ int __init cpuset_init(void)
>
> BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL));
>
> - if (housekeeping_enabled(HK_TYPE_DOMAIN_BOOT))
> + if (housekeeping_enabled(HK_TYPE_DOMAIN_BOOT)) {
> cpumask_andnot(isolated_cpus, cpu_possible_mask,
> housekeeping_cpumask(HK_TYPE_DOMAIN_BOOT));
> -
> + cpumask_copy(isolated_hk_cpus, isolated_cpus);
> + }
> return 0;
> }
>
--
Best regards,
Ridong