From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.194 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920297; b=r1DCDkFQqzhjc8i6O/ehiRDkXfi159R6ntUZC9NgON2HM9Kv9wgMrjnaOzQYHXPUflyX yYMoy2nykiIGg/LXyoood8zxvAOc4A9LdLK26jzQIy/TJ178qMG3lc65el2SfI9tp2SJ7 jzHsOwCrQRXZyCR4widR5KQu6h4B9ttrGZN38gNsFc3yoOiX0uGlTN7B29D+cWpUXrzDB PhPZyPkzvdjsFGeNyrqY6KL2SjFXpSYVQnDFOsOytyu1EbIjZJTbT1wMwVkH1xk+afxf8 DwpLCzaaR8irTv/T/rXrbeEZdoiqLSK36+Cx9t6mw+5a4kHWba/ozMqY0tp5/ch8Low== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920297; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-Id: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=QqzDR8g/3uXIwTt5gBNb3evfxFhPVX07y8hCtDlg16Y=; b=r+AOCNgu3RlxQjSsQzjcqV/BgRcbZ9vppR99sy2JaQpnwqSJmq6xDOBx/7dEuA6ps+hx difKf4TByvBXeHBTGLh1z08kxzbRhqB5MbtqJOQLflbv1P9gof2ZMRe1Lv6/Dqtlf5DuJ rgAghmmV+4Ivq7yzoDHQuw1qvVij92zIO6jndK000G14zd/9Tu9/vuYRtBfjpZO9ZRDyJ 1PZ5GZsEwoOH0NNfbc39Ngk23+SemM+17nFiBBPYjFROWJawhPVvaFlwj5oMVS1UiIEuz F7bNxmGZV5I7DR8xlkKMqa2KLnH79i2GgCefwBhEFMvOGX5c6OBHAHFXvByE24YZJag== 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=OCQ3UzsW; arc=none smtp.remote-ip=95.215.58.194 Received: from mta1.migadu.com (out-194.mta1.migadu.com [95.215.58.194]) (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 8C3A9606A683 for ; Sun, 29 Nov 2026 02:44:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C3A9606A683 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=OCQ3UzsW X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=14Mx8dj0qVqgGzcxVG/ygtzMiHD1DrlDOR39TgISYqA=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795920294; v=1; x=1796525094; b=OCQ3UzsWXpz/XmWw2vsamn4X4rxFtOeEQ5BM6SiO7auACKM0aJHp8S3+luYbQ+9XA0ShvddX 49LXyHu0nmJeE6Oz42nCcfR018Do2wRCmkE4KQPHdOTHz8VThBNngO8AcCAAPTRdkfysSFqIyWY XSPpjcCfDTLxS42Bo9X3/uSk= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id af70f73a87440ba5; Sun, 29 Nov 2026 02:44:54 +0000 X-Mizu-Trace-ID: af70f73a87440ba5 X-Migadu-Flow: FLOW_OUT From: Ridong Chen To: Waiman Long , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= Cc: Ridong Chen , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Ridong Chen Subject: [PATCH v6 03/12] cpuset: introduce partition_update() Date: Sun, 29 Nov 2026 10:44:22 +0800 Message-Id: <20261129024431.2485721-4-ridong.chen@linux.dev> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261129024431.2485721-1-ridong.chen@linux.dev> References: <20261129024431.2485721-1-ridong.chen@linux.dev> 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 Content-Transfer-Encoding: 8bit From: Ridong Chen Introduce partition_update() to centralize updates to key cpuset structures during a partition update, including: 1. effective_xcpus 2. exclusive_cpus Key operations performed: 1. Adding and removing exclusive CPUs via partition_xcpus_add()/del() 2. Synchronizing the effective exclusive CPUs mask 3. Updating the exclusive CPUs mask when modification is required 4. Triggering scheduler domain rebuilds For a local partition, the CPUs to be added or deleted are restricted to those in the parent's effective_xcpus, as the parent may have shrunk. The function returns early if nothing is to be changed. The partition root state is unchanged by this function, so no partition change notification is sent. Signed-off-by: Ridong Chen --- kernel/cgroup/cpuset.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index cfad92cf89d6..7efec768f212 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1825,6 +1825,59 @@ static void __maybe_unused partition_disable(struct cpuset *cs, int new_prs, update_sibling_cpumasks(parent, cs, tmp); } +/** + * partition_update - Update an existing partition configuration + * @cs: The cpuset to update + * @prs: Partition root state (must be positive) + * @xcpus: New exclusive CPUs mask for the partition (NULL to keep current) + * @excpus: New effective exclusive CPUs mask + * @tmp: Temporary masks + * + * Updates partition-related fields. The CPUs in tmp->addmask are taken + * from the effective_cpus of the parent, or of top_cpuset for a remote + * partition, and the CPUs in tmp->delmask are given back to it. If that + * parent is top_cpuset, subpartitions_cpus is updated accordingly. + */ +static void __maybe_unused partition_update(struct cpuset *cs, int prs, struct cpumask *xcpus, + struct cpumask *excpus, struct tmpmasks *tmp) +{ + struct cpuset *parent; + + lockdep_assert_cpuset_lock_held(); + WARN_ON_ONCE(!cpuset_v2()); + WARN_ON_ONCE(prs <= 0); + + parent = is_remote_partition(cs) ? NULL : parent_cs(cs); + + /* + * Only CPUs owned by the parent can be taken from or given back to + * it, the parent may have shrunk. A remote partition gets its CPUs + * from top_cpuset which owns all the CPUs. + */ + if (parent) { + cpumask_and(tmp->addmask, tmp->addmask, parent->effective_xcpus); + cpumask_and(tmp->delmask, tmp->delmask, parent->effective_xcpus); + } + if (cpumask_empty(tmp->addmask) && + cpumask_empty(tmp->delmask) && + cpumask_equal(cs->effective_xcpus, excpus)) + return; + + spin_lock_irq(&callback_lock); + partition_xcpus_add(prs, parent, tmp->addmask); + partition_xcpus_del(prs, parent, tmp->delmask); + /* + * Need to update effective_xcpus and exclusive_cpus now as + * update_sibling_cpumasks() called by the callers afterwards may + * iterate back to the same cs. + */ + cpumask_copy(cs->effective_xcpus, excpus); + if (xcpus) + cpumask_copy(cs->exclusive_cpus, xcpus); + spin_unlock_irq(&callback_lock); + cpuset_force_rebuild(); +} + /* * remote_partition_enable - Enable current cpuset as a remote partition root * @cs: the cpuset to update -- 2.34.1