From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920297; b=is9S8qaUy1uFZbXld9LEtd8gIvXUWpsch2v0wpvvDJejfKayx5KyCCLVbO0QCaQ66on2 uGDAV4IG1Zo1ghJ55MrceULlFdpyLKNKghGQpbDPxUXc7+CwXgYvOY/syLkPQGkrtjYoO zLrZOF2ThGUgr3naAEpRAVv48NSK3NHPsWqQvrPwoTXe/+PLAYHAy3pMpfwW+sKDzQ/Ex y7scZQCa/KlSAV2lO3MY+5kM+TMShGToRzGcVZJ009+LWu8SqeJL5suEZVARTHZtk5Wxe QxxydIrg6EXBJHIvQzPW/DwnRNPlquqr/VQcOSbzq773ZBsAYSTZ96hjk8F5ZSgfX1Q== 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=EnHpUny4AYLaUSLnEwdbX8DQw1HKBqNvpclwAqHQXd1j050XU2RCeidZCxwdgLkFTXGJ ecEE/jHQrEXtBXeCaqbXqXXEL6Ni2BRSgjemWLP3JUFCRsLRS631F2EoeqlXuR+9CWSS8 KytLyC3E0RjDw/t9+naQUgNMbX52yBVaPe2+gsdFp4jS/gKyh2L41NHkGvLrpCO8HsmWR 3FktF8zImkYxXMcpJYurdBKmuyYy35WbtMbaDH7ox53LpFI0DK2ePLThC2Q8y/egrLyG5 CPNCh6xDltBbBBcoyNb1LzUt0JuaCuu2uFEkSNtenxip1wYsHzUZ3zRKfVLXqQFKUlQ== 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.195 Received: from mta1.migadu.com (out-195.mta1.migadu.com [95.215.58.195]) (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 F2BBB606A32A for ; Sun, 29 Nov 2026 02:44:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2BBB606A32A 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: cgroups@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: cgroups@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: cgroups@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