From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796470027; b=wSxll54sMYWXU7iz3azsuisim+AWRsqR8XPqfXqYlSikUdEuZuY74ord6H4xAPq6rJIW A8sNt18chce9/5qdYMLmZU+rzMFSdmkhn3th3eqlGKMqb0PHk9sXo8/cGPGhgN2M7VofK tjYg+rTxVruFk0QrZbqyLnHgkCMNqPjYgmxz//MrPz3+w8J3ayG/T8ACh0nyM35Tu2lfX jruK7pLu/9mh52nDtPSpBETiyk1rx5r80HQGkGfnBIGqcZFeRTSHERzfSPQRMkt26Q4zd DQfVIGFQGX5arZALQABz5qW5bkhJVqrRxjTNYSydquKPO9a/OFwLwjUsPapf4CSmKIw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796470027; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=YwLNs+DydussKPLy6omZ997f0HtAynMlLw5+JxYwbCo=; b=aqFzf6Q7h81OmChuIJgL6rvkKKQ+tOCnerloZXRUDsTIAWkh+oXOFJBZHhZIoXedQwBR dfKg2bcGQoN5I1YPXOz0kU44V8yqUATBABgqbLyaLm6P8sg8lkLHIof2PlWrMnb4texLY 5bdZmXZ2ghTlXYlR4btWO+2msf/vFllK7tmswjfQKafS+IeKe3isdDjQh6TMZiqZNLWk1 IGWdeQGmFN/prfq4hKdN1nuUvZuZs7qfVikvT+pfZMHXnpIt1yxjR154MFYkx8C1tmFL3 q9Z6cAxFfpvDzdMR1NNXSxReowY6EiytZU0WgWLVMBot7GbNsgwLpGqtdw7uac/h+0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=io5Jz7Fb; arc=none smtp.remote-ip=91.218.175.65 Received: from mta0.migadu.com (out-65.mta0.migadu.com [91.218.175.65]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C697606A32F for ; Sat, 5 Dec 2026 11:27:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4C697606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=io5Jz7Fb X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=CDVL/tnGg3yefOBuurtTOon8jQ2Mw5QB1+d1F4kVmBM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796470024; v=1; x=1797074824; b=io5Jz7FbutucNEMz7o+cJTTUmE3g4i64KcntF/eBXhKR8FNKftj5B2H14Dtf72e0Fa+3Vbjm FjaG8qlqW2NTlahoybH0agOqSIA3CA/MZHhzSKKL9iWiMrCvus8I1xSWW2XwyR6L7eSrOISJVdo z75aUvKTJ5ssFj6P/l2noMo4= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id eb4cbe3b8dceb1fd; Sat, 05 Dec 2026 11:27:04 +0000 X-Mizu-Trace-ID: eb4cbe3b8dceb1fd X-Migadu-Flow: FLOW_OUT Message-ID: Date: Sat, 5 Dec 2026 19:26:57 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 11/12] cpuset: introduce local_partition_update() To: Ridong Chen , Waiman Long , Tejun Heo , Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Ridong Chen References: <20261129024431.2485721-1-ridong.chen@linux.dev> <20261129024431.2485721-12-ridong.chen@linux.dev> Content-Language: en-US From: Guopeng Zhang In-Reply-To: <20261129024431.2485721-12-ridong.chen@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 2026/11/29 10:44, Ridong Chen 写道: > From: Ridong Chen > > Factor the partcmd_update handling without a new cpumask out of > update_parent_effective_cpumask() into local_partition_update(), and > the one with a new cpumask, used by partition_cpus_change(), into > __local_partition_update(). > > __local_partition_update() validates the new effective exclusive CPUs > with validate_local_partition(), then: > > - if the validation fails, a valid partition is invalidated with > partition_disable() and its load balance flag is updated, while an > invalid partition only has its error code updated. The error code > is kept if the parent is not a valid partition root, e.g. for a > remote partition invalidated by hotplug, as the cpuset can't become > a valid local partition anyway. > - if the validation passes, an invalid partition becomes valid again > with partition_enable(), and a valid partition has its CPUs updated > with partition_update(). > > An invalid partition owns no CPU, so tmp->delmask is cleared for it. > Otherwise the housekeeping check would count its CPUs as released and > skip the check for the remaining housekeeping CPUs, as the old > partcmd_update path did not pass a delmask for an invalid partition > either. > > local_partition_update() computes the new effective exclusive CPUs > with compute_excpus() as before. As in the old partcmd_update path, the > sibling exclusivity check is only done for an invalid partition with an > empty cpuset.cpus.exclusive, as a valid partition has passed it > already. > > cpuset_hotplug_update_tasks() now calls local_partition_update() for > both the invalidation and the revival of a local partition, instead of > open coding the invalidation conditions. The only exception is when > subpartitions_cpus becomes empty because no CPU is left for > top_cpuset, in which case the local partition is disabled directly > with PERR_HOTPLUG. As before, an invalid partition is only revived if > it has an active CPU in its exclusive CPUs, so it doesn't take CPUs > back right after top_cpuset runs out of non-partition CPUs. A remote > partition only needs the hotplug invalidation check, so jump to > update_tasks right after it. As partition_disable() gives the CPUs > back to the parent and updates effective_cpus of the cpuset directly, > effective_cpus is saved before any partition state change and the new > effective cpumask is compared against it. Otherwise the tasks of a > partition invalidated by hotplug may be left with only the offlined > CPUs. > > In update_cpumasks_hier(), the effective cpumask is always recomputed > after local_partition_update(), as tmp->new_cpus may be reused by it. > effective_cpus of the child is only updated after that, so an > unvalidated cpumask is never exposed to its readers. > > Signed-off-by: Ridong Chen Hi Ridong, This seems to be the most complex patch in the series. I went through Sashiko's review carefully because I noticed that some of my previous review comments on other patches overlapped with Sashiko's findings. To avoid repeating the same feedback, I'm only raising the following points that I didn't see covered in Sashiko's review. > --- > kernel/cgroup/cpuset.c | 205 ++++++++++++++++++++++++++++++----------- > 1 file changed, 149 insertions(+), 56 deletions(-) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index a32bf85e48ad..26061bb44798 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -2090,6 +2090,109 @@ static int local_partition_enable(struct cpuset *cs, > return 0; > } > > +/** > + * __local_partition_update - Update local partition configuration > + * @cs: Target cpuset to update > + * @xcpus: New exclusive CPU mask > + * @excpus: New effective exclusive CPU mask > + * @tmp: Temporary mask storage for intermediate calculations > + * @excl_check: Flag to enable exclusivity validation > + * > + * Handles updates to local CPU partition configurations by validating > + * changes, managing state transitions, and propagating updates through > + * the cpuset hierarchy. > + * > + * Note on exclusivity checking: Exclusivity validation is required when > + * transitioning from an invalid to valid partition state. However, when > + * updating cpus_allowed or exclusive_cpus, exclusivity should have already > + * been verified by validate_change(). In such cases, excl_check must be > + * false since the cs cpumasks are not yet updated. > + * > + * Return: Partition error code (PERR_NONE indicates success) > + */ > +static int __local_partition_update(struct cpuset *cs, struct cpumask *xcpus, > + struct cpumask *excpus, struct tmpmasks *tmp, > + bool excl_check) > +{ > + struct cpuset *parent = parent_cs(cs); > + int part_error = PERR_NONE; /* Partition error? */ > + int old_prs, new_prs; > + > + lockdep_assert_cpuset_lock_held(); > + /* For local partition only */ > + if (WARN_ON_ONCE(is_remote_partition(cs) || cs_is_member(cs))) > + return PERR_NONE; > + > + old_prs = cs->partition_root_state; > + /* > + * If new_prs < 0, it might transition to valid partition state. Should the comment refer to old_prs instead of new_prs? > + * Use absolute value for validation checks. > + */ > + new_prs = old_prs < 0 ? -old_prs : old_prs; > + cpumask_andnot(tmp->addmask, excpus, cs->effective_xcpus); > + /* > + * An invalid partition doesn't own any CPU, so it gives nothing back > + * and the housekeeping check must not count any CPU as released. > + */ > + if (is_partition_valid(cs)) > + cpumask_andnot(tmp->delmask, cs->effective_xcpus, excpus); > + else > + cpumask_clear(tmp->delmask); > + part_error = validate_local_partition(cs, new_prs, excpus, > + excl_check, tmp); I noticed that the partition invalidation reason changes in the following case. I think the original PERR_NOCPUS describes this situation more accurately. I tested this on both the baseline kernel and the complete v6 series on a 32-vCPU x86-64 VM, with CPUs 0-31 online and no isolcpus or nohz_full boot parameters. cd /sys/fs/cgroup echo +cpuset > cgroup.subtree_control mkdir A echo 0-7 > A/cpuset.cpus echo 0-7 > A/cpuset.cpus.exclusive echo +cpuset > A/cgroup.subtree_control echo root > A/cpuset.cpus.partition mkdir A/B echo 4-7 > A/B/cpuset.cpus echo 4-7 > A/B/cpuset.cpus.exclusive echo root > A/B/cpuset.cpus.partition echo 0-3 > A/cpuset.cpus.exclusive cat A/B/cpuset.cpus.partition Before the patch: root invalid (Parent unable to distribute cpu downstream) With v6: root invalid (Invalid cpu list in cpuset.cpus.exclusive) The child's configured masks remain unchanged and nonempty,its parent simply no longer grants it any of those CPUs. Since the partition becomes invalid because the parent has withdrawn its CPU allocation,I think PERR_NOCPUS is more descriptive here. Do you think this path should retain the original reason? Thanks, Guopeng > + if (part_error) { > + /* > + * An invalid partition only needs to update its error code. > + * Keep the error code if the parent is not a valid partition > + * root, e.g. for an invalidated remote partition, as the > + * cpuset can't become a valid local partition anyway. > + */ > + if (is_partition_valid(cs)) { > + partition_disable(cs, -new_prs, part_error, tmp); > + update_partition_sd_lb(cs, old_prs); > + } else if (is_partition_valid(parent)) { > + WRITE_ONCE(cs->prs_err, part_error); > + } > + return part_error; > + } > + > + /* Nothing changes, return PERR_NONE */ > + if (new_prs == old_prs && > + (cpumask_empty(tmp->addmask) && cpumask_empty(tmp->delmask))) > + return PERR_NONE; > + > + /* > + * If partition was previously invalid but now passes checks, > + * re-enable it and update related flags. > + * Otherwise, partition state doesn't change, only cpumasks change. > + */ > + if (is_partition_invalid(cs)) { > + partition_enable(cs, parent, new_prs, excpus); > + update_partition_sd_lb(cs, old_prs); > + } else { > + partition_update(cs, new_prs, xcpus, excpus, tmp); > + } > + > + cpuset_update_tasks_cpumask(parent, tmp->addmask); > + update_sibling_cpumasks(parent, cs, tmp); > + return PERR_NONE; > +} > + > +static int local_partition_update(struct cpuset *cs, struct tmpmasks *tmp) > +{ > + /* > + * A valid partition has passed the exclusivity check already. An > + * invalid partition has to pass it before becoming valid again when > + * cpuset.cpus.exclusive is empty. > + */ > + bool excl_check = is_partition_invalid(cs) && > + cpumask_empty(cs->exclusive_cpus); > + > + compute_excpus(cs, tmp->new_cpus); > + return __local_partition_update(cs, NULL, tmp->new_cpus, tmp, > + excl_check); > +} > + > /** > * update_parent_effective_cpumask - update effective_cpus mask of parent cpuset > * @cs: The cpuset that requests change in partition root state > @@ -2127,9 +2230,9 @@ static int local_partition_enable(struct cpuset *cs, > * check for error and so partition_root_state and prs_err will be updated > * directly. > */ > -static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > - struct cpumask *newmask, > - struct tmpmasks *tmp) > +static int __maybe_unused update_parent_effective_cpumask(struct cpuset *cs, int cmd, > + struct cpumask *newmask, > + struct tmpmasks *tmp) > { > struct cpuset *parent = parent_cs(cs); > int adding; /* Adding cpus to parent's effective_cpus */ > @@ -2149,23 +2252,6 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, > adding = deleting = false; > old_prs = new_prs = cs->partition_root_state; > > - if (cmd == partcmd_invalidate) { > - if (is_partition_invalid(cs)) > - return 0; > - > - /* > - * Make the current partition invalid. > - */ > - if (is_partition_valid(parent)) > - adding = cpumask_and(tmp->addmask, > - cs->effective_xcpus, > - parent->effective_xcpus); > - if (old_prs > 0) > - new_prs = -old_prs; > - > - goto write_error; > - } > - > /* > * The parent must be a partition root. > * The new cpumask, if present, or the current cpus_allowed must > @@ -2525,12 +2611,12 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp, > rcu_read_unlock(); > > if (update_parent) { > - update_parent_effective_cpumask(cp, partcmd_update, NULL, tmp); > + local_partition_update(cp, tmp); > /* > * Capture current partition_root_state as it may have > * changed. Always recompute effective cpumask as tmp->new_cpus > * may be clobbered when update_sibling_cpumasks() is called > - * within update_parent_effective_cpumask(). > + * within local_partition_update(). > */ > new_prs = cp->partition_root_state; > compute_effective_cpumask(tmp->new_cpus, cp, parent); > @@ -2689,8 +2775,8 @@ static void partition_cpus_change(struct cpuset *cs, struct cpuset *trialcs, > trialcs->effective_xcpus, tmp); > } else { > if (!trialcs->prs_err) > - update_parent_effective_cpumask(cs, partcmd_update, > - trialcs->effective_xcpus, tmp); > + __local_partition_update(cs, trialcs->exclusive_cpus, > + trialcs->effective_xcpus, tmp, false); > else if (is_partition_valid(cs)) > partition_disable(cs, -cs->partition_root_state, > trialcs->prs_err, tmp); > @@ -4144,60 +4230,67 @@ void cpuset_force_rebuild(void) > */ > static void cpuset_hotplug_update_tasks(struct cpuset *cs, struct tmpmasks *tmp) > { > - static cpumask_t new_cpus; > + static cpumask_t new_cpus, old_cpus; > static nodemask_t new_mems; > bool cpus_updated; > bool mems_updated; > - int partcmd = -1; > struct cpuset *parent; > > wait_attach_done_lock(); > parent = parent_cs(cs); > + /* > + * Partition state changes below may update effective_cpus directly, > + * save it to check if tasks need to be updated. > + */ > + cpumask_copy(&old_cpus, cs->effective_cpus); > compute_effective_cpumask(&new_cpus, cs, parent); > compute_effective_nodemask(&new_mems, cs, parent); > > if (!tmp || !cs->partition_root_state) > goto update_tasks; > > - if (is_remote_partition(cs) && (cpumask_empty(subpartitions_cpus) || > - (cpumask_empty(&new_cpus) && > - partition_is_populated(cs, NULL)))) { > - partition_disable(cs, -cs->partition_root_state, PERR_HOTPLUG, > - tmp); > - compute_effective_cpumask(&new_cpus, cs, parent); > + /* > + * Compute effective_cpus for valid partition root, may invalidate > + * child partition roots if necessary. > + */ > + if (is_remote_partition(cs)) { > + if (cpumask_empty(subpartitions_cpus) || > + (cpumask_empty(&new_cpus) && > + partition_is_populated(cs, NULL))) { > + partition_disable(cs, -cs->partition_root_state, > + PERR_HOTPLUG, tmp); > + compute_effective_cpumask(&new_cpus, cs, parent); > + } > + goto update_tasks; > } > > /* > - * Force the partition to become invalid if either one of > - * the following conditions hold: > - * 1) empty effective cpus but not valid empty partition. > - * 2) parent is invalid or doesn't grant any cpus to child > - * partitions. > - * 3) subpartitions_cpus is empty. > + * The subpartitions_cpus may be cleared if no CPUs remain available for > + * the top_cpuset. In this case, disable the local partition directly. > + * Otherwise, local_partition_update() will handle the automatic > + * transition between valid and invalid partition states. > */ > - if (is_local_partition(cs) && > - (!is_partition_valid(parent) || > - tasks_nocpu_error(parent, cs, &new_cpus) || > - cpumask_empty(subpartitions_cpus))) > - partcmd = partcmd_invalidate; > + if (is_local_partition(cs) && cpumask_empty(subpartitions_cpus)) > + partition_disable(cs, -cs->partition_root_state, PERR_HOTPLUG, > + tmp); > /* > - * On the other hand, an invalid partition root may be transitioned > - * back to a regular one if its effective xcpus has an active CPU. > + * Only try to revive an invalid partition if it has an active CPU, > + * or it may take back CPUs that other partitions need when top_cpuset > + * has just run out of non-partition CPUs. > */ > - else if (is_partition_valid(parent) && is_partition_invalid(cs) && > - cpumask_intersects(cs->effective_xcpus, cpu_active_mask)) > - partcmd = partcmd_update; > + else if (is_partition_valid(cs) || > + cpumask_intersects(user_xcpus(cs), cpu_active_mask)) > + local_partition_update(cs, tmp); > > - if (partcmd >= 0) { > - update_parent_effective_cpumask(cs, partcmd, NULL, tmp); > - if (is_partition_valid(cs) || (partcmd == partcmd_invalidate)) { > - compute_effective_cpumask(&new_cpus, cs, parent); > - cpuset_force_rebuild(); > - } > - } > + /* > + * Recompute effective CPU mask after partition state update: > + * - For valid partitions: calculate partition-specific effective CPUs > + * - For invalid partitions: compute member effective CPU mask > + */ > + compute_effective_cpumask(&new_cpus, cs, parent); > > update_tasks: > - cpus_updated = !cpumask_equal(&new_cpus, cs->effective_cpus); > + cpus_updated = !cpumask_equal(&new_cpus, &old_cpus); > mems_updated = !nodes_equal(new_mems, cs->effective_mems); > if (!cpus_updated && !mems_updated) > goto unlock; /* Hotplug doesn't affect this cpuset */