Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp444447lqr; Wed, 5 Jun 2024 10:19:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXs0Fl2yDmNbPYtSg5ZHBM4P6TPKkvOPXw+EsNM6b6vcan86cntYCbh1ch/AepJKrp+PaBqnPrtYMzQl6yBc7f1mj11StSi19YX26ACNg== X-Google-Smtp-Source: AGHT+IEpGB4O9tl+D/50kRM66f95Ma1HnGfN7wIhis5spCLTBQU04oW23n3A0ieHRH4lCVuKpCc6 X-Received: by 2002:a05:620a:2592:b0:794:de31:fe5a with SMTP id af79cd13be357-79523fbeae7mr408963085a.52.1717607984612; Wed, 05 Jun 2024 10:19:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717607984; cv=pass; d=google.com; s=arc-20160816; b=ycR6eEo8pz6bBT/aPOT8JBNz72tEXdTAu+VKD/9oAHFtghfxxp9KRrNcwyjsm/Ij8V E45Rd2rjT7N4aNjiIH2Z1m3DGB4VuKTK2+uA/lE2UCeHNMEErS/L7IqmnI35IP9Xg84h V4v9McwH5N+qR5jVtQa8BgKOl7Qhy52quyvE5oFqPE9MLVAyMHZlF8L39M2DE3s3dR9r pFKVwHYdIdqpMB6stZXmsAzxC2u9/1W5vLcXeJn0Ng+JGtoAk9c5pp8lJrAO8l9NvUlh WZqEI2Xgapkm4ZFKsjCHv7HIpp8eqxUMvRof5AhLDTpWYmDj5fsqyFwa9y6KFDFu+rtY 87eQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YoV1XwOZ7Cwl9H/g9F44sqIaQzIwrjfnCXC0mFAkhaw=; fh=KSJuIig2shS53UyQAMrLEuRV6ACKt4VTwz4oQuxz/QE=; b=t1ZUi4PIK8WeOyjE4YHh6RdHlxlDsLDY9LDFw2FoRI8hqnpI0NocpBhLPt/hyh9XjI bLgGShHnz+XNKbp52fQICHMnwJmAo7n7wKPFhmY96VQBqDSX0DkqbivaECs4Bn+pcQYd zh/54V4cfGSNm7kvFasA1GWiadyDCzBNRkUOjbG+Tfk//kiHeQQ24IITAq8CqKWjZHt3 WQZ1N7xuAblQ016y+amPtt9KVv9B1GLIo121FhlfevfRj8D7t3mcH/LLqmZBexTyeKt2 7+Xu9Tgmb/QX3cAPMU9ZbeAZV3yrGP/CIi9xuc+d/eHoN/URcLmEOYYwU04A/fk7BaJ1 VGAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ft0+F9aj; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-202966-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202966-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff257f080si58311421cf.510.2024.06.05.10.19.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 10:19:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202966-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ft0+F9aj; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-202966-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202966-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4760D1C22E80 for ; Wed, 5 Jun 2024 17:19:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41B9213A864; Wed, 5 Jun 2024 17:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ft0+F9aj" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 9036F139D1B for ; Wed, 5 Jun 2024 17:19:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717607961; cv=none; b=bY15YeoW7dFduGn59JLgX4etsWBJQh32Jbo8mrIATcpLtwkE+NzE7NwKx+nDgvvorw42u2KUEI/ApBG+j9krNIaOPm4I2KtP368eMS7yCmTrgRv5NyHmK4bGNy6CpDs5OaBvzKh7e+KtMrNQNEY1+uGxlDFFgK80jU7RVTxVAf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717607961; c=relaxed/simple; bh=BKxZRYhWTUP+ZwtfxFFfpIbGweia8FSOZExsleG1QNc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dMoMVdCLStNPZaTQW37tb5OGYcrBqSXb3//hbFETK3W3mnknIXJ0WLsJhm/sPhG8jC4T05F9uPIFum8rVa98SPvuFcAI2re384gGMvZ0afQLUbg+Fs4ghDt9h5TGjyjqNTLfSDHg/R8mPCaj6LaBrfaqkvvzIMNSuIsflI8P8Rk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ft0+F9aj; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717607958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YoV1XwOZ7Cwl9H/g9F44sqIaQzIwrjfnCXC0mFAkhaw=; b=Ft0+F9aj7TFApzggX/zTPFUL8EJCVGeOPjhvB3UmdsxTRGasldSp4ENkIxhvN6OpAp0fve +2+O50/Ho0MaKqxlaLwT4gd5Dh5O/Cj1iH/+StfjecatzwORR5v+/xbgeU+8j/xTuDsGf1 gmjCq5jeNxXevfMbPcsPi3j22w3NFug= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-1f_DfBYAM2CqQNOyI9fQYw-1; Wed, 05 Jun 2024 13:19:14 -0400 X-MC-Unique: 1f_DfBYAM2CqQNOyI9fQYw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4F6681954B07; Wed, 5 Jun 2024 17:19:12 +0000 (UTC) Received: from llong.com (unknown [10.22.33.216]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 951B5195606C; Wed, 5 Jun 2024 17:19:10 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Xavier , Waiman Long Subject: [PATCH-cgroup 1/2] cgroup/cpuset: Fix remote root partition creation problem Date: Wed, 5 Jun 2024 13:18:57 -0400 Message-Id: <20240605171858.1323464-2-longman@redhat.com> In-Reply-To: <20240605171858.1323464-1-longman@redhat.com> References: <20240605171858.1323464-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Since commit 181c8e091aae ("cgroup/cpuset: Introduce remote partition"), a remote partition can be created underneath a non-partition root cpuset as long as its exclusive_cpus are set to distribute exclusive CPUs down to its children. The generate_sched_domains() function, however, doesn't take into account this new behavior and hence will fail to create the sched domain needed for a remote root (non-isolated) partition. There are two issues related to remote partition support. First of all, generate_sched_domains() has a fast path that is activated if root_load_balance is true and top_cpuset.nr_subparts is non-zero. The later condition isn't quite correct for remote partitions as nr_subparts just shows the number of local child partitions underneath it. There can be no local child partition under top_cpuset even if there are remote partitions further down the hierarchy. Fix that by checking for subpartitions_cpus which contains exclusive CPUs allocated to both local and remote partitions. Secondly, the valid partition check for subtree skipping in the csa[] generation loop isn't enough as remote partition does not need to have a partition root parent. Fix this problem by breaking csa[] array generation loop of generate_sched_domains() into v1 and v2 specific parts and checking a cpuset's exclusive_cpus before skipping its subtree in the v2 case. Also simplify generate_sched_domains() for cgroup v2 as only non-isolating partition roots should be included in building the cpuset array and none of the v1 scheduling attributes other than a different way to create an isolated partition are supported. Fixes: 181c8e091aae ("cgroup/cpuset: Introduce remote partition") Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 55 ++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index f9b97f65e204..fb71d710a603 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -169,7 +169,7 @@ struct cpuset { /* for custom sched domain */ int relax_domain_level; - /* number of valid sub-partitions */ + /* number of valid local child partitions */ int nr_subparts; /* partition root state */ @@ -957,13 +957,14 @@ static int generate_sched_domains(cpumask_var_t **domains, int nslot; /* next empty doms[] struct cpumask slot */ struct cgroup_subsys_state *pos_css; bool root_load_balance = is_sched_load_balance(&top_cpuset); + bool cgrpv2 = cgroup_subsys_on_dfl(cpuset_cgrp_subsys); doms = NULL; dattr = NULL; csa = NULL; /* Special case for the 99% of systems with one, full, sched domain */ - if (root_load_balance && !top_cpuset.nr_subparts) { + if (root_load_balance && cpumask_empty(subpartitions_cpus)) { single_root_domain: ndoms = 1; doms = alloc_sched_domains(ndoms); @@ -992,16 +993,18 @@ static int generate_sched_domains(cpumask_var_t **domains, cpuset_for_each_descendant_pre(cp, pos_css, &top_cpuset) { if (cp == &top_cpuset) continue; + + if (cgrpv2) + goto v2; + /* + * v1: * Continue traversing beyond @cp iff @cp has some CPUs and * isn't load balancing. The former is obvious. The * latter: All child cpusets contain a subset of the * parent's cpus, so just skip them, and then we call * update_domain_attr_tree() to calc relax_domain_level of * the corresponding sched domain. - * - * If root is load-balancing, we can skip @cp if it - * is a subset of the root's effective_cpus. */ if (!cpumask_empty(cp->cpus_allowed) && !(is_sched_load_balance(cp) && @@ -1009,16 +1012,28 @@ static int generate_sched_domains(cpumask_var_t **domains, housekeeping_cpumask(HK_TYPE_DOMAIN)))) continue; - if (root_load_balance && - cpumask_subset(cp->cpus_allowed, top_cpuset.effective_cpus)) - continue; - if (is_sched_load_balance(cp) && !cpumask_empty(cp->effective_cpus)) csa[csn++] = cp; - /* skip @cp's subtree if not a partition root */ - if (!is_partition_valid(cp)) + /* skip @cp's subtree */ + pos_css = css_rightmost_descendant(pos_css); + continue; + +v2: + /* + * Only valid partition roots that are not isolated and with + * non-empty effective_cpus will be saved into csn[]. + */ + if ((cp->partition_root_state == PRS_ROOT) && + !cpumask_empty(cp->effective_cpus)) + csa[csn++] = cp; + + /* + * Skip @cp's subtree if not a partition root and has no + * exclusive CPUs to be granted to child cpusets. + */ + if (!is_partition_valid(cp) && cpumask_empty(cp->exclusive_cpus)) pos_css = css_rightmost_descendant(pos_css); } rcu_read_unlock(); @@ -1072,6 +1087,20 @@ static int generate_sched_domains(cpumask_var_t **domains, dattr = kmalloc_array(ndoms, sizeof(struct sched_domain_attr), GFP_KERNEL); + /* + * Cgroup v2 doesn't support domain attributes, just set all of them + * to SD_ATTR_INIT. Also non-isolating partition root CPUs are a + * subset of HK_TYPE_DOMAIN housekeeping CPUs. + */ + if (cgrpv2) { + for (i = 0; i < ndoms; i++) { + cpumask_copy(doms[i], csa[i]->effective_cpus); + if (dattr) + dattr[i] = SD_ATTR_INIT; + } + goto done; + } + for (nslot = 0, i = 0; i < csn; i++) { struct cpuset *a = csa[i]; struct cpumask *dp; @@ -1231,7 +1260,7 @@ static void rebuild_sched_domains_locked(void) * root should be only a subset of the active CPUs. Since a CPU in any * partition root could be offlined, all must be checked. */ - if (top_cpuset.nr_subparts) { + if (!cpumask_empty(subpartitions_cpus)) { rcu_read_lock(); cpuset_for_each_descendant_pre(cs, pos_css, &top_cpuset) { if (!is_partition_valid(cs)) { @@ -4575,7 +4604,7 @@ static void cpuset_handle_hotplug(void) * In the rare case that hotplug removes all the cpus in * subpartitions_cpus, we assumed that cpus are updated. */ - if (!cpus_updated && top_cpuset.nr_subparts) + if (!cpus_updated && !cpumask_empty(subpartitions_cpus)) cpus_updated = true; /* For v1, synchronize cpus_allowed to cpu_active_mask */ -- 2.39.3