From 6537bdc0b973080428bf89d89af6548fcfd97177 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 21 Jul 2021 23:34:47 +0200 Subject: [PATCH] cgroup: Use and explain cpu.weight. --- content/posts/cgroup v2 by hand.adoc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/content/posts/cgroup v2 by hand.adoc b/content/posts/cgroup v2 by hand.adoc index d8ddc8d..384d4f1 100644 --- a/content/posts/cgroup v2 by hand.adoc +++ b/content/posts/cgroup v2 by hand.adoc @@ -91,7 +91,7 @@ the power of 2 CPU cores. echo "+cpu" > cgroup.subtree_control mkdir testgroup cd testgroup -echo "10" > cpu.weight.nice +echo "50" > cpu.weight echo "200000 100000" > cpu.max -------------------------------------------------------------------------------- @@ -99,9 +99,14 @@ Try adding your current shell to the group with `echo "$$" > cgroup.procs`. All processes you start from this shell are now in the same cgroup. But what does the example do, exactly? -- *cpu.weight.nice* works like the link:{url-nice}[nice] command (but it is not - the same) and has a range from -20 to 19. It is an alternate interface to - *cpu.weight* which has a range from 1 to 10,000. +- *cpu.weight* is the relative amount of CPU cycles the cgroup is getting under + load. The CPU cycles are distributed by adding up the weights of all _active_ + children and giving each the fraction matching the ratio of its weight against + the sum.footnote:[link:{url-kernel-doc}#weights[Kernel documentation on + Control Group v2, section “Resource Distribution Models” → “Weights”]] It has + a range from 1 to 10,000. If one process has a weight of 3,000 and the only + other active process has a weight of 7,000, the former will get 30% and the + latter 70% of CPU cycles. The default is 100. - *cpu.max* sets the “maximum bandwidth limit”. We told the kernel that the processes should use at most 200,000 µs every 100,000 µs, meaning they can use the power of up to 2 cores. @@ -115,6 +120,10 @@ You can add a cgroup column to link:{url-htop}[htop] by pressing kbd:[F2] and then navigating to “Columns”. Select “CGROUP” in “Available Columns” and press kbd:[Enter]. +[TIP] +*cpu.weight.nice* is an alternate interface to *cpu.weight* that uses the same +values used by link:{url-nice}[nice] and has a range from -20 to 19. + === Controlling CPU core usage This control group will use the cpuset controller to restrict the processes to