Re: [PATCH-next 1/6] cgroup/cpuset: Find furthest isolated ancestor for invalidated isolated partition
From: Guopeng Zhang
Date: Thu Oct 22 2026 - 09:29:14 EST
在 2026/10/22 11:16, Waiman Long 写道:
> Commit 46b885416c27 ("cgroup/cpuset: Fix a missing isolated_cpus
> update in update_cpumasks_hier()") searches for the closet partition
> root ancestor to determine if the isolated CPUs in a to be invalidated
> isolation partition should be removed from isolated_cpus or not.
>
> As reported by sashiko, this method may not work when there is a deeply
> nested isolated partition hierarchy. For instance, Consider a nested
> hierarchy A0 -> A1 -> A2 -> A3 where all four are PRS_ISOLATED:
>
> A0: effective_xcpus = 0-4
> A1: effective_xcpus = 1-4
> A2: effective_xcpus = 2-4
> A3: effective_xcpus = 3-4
>
> When A1 shrinks its exclusive_cpus from 1-4 to 1-2, A2 will update it
> effective_xcpus to 2. A3 will find its closet partition root ancestor
> A2 and decides that its effective_xcpus 3-4 should be removed from
> isolated_cpus which is incorrect.
>
> Address this corner case by searching for the furthest isolated partition
> root ancestor instead to decide if its isolated CPUs should be returned
> to isolated_cpus.
>
This looks good to me. Would it be worth adding a test case for the
scenario described above, something like:
# A middle isolated parent shrunk below coverage: the released
# CPUs of the invalidated child stay isolated as a higher
# ancestor still covers them.
" CX0-4:P2 CX2-4:P2 CX3-4:P2 . . X2 . . 0 A1:0-1,3-4|A2:2|A3:2 A1:P2|A2:P2|A3:P-2 0-4"
Reviewed-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
Tested-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
Thanks,
Guopeng
> Fixes: 46b885416c27 ("cgroup/cpuset: Fix a missing isolated_cpus update in update_cpumasks_hier()")
> Signed-off-by: Waiman Long <longman@xxxxxxxxxx>
> ---
> kernel/cgroup/cpuset.c | 36 +++++++++++++++++-------------------
> 1 file changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 585a982249ad..7ead8c3b7974 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -2156,22 +2156,20 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
> }
>
> /*
> - * ancestor_partition - Find and return the closest valid partition root ancestor
> + * iancestor_partition - Return furthest isolated partition root ancestor available
> * @cs: the current cpuset
> - *
> - * Return: The closet partition root ancestor cpuset
> + * Return: The furthest isolated partition root ancestor available or NULL if
> + * not found.
> */
> -static struct cpuset *ancestor_partition(struct cpuset *cs)
> +static struct cpuset *iancestor_partition(struct cpuset *cs)
> {
> struct cpuset *ancestor = parent_cs(cs);
> + struct cpuset *iancestor = NULL;
>
> - /*
> - * The top_cpuset is always a valid partition root which will stop
> - * the loop if it is reached.
> - */
> - while (!is_partition_valid(ancestor))
> - ancestor = parent_cs(ancestor);
> - return ancestor;
> + for (; ancestor; ancestor = parent_cs(ancestor))
> + if (ancestor->partition_root_state == PRS_ISOLATED)
> + iancestor = ancestor;
> + return iancestor;
> }
>
> /*
> @@ -2283,23 +2281,23 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
> * For a to be invalidated isolated partition,
> * its isolated CPUs may or may not need to be
> * removed from isolated_cpus depending on if
> - * its closest partition root ancestor is a root
> - * or isolated partition. With a PRS_ISOLATED
> - * ancestor, the CPUs are checked against its
> - * effective xcpus to see if any of them needed
> - * to be removed.
> + * there is a furthest isolated partition root
> + * ancestor available. When such a PRS_ISOLATED
> + * ancestor is available, the CPUs are checked
> + * against its effective xcpus to see if any of
> + * them needed to be removed.
> */
> if (is_partition_valid(cp))
> new_prs = -old_prs;
>
> if (old_prs == PRS_ISOLATED) {
> - struct cpuset *ancestor = ancestor_partition(cp);
> + struct cpuset *iancestor = iancestor_partition(cp);
>
> - if (ancestor->partition_root_state == PRS_ROOT)
> + if (!iancestor)
> del_cpus = cp->effective_xcpus;
> else if (cpumask_andnot(tmp->delmask,
> cp->effective_xcpus,
> - ancestor->effective_xcpus))
> + iancestor->effective_xcpus))
> del_cpus = tmp->delmask;
>
> if (del_cpus) {