From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 125E71CD1E4 for ; Tue, 23 Jun 2026 01:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782177321; cv=none; b=br6MCu0WlhPjq6zFwTAj/DJLrgChf+giz3Ky7TTn9Wo6fPOgnas2ttkx/YJIBU1EQTdKY8Nypso/QN1u1iVy85ro++6ewnMam2FlhVLpi4O1fs1wShdjPQOcptOkIXE1eNL8PkAfWObG7DUxBKdEYBLcjT0Cos9fYvpdIghSeQo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782177321; c=relaxed/simple; bh=CXlJ+IGAMu+WnGGoTqqoxMmqr9c6F6sSbek2igt/B6w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=M822WE3+jvyuhY8IgEKXegg8kz5hbFUANDR07hS29Q7Hr8vrWtjBaQ2QPgbNPhCMk5x5K3yNaNjRXqvqaym80CVtuSf2JuA2rR36xa0rIhHMb0x2uhPIsCjfj5fovEfKDtlKS/XzD3iHpZM9u6OrE7CsE+Z0HFqN/jeyS7MOY+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gdC9aSjh; arc=none smtp.client-ip=95.215.58.186 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) header.d=linux.dev header.i=@linux.dev header.b="gdC9aSjh" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782177308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Xehzt1SVC9gtzjAb+OIQuJbK4C/O+ft3+abYnowKwg=; b=gdC9aSjhT98sWW65C9TYwDKrS0CCCEH4A1fyMutR88fuJ3iKvSjy6g9sUSAoNd+ZicS16i x85iujJC26C2a0jvFML5EHj4RfTN09hfMvmCsOaAuI0x/tUde2BB+2pH1QElf02gPcGMvn hdpDh8ZWpgpJzvEv3cFUtPh1lt/Vlck= Date: Tue, 23 Jun 2026 09:14:59 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/2] cgroup/cpuset: Avoid unnecessary cpus & mems update in cpuset_hotplug_update_tasks() To: Waiman Long , Tejun Heo , Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Jonathan Corbet , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org References: <20260622224509.1927419-1-longman@redhat.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Ridong Chen In-Reply-To: <20260622224509.1927419-1-longman@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 6/23/2026 6:45 AM, Waiman Long wrote: > As reported by sashiko [1], cpuset_hotplug_update_tasks() may perform > unnecessary task iteration and updating of tasks' CPU and node masks > when mems_allowed and/or cpus_allowed are not set in cpuset v2. It is > due to the fact that the temporary new_cpus and new_mems masks do not > inherit parent's effective_cpus/mems when they are empty which is the > expected behavior for cpuset v2 since commit 4ec22e9c5a90 ("cpuset: > Enable cpuset controller in default hierarchy"). > > Fix that and avoid unnecessay work by adding the empty mask checks and > inheriting the parent's versions if empty. > > [1] https://sashiko.dev/#/patchset/20260621032816.1806773-1-longman%40redhat.com > > Fixes: 4ec22e9c5a90 ("cpuset: Enable cpuset controller in default hierarchy") > Signed-off-by: Waiman Long > --- > kernel/cgroup/cpuset.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index aff86acea701..bc0207fd6e57 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c > @@ -3925,6 +3925,14 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs, struct tmpmasks *tmp) > compute_effective_cpumask(&new_cpus, cs, parent); > nodes_and(new_mems, cs->mems_allowed, parent->effective_mems); > > + if (is_in_v2_mode()) { > + /* Inherit parent's effective_cpus/mems if empty */ > + if (cpumask_empty(&new_cpus)) > + cpumask_copy(&new_cpus, parent->effective_cpus); > + if (nodes_empty(new_mems)) > + new_mems = parent->effective_mems; > + } > + > if (!tmp || !cs->partition_root_state) > goto update_tasks; > I noticed that compute_effective_cpumask(...) is called in several places, so I think the logic should be consolidated into that function. ``` static void compute_effective_cpumask(struct cpumask *new_cpus, struct cpuset *cs, struct cpuset *parent) { cpumask_and(new_cpus, cs->cpus_allowed, parent->effective_cpus); if (cpumask_empty(&new_cpus) && is_in_v2_mode()) cpumask_copy(&new_cpus, parent->effective_cpus); } ``` Similarly, for new_mems, should we introduce a dedicated helper like compute_effective_nodemask? The same fallback logic is needed in update_nodemasks_hier: ``` static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems) { ... bool has_mems = nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems); /* * If it becomes empty, inherit the effective mask of the * parent, which is guaranteed to have some MEMs. */ if (is_in_v2_mode() && !has_mems) *new_mems = parent->effective_mems; ... ``` -- Best regards Ridong