From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B64C130568B for ; Sun, 21 Jun 2026 03:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782012557; cv=none; b=RGeehfxxWPAmK/rvfNaLjEinwgBrza9d60UrIXWJZadBabfHq0hJiO5IPktbB+romH27D3aKGISwVWFyeNT85beBgF0knNuoaTlVIYlDYOofzNrctp/X0zYGFxZSiJJ0TjDatymmqaVh+0zG5gbB7/c/xKTsybQpLyRFeafnoOw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782012557; c=relaxed/simple; bh=LG3jA1kns3vOL7iDl4c0Y72M/5n2zvpUFl+rM/4aX9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D9z7OCTHmLT9xHaBkYmECR5x00kVL8Yk0gMbLQXpUPLf1J/yZT66F/jgZ51EM24LZfQNEKo59SgO4fRNDlN6IKyMmJOrea0Nl9kfhqav0D5ckSxWzf49GCaGKpbL0kKWqkLhV+IIU8upqVopBq+GLfBqvKsGZVIFNUh5DDFZvRk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=NPkbMUgk; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NPkbMUgk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782012552; 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=1eGmG/4U4ZgvfKwrtncYxEsc8C96XKxQC9pSbAEGcKw=; b=NPkbMUgk0b9K2SijgcqXsQZEDRPKR2TN0n0PDYZhGPsixpFA79P4As5wZjH8dK9oH2awIm zdz6PqH3XXNio9QRe11HYho9DfH19aqMdfdCQObHeKXqgyiymSb1Gk7GWrfraUHuCReUGx p80eT8pWeLWJVD3yNeJOJv4oKabqP5M= 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-441-aLNYCjBHOsqHh0q8KOcpew-1; Sat, 20 Jun 2026 23:29:09 -0400 X-MC-Unique: aLNYCjBHOsqHh0q8KOcpew-1 X-Mimecast-MFC-AGG-ID: aLNYCjBHOsqHh0q8KOcpew_1782012547 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 E8F0F1956060; Sun, 21 Jun 2026 03:29:06 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.88.8]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5F48195604E; Sun, 21 Jun 2026 03:29:04 +0000 (UTC) From: Waiman Long To: Ridong Chen , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Li Zefan , Farhad Alemi , Andrew Morton Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron Tomlin , Guopeng Zhang , Gregory Price , David Hildenbrand , Waiman Long Subject: [PATCH v7 4/9] cgroup/cpuset: Add a cpuset_reserve_dl_bw() helper Date: Sat, 20 Jun 2026 23:28:11 -0400 Message-ID: <20260621032816.1806773-5-longman@redhat.com> In-Reply-To: <20260621032816.1806773-1-longman@redhat.com> References: <20260621032816.1806773-1-longman@redhat.com> Precedence: bulk X-Mailing-List: cgroups@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.17 Extract the DL bandwidth allocation code in cpuset_attach() to a new cpuset_reserve_dl_bw() helper to simplify code. No functional change is expected. Reviewed-by: Ridong Chen Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 47 ++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 65d095dcada1..2ffc66baedf3 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2994,6 +2994,25 @@ static int cpuset_can_attach_check(struct cpuset *cs) return 0; } +static int cpuset_reserve_dl_bw(struct cpuset *cs) +{ + int cpu, ret; + + if (!cs->sum_migrate_dl_bw) + return 0; + + cpu = cpumask_any_and(cpu_active_mask, cs->effective_cpus); + if (unlikely(cpu >= nr_cpu_ids)) + return -EINVAL; + + ret = dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); + if (ret) + return ret; + + cs->dl_bw_cpu = cpu; + return 0; +} + static void reset_migrate_dl_data(struct cpuset *cs) { cs->nr_migrate_dl_tasks = 0; @@ -3008,7 +3027,7 @@ static int cpuset_can_attach(struct cgroup_taskset *tset) struct cpuset *cs, *oldcs; struct task_struct *task; bool setsched_check; - int cpu, ret; + int ret; /* used later by cpuset_attach() */ cpuset_attach_old_cs = task_cs(cgroup_taskset_first(tset, &css)); @@ -3064,28 +3083,16 @@ static int cpuset_can_attach(struct cgroup_taskset *tset) } } - if (!cs->sum_migrate_dl_bw) - goto out_success; - - cpu = cpumask_any_and(cpu_active_mask, cs->effective_cpus); - if (unlikely(cpu >= nr_cpu_ids)) { - ret = -EINVAL; - goto out_unlock; - } - - ret = dl_bw_alloc(cpu, cs->sum_migrate_dl_bw); - if (ret) - goto out_unlock; - - cs->dl_bw_cpu = cpu; - -out_success: - cs->attach_in_progress++; - oldcs->attach_in_progress++; + ret = cpuset_reserve_dl_bw(cs); out_unlock: - if (ret) + if (ret) { reset_migrate_dl_data(cs); + } else { + cs->attach_in_progress++; + oldcs->attach_in_progress++; + } + mutex_unlock(&cpuset_mutex); return ret; } -- 2.54.0