Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp414850pxy; Sat, 14 Aug 2021 10:43:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHgDAGOm+LI20o7f5He8PeT3tj/QSi4d4mCNmBZ2i147v+aUXAG/8ge3bZ7yMAKiT8ZSKO X-Received: by 2002:a17:906:ca47:: with SMTP id jx7mr8494160ejb.286.1628963024671; Sat, 14 Aug 2021 10:43:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628963024; cv=none; d=google.com; s=arc-20160816; b=dKN2ivjOZLUtn67RnfXBcRNNlTJZo5Q6zLKJVH9aj4/aG8JNkiwQ+STw4bCI8CZZFA MxALCmhoKkxpS1LoZZR3msFN4dQXEECbjr2j0EzFsqUUkmYvijiB+Gh0rUomgws9bEq9 2XduUA3nEveQwSVbyqW5+L3sL/VqFn5cjB4Zh8LCbnCwz+UKm0bbTLwjxP+KKXPWUb3e dIy0KKGpb8gXxjBF+9Foso8zkXNvJiTOQYmEcokWyyeOW6aHLOHgrt8R+PTto5asLmhq 20FS0IGm4oL4hZgMnL7C1k5WpnIckz95GaC43WpIdXHjOVcfDqoi7EtkISrc85FEFctB 8xOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=4wV7V3qeD9YcjdJFq5SbCoDMmsCijaAxtKzqeyOb8Uo=; b=KVdWnMbTfdBNcwwWDnHtP68Yts8+jLZ7wndWjSsUDWdkuMppS36tDzCcuAzB8WqyZk 9NxBc1kV1lFV0MAppOLYI+JuU+SjdcgXJ2GziefVlOlN3zBD908gugG3ggY2LOLvTvg4 hIXdMPp1q1GO8KHZ+gnxlqamld9QzS+z5NErzdNsMa0cnOW9qcpyFXAyJ7BJQyXfbv3c GLrzdNLHJOH4vr450wkrTxZ84jlcU4mVhGjUORDmzJAC30yA6p2FtvHWBHdKYXr1/ahK F77gNntXvmmLeYAK+202sCa8i0VSrRcS2pSLoWdwfJTYwTV1VcjOcU6do4GSBN4r+ROl ShRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R6eoBkV9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si803473edd.82.2021.08.14.10.43.21; Sat, 14 Aug 2021 10:43:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R6eoBkV9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238953AbhHNRmP (ORCPT + 99 others); Sat, 14 Aug 2021 13:42:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21045 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238915AbhHNRlz (ORCPT ); Sat, 14 Aug 2021 13:41:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628962883; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=4wV7V3qeD9YcjdJFq5SbCoDMmsCijaAxtKzqeyOb8Uo=; b=R6eoBkV9oed4aCxJYLuXJ9gHbtebKpVuzBZbQa9hLTefDJwb1MmxEMO7alwAbXuhu58URQ rzF8CdJFe96+JcsinM47WHctoeVsJEQTeMYqaAqoDo3tGBdpWSM+PDzbHe4MEaMMZFNSUW FiW0zC+MQGc8RYp9cLssJFGrB61frk0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-123-qbvDlX_YPiewq-11W8l3gw-1; Sat, 14 Aug 2021 13:41:20 -0400 X-MC-Unique: qbvDlX_YPiewq-11W8l3gw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 398888799E0; Sat, 14 Aug 2021 17:41:18 +0000 (UTC) Received: from llong.com (unknown [10.22.8.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 706D61036D14; Sat, 14 Aug 2021 17:41:16 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrew Morton , Roman Gushchin , Phil Auld , Peter Zijlstra , Juri Lelli , Frederic Weisbecker , Marcelo Tosatti , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Waiman Long Subject: [PATCH v5 3/6] cgroup/cpuset: Add a new isolated cpus.partition type Date: Sat, 14 Aug 2021 13:38:45 -0400 Message-Id: <20210814173848.11540-4-longman@redhat.com> In-Reply-To: <20210814173848.11540-1-longman@redhat.com> References: <20210814173848.11540-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=TBD commit 994fb794cb252edd124a46ca0994e37a4726a100 Author: Waiman Long Date: Sat, 19 Jun 2021 13:28:19 -0400 cgroup/cpuset: Add a new isolated cpus.partition type Cpuset v1 uses the sched_load_balance control file to determine if load balancing should be enabled. Cpuset v2 gets rid of sched_load_balance as its use may require disabling load balancing at cgroup root. For workloads that require very low latency like DPDK, the latency jitters caused by periodic load balancing may exceed the desired latency limit. When cpuset v2 is in use, the only way to avoid this latency cost is to use the "isolcpus=" kernel boot option to isolate a set of CPUs. After the kernel boot, however, there is no way to add or remove CPUs from this isolated set. For workloads that are more dynamic in nature, that means users have to provision enough CPUs for the worst case situation resulting in excess idle CPUs. To address this issue for cpuset v2, a new cpuset.cpus.partition type "isolated" is added which allows the creation of a cpuset partition without load balancing. This will allow system administrators to dynamically adjust the size of isolated partition to the current need of the workload without rebooting the system. Signed-off-by: Waiman Long Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 48 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 5fec3c96465c..d7b3eb024b84 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -193,6 +193,8 @@ struct cpuset { * * 1 - partition root * + * 2 - partition root without load balancing (isolated) + * * -1 - invalid partition root * None of the cpus in cpus_allowed can be put into the parent's * subparts_cpus. In this case, the cpuset is not a real partition @@ -202,6 +204,7 @@ struct cpuset { */ #define PRS_DISABLED 0 #define PRS_ENABLED 1 +#define PRS_ISOLATED 2 #define PRS_ERROR -1 /* @@ -1298,17 +1301,22 @@ static int update_parent_subparts_cpumask(struct cpuset *cpuset, int cmd, if (cmd == partcmd_update) { /* - * Check for possible transition between PRS_ENABLED - * and PRS_ERROR. + * Check for possible transition between PRS_ERROR and + * PRS_ENABLED/PRS_ISOLATED. */ switch (cpuset->partition_root_state) { case PRS_ENABLED: + case PRS_ISOLATED: if (part_error) new_prs = PRS_ERROR; break; case PRS_ERROR: - if (!part_error) + if (part_error) + break; + if (is_sched_load_balance(cpuset)) new_prs = PRS_ENABLED; + else + new_prs = PRS_ISOLATED; break; } } @@ -1443,6 +1451,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp) break; case PRS_ENABLED: + case PRS_ISOLATED: if (update_parent_subparts_cpumask(cp, partcmd_update, NULL, tmp)) update_tasks_cpumask(parent); /* @@ -1468,7 +1477,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp) spin_lock_irq(&callback_lock); - if (cp->nr_subparts_cpus && (new_prs != PRS_ENABLED)) { + if (cp->nr_subparts_cpus && (new_prs <= 0)) { /* * Put all active subparts_cpus back to effective_cpus. */ @@ -2007,6 +2016,7 @@ static int update_prstate(struct cpuset *cs, int new_prs) int err, old_prs = cs->partition_root_state; struct cpuset *parent = parent_cs(cs); struct tmpmasks tmpmask; + bool sched_domain_rebuilt = false; if (old_prs == new_prs) return 0; @@ -2041,6 +2051,22 @@ static int update_prstate(struct cpuset *cs, int new_prs) update_flag(CS_CPU_EXCLUSIVE, cs, 0); goto out; } + + if (new_prs == PRS_ISOLATED) { + /* + * Disable the load balance flag should not return an + * error unless the system is running out of memory. + */ + update_flag(CS_SCHED_LOAD_BALANCE, cs, 0); + sched_domain_rebuilt = true; + } + } else if (old_prs && new_prs) { + /* + * A change in load balance state only, no change in cpumasks. + */ + update_flag(CS_SCHED_LOAD_BALANCE, cs, (new_prs != PRS_ISOLATED)); + err = 0; + goto out; /* Sched domain is rebuilt in update_flag() */ } else { /* * Switch back to member is always allowed even if it @@ -2073,6 +2099,12 @@ static int update_prstate(struct cpuset *cs, int new_prs) /* Turning off CS_CPU_EXCLUSIVE will not return error */ update_flag(CS_CPU_EXCLUSIVE, cs, 0); + + if (!is_sched_load_balance(cs)) { + /* Make sure load balance is on */ + update_flag(CS_SCHED_LOAD_BALANCE, cs, 1); + sched_domain_rebuilt = true; + } } /* @@ -2085,7 +2117,8 @@ static int update_prstate(struct cpuset *cs, int new_prs) if (parent->child_ecpus_count) update_sibling_cpumasks(parent, cs, &tmpmask); - rebuild_sched_domains_locked(); + if (!sched_domain_rebuilt) + rebuild_sched_domains_locked(); out: if (!err) { spin_lock_irq(&callback_lock); @@ -2588,6 +2621,9 @@ static int sched_partition_show(struct seq_file *seq, void *v) case PRS_ENABLED: seq_puts(seq, "root\n"); break; + case PRS_ISOLATED: + seq_puts(seq, "isolated\n"); + break; case PRS_DISABLED: seq_puts(seq, "member\n"); break; @@ -2618,6 +2654,8 @@ static ssize_t sched_partition_write(struct kernfs_open_file *of, char *buf, val = PRS_ENABLED; else if (!strcmp(buf, "member")) val = PRS_DISABLED; + else if (!strcmp(buf, "isolated")) + val = PRS_ISOLATED; else return -EINVAL; -- 2.18.1