mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ridong Chen <ridong.chen@linux.dev>
To: Guopeng Zhang <guopeng.zhang@linux.dev>,
	Waiman Long <longman@redhat.com>,
	cgroups@vger.kernel.org
Cc: tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com,
	shuah@kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	Guopeng Zhang <zhangguopeng@kylinos.cn>
Subject: Re: [PATCH v3 1/7] cgroup/cpuset: Factor out child partition validation
Date: Tue, 8 Sep 2026 09:27:17 +0800	[thread overview]
Message-ID: <a89dab46-c6e8-4643-bf83-83fd76a38ab7@linux.dev> (raw)
In-Reply-To: <0b2b6b9d-98de-4f45-8e65-a202fe9ce0d1@linux.dev>



On 9/7/2026 6:16 PM, Guopeng Zhang wrote:
> 
> 
> 在 2026/9/4 09:55, Ridong Chen 写道:
>>
>>
>> On 9/4/2026 9:25 AM, Ridong Chen wrote:
>>>
>>>
>>> On 9/4/2026 2:33 AM, Waiman Long wrote:
>>>> On 9/2/26 6:26 AM, Guopeng Zhang wrote:
>>>>> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>>>>
>>>>> compute_partition_effective_cpumask() checks whether each valid child
>>>>> partition remains covered by the parent exclusive CPU mask and whether it
>>>>> would consume all remaining CPUs of a populated parent.
>>>>>
>>>>> Factor these two checks into child_partition_error() so the same rules can
>>>>> be reused when evaluating a proposed parent configuration. This is a
>>>>> preparatory refactoring with no intended functional change.
>>>>>
>>>>> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
>>>>> ---
>>>>>    kernel/cgroup/cpuset.c | 38 +++++++++++++++++++++++++++++---------
>>>>>    1 file changed, 29 insertions(+), 9 deletions(-)
>>>>>
>>>>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>>>>> index 8f24171b6055..6994dc75d940 100644
>>>>> --- a/kernel/cgroup/cpuset.c
>>>>> +++ b/kernel/cgroup/cpuset.c
>>>>> @@ -2085,6 +2085,26 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,
>>>>>        return 0;
>>>>>    }
>>>>> +/*
>>>>> + * Return the error that will invalidate a child partition under a proposed
>>>>> + * parent partition configuration.
>>>>> + */
>>>>> +static enum prs_errcode
>>>>> +child_partition_error(struct cpuset *child,
>>>>> +              const struct cpumask *partition_cpus,
>>>>> +              const struct cpumask *remaining_cpus,
>>>>> +              bool parent_populated)
>>>> I think you should add some functional comments on what "partition_cpus" and "remaining_cpus" are supposed to be so that caller knows what to pass into this helper.
>>>
>>> Would it help to rename them to excpus and local_excpus?
>>> local already implies "excluding children" (just like cgroup.stat.local), so I think that makes the intent clearer.
>>>
>>
>> Regarding the naming: child_partition_error is a bit odd — it sounds like it's validating a hierarchical child partition, but it's actually validating the partition itself (the child argument). The parent is only needed as context for the validation logic, not because we're checking a subordinate partition.
>>
>> I'd suggest renaming it to something like:
>>
>> ```
>> static enum prs_errcode cs_partition_error(struct cpuset *cs, ...)
>>
>> ```
>>
>> That would better reflect what the function actually does.
>>
> 
> Thanks, Ridong. I see what you mean about the name.
> 
> My intention with "child" was to describe the role of the partition in these checks. Both callers use the helper while walking a parent's child partitions, and the result depends on the parent's complete exclusive mask, whether the parent is populated, and the active CPUs remaining at that point in the walk. The helper also checks only the two conditions that can invalidate a child during this process, rather than performing general validation of an arbitrary cpuset partition.
> 
> For that reason, `cs_partition_error()` might suggest a broader scope than the helper actually has. Would it make sense to keep `child_partition_error()` and clarify the comment, for example:
> 

As you can see, we are continuing to add partition checks, so I'd still suggest 
avoiding child_partition_error(), it would become confusing when we later 
refactor the partition validation logic. All of these functions are ultimately 
used to validate a partition, and the validation may depend on either the parent 
or a trialcs, or something else.

So I'd propose keeping it as:

static enum prs_errcode cs_partition_error(struct cpuset *cs, struct cpuset 
*parent);

This is more general and better accommodates future extensions.


> /*
>   * Return the error that would invalidate @child under its parent
>   * partition's CPU configuration.
>   */
> 
> I am also open to another name that preserves this parent-child context.
> 



