Message ID | 20210621184924.27493-4-longman@redhat.com |
---|---|
State | New |
Headers | show |
Series | cgroup/cpuset: Add new cpuset partition type & empty effecitve cpus | expand |
Hello. On Mon, Jun 21, 2021 at 02:49:21PM -0400, Waiman Long <longman@redhat.com> wrote: > 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. I like this work. Would it be worth generalizing the API to be on par with what isolcpus= can configure? (I.e. not only load balancing but the other dimensions of isolation (like the flags nohz and managed_irq now).) I don't know if all such behaviors could be implemented dynamically (likely not easy) but the API could initially implement just what you do here with the "isolated" partition type. The variant I'm thinking of would keep just the "root" and "member" partitions type and the "root" type could be additionally configured via cpuset.cpus.partition.flags (for example). WDYT? Michal
On 6/24/21 8:51 AM, Michal Koutný wrote: > Hello. > > On Mon, Jun 21, 2021 at 02:49:21PM -0400, Waiman Long <longman@redhat.com> wrote: >> 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. > I like this work. > Would it be worth generalizing the API to be on par with what isolcpus= > can configure? (I.e. not only load balancing but the other dimensions of > isolation (like the flags nohz and managed_irq now).) Good point, the isolated partition is equivalent to isolcpus=domain. I will need to evaluate the nohz and managed_irq options to see if they can be done dynamically without adding a lot of overhead. If so, we can extend the functionality to cover that in future patches. Right now, this is for the domain functionality only. If we can cover the nohz and managed_irq options, we can deprecate isolcpus and advocate the use of cgroup instead. > > I don't know if all such behaviors could be implemented dynamically > (likely not easy) but the API could initially implement just what you do > here with the "isolated" partition type. > > The variant I'm thinking of would keep just the "root" and "member" > partitions type and the "root" type could be additionally configured via > cpuset.cpus.partition.flags (for example). > > WDYT? What I am thinking is that "isolated" means "isolated:domain" or one can do "isolated:nohz,domain,manged_irq" just like the current isolcpus boot option. I don't think we really need to add an extra flags control file. Cheers, Longman
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 3fe68d0f593d..1a4b90e70e68 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -169,6 +169,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 @@ -180,6 +182,7 @@ struct cpuset { */ #define PRS_DISABLED 0 #define PRS_ENABLED 1 +#define PRS_ISOLATED 2 #define PRS_ERROR -1 /* @@ -1267,17 +1270,22 @@ static int update_parent_subparts_cpumask(struct cpuset *cpuset, int cmd, int prev_prs = cpuset->partition_root_state; /* - * 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) cpuset->partition_root_state = PRS_ERROR; break; case PRS_ERROR: - if (!part_error) + if (part_error) + break; + if (is_sched_load_balance(cpuset)) cpuset->partition_root_state = PRS_ENABLED; + else + cpuset->partition_root_state = PRS_ISOLATED; break; } /* @@ -1409,6 +1417,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); break; @@ -1429,7 +1438,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp) spin_lock_irq(&callback_lock); if (cp->nr_subparts_cpus && - (cp->partition_root_state != PRS_ENABLED)) { + (cp->partition_root_state <= 0)) { /* * Put all active subparts_cpus back to effective_cpus. */ @@ -1963,6 +1972,7 @@ static int update_prstate(struct cpuset *cs, int new_prs) int err; struct cpuset *parent = parent_cs(cs); struct tmpmasks tmpmask; + bool sched_domain_rebuilt = false; if (new_prs == cs->partition_root_state) return 0; @@ -1993,11 +2003,30 @@ static int update_prstate(struct cpuset *cs, int new_prs) err = update_parent_subparts_cpumask(cs, partcmd_enable, NULL, &tmpmask); + if (err) { update_flag(CS_CPU_EXCLUSIVE, cs, 0); goto out; } - cs->partition_root_state = PRS_ENABLED; + 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; + } + + cs->partition_root_state = new_prs; + } else if (cs->partition_root_state && new_prs) { + /* + * A change in load balance state only, no change in cpumasks. + */ + update_flag(CS_SCHED_LOAD_BALANCE, cs, (new_prs != PRS_ISOLATED)); + + cs->partition_root_state = new_prs; + err = 0; + goto out; /* Sched domain is rebuilt in update_flag() */ } else { /* * Switch back to member is always allowed if PRS_ERROR. @@ -2024,6 +2053,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; + } } /* @@ -2036,7 +2071,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: free_cpumasks(NULL, &tmpmask); return err; @@ -2531,6 +2567,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; @@ -2557,6 +2596,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;