CGROUP_BLKIO_WEIGHT_MIN, CGROUP_BLKIO_WEIGHT_MAX);
}
-static void set_bfq_weight(Unit *u, const char *controller, uint64_t io_weight) {
- char buf[DECIMAL_STR_MAX(uint64_t)+STRLEN("\n")];
+static void set_bfq_weight(Unit *u, const char *controller, dev_t dev, uint64_t io_weight) {
+ char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+STRLEN("\n")];
const char *p;
uint64_t bfq_weight;
/* Adjust to kernel range is 1..1000, the default is 100. */
bfq_weight = BFQ_WEIGHT(io_weight);
- xsprintf(buf, "%" PRIu64 "\n", bfq_weight);
+ if (major(dev) > 0)
+ xsprintf(buf, "%u:%u %" PRIu64 "\n", major(dev), minor(dev), bfq_weight);
+ else
+ xsprintf(buf, "%" PRIu64 "\n", bfq_weight);
if (set_attribute_and_warn(u, controller, p, buf) >= 0 && io_weight != bfq_weight)
- log_unit_debug(u, "%sIOWeight=%" PRIu64 " scaled to %s=%" PRIu64,
+ log_unit_debug(u, "%sIO%sWeight=%" PRIu64 " scaled to %s=%" PRIu64,
streq(controller, "blkio") ? "Block" : "",
+ major(dev) > 0 ? "Device" : "",
io_weight, p, bfq_weight);
}
if (r < 0)
return;
+ /* BFQ per-device weights work since Linux kernel v5.4. */
+ set_bfq_weight(u, "io", dev, io_weight);
+
xsprintf(buf, "%u:%u %" PRIu64 "\n", major(dev), minor(dev), io_weight);
(void) set_attribute_and_warn(u, "io", "io.weight", buf);
}
assert(u);
- set_bfq_weight(u, "io", weight);
+ set_bfq_weight(u, "io", makedev(0, 0), weight);
xsprintf(buf, "default %" PRIu64 "\n", weight);
(void) set_attribute_and_warn(u, "io", "io.weight", buf);
assert(u);
- set_bfq_weight(u, "blkio", weight);
+ set_bfq_weight(u, "blkio", makedev(0, 0), weight);
xsprintf(buf, "%" PRIu64 "\n", weight);
(void) set_attribute_and_warn(u, "blkio", "blkio.weight", buf);