> 
>> On a related note, the current partition validation logic is scattered across the code. I think we should consider consolidating it into a common set of helpers, perhaps like:
>>
>>
>> ```
>> static enum prs_errcode validate_partition(struct cpuset *cs, struct cpuset *trialcs, struct cpuset *parent)
>> {
>> ...
>> }
>>
>> static enum prs_errcode validate_local_partition(struct cpuset *cs, struct cpuset *trialcs, struct cpuset *parent)
>> {
>>      // local partion specific check
>>      // call validate_partition
>>      
>> }
>>
>> static enum prs_errcode validate_remote_partition(struct cpuset *cs, struct cpuset *trialcs, struct cpuset *parent)
>> {
>>      // remote partion specific check
>>      // call validate_partition
>> }
>>
>> ```
>>
> 
> That sounds like a good idea.
> 
> Since these validation paths have different inputs and side effects, consolidating them may require a broader review and restructuring.
> 
> I will look into this separately after the current series is completed.
> 
> Thanks,
> Guopeng
>>
>>>>> +{
>>>>> +    if (!cpumask_subset(child->effective_xcpus, partition_cpus))
>>>>> +        return PERR_INVCPUS;
>>>>> +
>>>>> +    if (parent_populated &&
>>>>> +        cpumask_subset(remaining_cpus, child->effective_xcpus))
>>>>> +        return PERR_NOCPUS;
>>>>> +
>>>>> +    return PERR_NONE;
>>>>> +}
>>>>> +
>>>>>    /**
>>>>>     * compute_partition_effective_cpumask - compute effective_cpus for partition
>>>>>     * @cs: partition root cpuset
>>>>> @@ -2121,6 +2141,8 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
>>>>>        rcu_read_lock();
>>>>>        cpuset_for_each_child(child, css, cs) {
>>>>> +        enum prs_errcode child_err;
>>>>> +
>>>>>            if (!is_partition_valid(child))
>>>>>                continue;
>>>>> @@ -2129,15 +2151,13 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,
>>>>>             * partition root.
>>>>>             */
>>>>>            WARN_ON_ONCE(is_remote_partition(child));
>>>>> -        WRITE_ONCE(child->prs_err, 0);
>>>>> -        if (!cpumask_subset(child->effective_xcpus,
>>>>> -                    cs->effective_xcpus))
>>>>> -            WRITE_ONCE(child->prs_err, PERR_INVCPUS);
>>>>> -        else if (populated &&
>>>>> -             cpumask_subset(new_ecpus, child->effective_xcpus))
>>>>> -            WRITE_ONCE(child->prs_err, PERR_NOCPUS);
>>>>> -
>>>>> -        if (child->prs_err) {
>>>>> +        WRITE_ONCE(child->prs_err, PERR_NONE);
>>>>> +        child_err = child_partition_error(child, cs->effective_xcpus,
>>>>> +                          new_ecpus, populated);
>>>>> +        if (child_err)
>>>>> +            WRITE_ONCE(child->prs_err, child_err);
>>>>> +
>>>>
>>>> You can ignore the inital PERR_NONE write and always write the child_err value into child->prs_err.
>>>>
>>>> Not big issue, just some nits.
>>>>
>>>> Cheers,
>>>> Longman
>>>>
>>>>> +        if (child_err) {
>>>>>                int old_prs = child->partition_root_state;
>>>>>                /*
>>>>
>>>
>>
> 

-- 
Best regards
Ridong


  reply	other threads:[~2026-09-08  1:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 10:26 [PATCH v3 0/7] cgroup/cpuset: Fix partition type transitions Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 1/7] cgroup/cpuset: Factor out child partition validation Guopeng Zhang
2026-09-03 18:33   ` Waiman Long
2026-09-04  1:25     ` Ridong Chen
2026-09-04  1:55       ` Ridong Chen
2026-09-07 10:16         ` Guopeng Zhang
2026-09-08  1:27           ` Ridong Chen [this message]
2026-09-08 12:14             ` Guopeng Zhang
2026-09-04  1:57       ` Ridong Chen
2026-09-04  2:00       ` Ridong Chen
2026-09-07  9:49       ` Guopeng Zhang
2026-09-08  1:40         ` Ridong Chen
2026-09-08 12:25           ` Guopeng Zhang
2026-09-07  9:48     ` Guopeng Zhang
2026-09-03 19:11   ` Waiman Long
2026-09-07  9:48     ` Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 2/7] cgroup/cpuset: Account for child CPU ownership in partition changes Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 3/7] selftests/cgroup: Add tests for type-change isolation accounting Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 4/7] selftests/cgroup: Test child CPU ownership in partition changes Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 5/7] selftests/cgroup: Add tests for housekeeping CPU return to isolated parents Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 6/7] cgroup/cpuset: Release CPUs when type-change validation fails Guopeng Zhang
2026-09-02 10:26 ` [PATCH v3 7/7] selftests/cgroup: Add CPU release tests for type-change validation failures Guopeng Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a89dab46-c6e8-4643-bf83-83fd76a38ab7@linux.dev \
    --to=ridong.chen@linux.dev \
    --cc=cgroups@vger.kernel.org \
    --cc=guopeng.zhang@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    --cc=zhangguopeng@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®