]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: map io.bfq.weight to 1..1000
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 Feb 2021 08:48:19 +0000 (09:48 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 4 Feb 2021 18:15:03 +0000 (19:15 +0100)
Aaargh. See the comment in the code.

Apparently the range is like that:
$ sudo bash -c 'echo "default 1001" >/sys/fs/cgroup/user.slice/io.bfq.weight'
bash: line 0: echo: write error: Numerical result out of range

$ uname -r
5.11.0-0.rc4.129.fc34.x86_64

src/core/cgroup.c

index c881a1952675dcb5517158a5843758e1c1c5f852..c9cf7fb16c6abc9ac0d7379db923226d8810d6cd 100644 (file)
@@ -1057,6 +1057,23 @@ static int cgroup_apply_devices(Unit *u) {
         return r;
 }
 
+static void set_io_weight(Unit *u, const char *controller, uint64_t weight) {
+        char buf[8+DECIMAL_STR_MAX(uint64_t)+1];
+        const char *p;
+
+        p = strjoina(controller, ".weight");
+        xsprintf(buf, "default %" PRIu64 "\n", weight);
+        (void) set_attribute_and_warn(u, controller, p, buf);
+
+        /* FIXME: drop this when distro kernels properly support BFQ through "io.weight"
+         * See also: https://github.com/systemd/systemd/pull/13335 and
+         * https://github.com/torvalds/linux/commit/65752aef0a407e1ef17ec78a7fc31ba4e0b360f9.
+         * The range is 1..1000 apparently. */
+        p = strjoina(controller, ".bfq.weight");
+        xsprintf(buf, "%" PRIu64 "\n", (weight + 9) / 10);
+        (void) set_attribute_and_warn(u, controller, p, buf);
+}
+
 static void cgroup_context_apply(
                 Unit *u,
                 CGroupMask apply_mask,
@@ -1143,7 +1160,6 @@ static void cgroup_context_apply(
          * controller), and in case of containers we want to leave control of these attributes to the container manager
          * (and we couldn't access that stuff anyway, even if we tried if proper delegation is used). */
         if ((apply_mask & CGROUP_MASK_IO) && !is_local_root) {
-                char buf[8+DECIMAL_STR_MAX(uint64_t)+1];
                 bool has_io, has_blockio;
                 uint64_t weight;
 
@@ -1163,13 +1179,7 @@ static void cgroup_context_apply(
                 } else
                         weight = CGROUP_WEIGHT_DEFAULT;
 
-                xsprintf(buf, "default %" PRIu64 "\n", weight);
-                (void) set_attribute_and_warn(u, "io", "io.weight", buf);
-
-                /* FIXME: drop this when distro kernels properly support BFQ through "io.weight"
-                 * See also: https://github.com/systemd/systemd/pull/13335 */
-                xsprintf(buf, "%" PRIu64 "\n", weight);
-                (void) set_attribute_and_warn(u, "io", "io.bfq.weight", buf);
+                set_io_weight(u, "io", weight);
 
                 if (has_io) {
                         CGroupIODeviceLatency *latency;
@@ -1225,7 +1235,6 @@ static void cgroup_context_apply(
                 /* Applying a 'weight' never makes sense for the host root cgroup, and for containers this should be
                  * left to our container manager, too. */
                 if (!is_local_root) {
-                        char buf[DECIMAL_STR_MAX(uint64_t)+1];
                         uint64_t weight;
 
                         if (has_io) {
@@ -1241,13 +1250,7 @@ static void cgroup_context_apply(
                         else
                                 weight = CGROUP_BLKIO_WEIGHT_DEFAULT;
 
-                        xsprintf(buf, "%" PRIu64 "\n", weight);
-                        (void) set_attribute_and_warn(u, "blkio", "blkio.weight", buf);
-
-                        /* FIXME: drop this when distro kernels properly support BFQ through "blkio.weight"
-                         * See also: https://github.com/systemd/systemd/pull/13335 */
-                        xsprintf(buf, "%" PRIu64 "\n", weight);
-                        (void) set_attribute_and_warn(u, "blkio", "blkio.bfq.weight", buf);
+                        set_io_weight(u, "blkio", weight);
 
                         if (has_io) {
                                 CGroupIODeviceWeight *w;