naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
52b84b
From 2240e7955d64260e94dd52a3ab9855d267c2af89 Mon Sep 17 00:00:00 2001
52b84b
From: Tejun Heo <tj@kernel.org>
52b84b
Date: Wed, 13 Jun 2018 14:16:35 -0700
52b84b
Subject: [PATCH] core: add IODeviceLatencyTargetSec
52b84b
52b84b
This adds support for the following proposed latency based IO control
52b84b
mechanism.
52b84b
52b84b
  https://lkml.org/lkml/2018/6/5/428
52b84b
52b84b
(cherry picked from commit 6ae4283cb14c4e4a895f4bbba703804e4128c86c)
52b84b
52b84b
Resolves: #1831519
52b84b
---
52b84b
 man/systemd.resource-control.xml      |  29 +++++--
52b84b
 src/core/cgroup.c                     |  56 +++++++++++--
52b84b
 src/core/cgroup.h                     |   9 +++
52b84b
 src/core/dbus-cgroup.c                | 111 ++++++++++++++++++++++++++
52b84b
 src/core/load-fragment-gperf.gperf.m4 |   1 +
52b84b
 src/core/load-fragment.c              |  72 +++++++++++++++++
52b84b
 src/core/load-fragment.h              |   1 +
52b84b
 src/shared/bus-unit-util.c            |  31 +++++++
52b84b
 src/systemctl/systemctl.c             |  22 +++++
52b84b
 9 files changed, 320 insertions(+), 12 deletions(-)
52b84b
52b84b
diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml
52b84b
index 4329742e94..b0064bf98f 100644
52b84b
--- a/man/systemd.resource-control.xml
52b84b
+++ b/man/systemd.resource-control.xml
52b84b
@@ -417,11 +417,11 @@
52b84b
         <listitem>
52b84b
           <para>Set the per-device overall block I/O weight for the executed processes, if the unified control group
52b84b
           hierarchy is used on the system. Takes a space-separated pair of a file path and a weight value to specify
52b84b
-          the device specific weight value, between 1 and 10000. (Example: "/dev/sda 1000"). The file path may be
52b84b
-          specified as path to a block device node or as any other file, in which case the backing block device of the
52b84b
-          file system of the file is determined. This controls the <literal>io.weight</literal> control group
52b84b
-          attribute, which defaults to 100. Use this option multiple times to set weights for multiple devices. For
52b84b
-          details about this control group attribute, see 
52b84b
+          the device specific weight value, between 1 and 10000. (Example: <literal>/dev/sda 1000</literal>). The file
52b84b
+          path may be specified as path to a block device node or as any other file, in which case the backing block
52b84b
+          device of the file system of the file is determined. This controls the <literal>io.weight</literal> control
52b84b
+          group attribute, which defaults to 100. Use this option multiple times to set weights for multiple devices.
52b84b
+          For details about this control group attribute, see 
52b84b
           url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
52b84b
 
52b84b
           <para>Implies <literal>IOAccounting=true</literal>.</para>
52b84b
@@ -482,6 +482,25 @@
52b84b
         </listitem>
52b84b
       </varlistentry>
52b84b
 
52b84b
+      <varlistentry>
52b84b
+        <term><varname>IODeviceLatencyTargetSec=<replaceable>device</replaceable> <replaceable>target</replaceable></varname></term>
52b84b
+
52b84b
+        <listitem>
52b84b
+          <para>Set the per-device average target I/O latency for the executed processes, if the unified control group
52b84b
+          hierarchy is used on the system. Takes a file path and a timespan separated by a space to specify
52b84b
+          the device specific latency target. (Example: "/dev/sda 25ms"). The file path may be specified
52b84b
+          as path to a block device node or as any other file, in which case the backing block device of the file
52b84b
+          system of the file is determined. This controls the <literal>io.latency</literal> control group
52b84b
+          attribute. Use this option multiple times to set latency target for multiple devices. For details about this
52b84b
+          control group attribute, see 
52b84b
+          url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
52b84b
+
52b84b
+          <para>Implies <literal>IOAccounting=true</literal>.</para>
52b84b
+
52b84b
+          <para>These settings are supported only if the unified control group hierarchy is used.</para>
52b84b
+        </listitem>
52b84b
+      </varlistentry>
52b84b
+
52b84b
       <varlistentry>
52b84b
         <term><varname>IPAccounting=</varname></term>
52b84b
 
52b84b
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
52b84b
index 9e4c3c7dac..ad8219bd79 100644
52b84b
--- a/src/core/cgroup.c
52b84b
+++ b/src/core/cgroup.c
52b84b
@@ -114,6 +114,15 @@ void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight
52b84b
         free(w);
52b84b
 }
52b84b
 
52b84b
+void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLatency *l) {
52b84b
+        assert(c);
52b84b
+        assert(l);
52b84b
+
52b84b
+        LIST_REMOVE(device_latencies, c->io_device_latencies, l);
52b84b
+        free(l->path);
52b84b
+        free(l);
52b84b
+}
52b84b
+
52b84b
 void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l) {
52b84b
         assert(c);
52b84b
         assert(l);
52b84b
@@ -147,6 +156,9 @@ void cgroup_context_done(CGroupContext *c) {
52b84b
         while (c->io_device_weights)
52b84b
                 cgroup_context_free_io_device_weight(c, c->io_device_weights);
52b84b
 
52b84b
+        while (c->io_device_latencies)
52b84b
+                cgroup_context_free_io_device_latency(c, c->io_device_latencies);
52b84b
+
52b84b
         while (c->io_device_limits)
52b84b
                 cgroup_context_free_io_device_limit(c, c->io_device_limits);
52b84b
 
52b84b
@@ -171,6 +183,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
52b84b
         _cleanup_free_ char *cpuset_mems = NULL;
52b84b
         CGroupIODeviceLimit *il;
52b84b
         CGroupIODeviceWeight *iw;
52b84b
+        CGroupIODeviceLatency *l;
52b84b
         CGroupBlockIODeviceBandwidth *b;
52b84b
         CGroupBlockIODeviceWeight *w;
52b84b
         CGroupDeviceAllow *a;
52b84b
@@ -256,11 +269,18 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
52b84b
 
52b84b
         LIST_FOREACH(device_weights, iw, c->io_device_weights)
52b84b
                 fprintf(f,
52b84b
-                        "%sIODeviceWeight=%s %" PRIu64,
52b84b
+                        "%sIODeviceWeight=%s %" PRIu64 "\n",
52b84b
                         prefix,
52b84b
                         iw->path,
52b84b
                         iw->weight);
52b84b
 
52b84b
+        LIST_FOREACH(device_latencies, l, c->io_device_latencies)
52b84b
+                fprintf(f,
52b84b
+                        "%sIODeviceLatencyTargetSec=%s %s\n",
52b84b
+                        prefix,
52b84b
+                        l->path,
52b84b
+                        format_timespan(u, sizeof(u), l->target_usec, 1));
52b84b
+
52b84b
         LIST_FOREACH(device_limits, il, c->io_device_limits) {
52b84b
                 char buf[FORMAT_BYTES_MAX];
52b84b
                 CGroupIOLimitType type;
52b84b
@@ -573,6 +593,7 @@ static bool cgroup_context_has_io_config(CGroupContext *c) {
52b84b
                 c->io_weight != CGROUP_WEIGHT_INVALID ||
52b84b
                 c->startup_io_weight != CGROUP_WEIGHT_INVALID ||
52b84b
                 c->io_device_weights ||
52b84b
+                c->io_device_latencies ||
52b84b
                 c->io_device_limits;
52b84b
 }
52b84b
 
52b84b
@@ -646,6 +667,26 @@ static void cgroup_apply_blkio_device_weight(Unit *u, const char *dev_path, uint
52b84b
                               "Failed to set blkio.weight_device: %m");
52b84b
 }
52b84b
 
52b84b
+static void cgroup_apply_io_device_latency(Unit *u, const char *dev_path, usec_t target) {
52b84b
+        char buf[DECIMAL_STR_MAX(dev_t)*2+2+7+DECIMAL_STR_MAX(uint64_t)+1];
52b84b
+        dev_t dev;
52b84b
+        int r;
52b84b
+
52b84b
+        r = lookup_block_device(dev_path, &dev;;
52b84b
+        if (r < 0)
52b84b
+                return;
52b84b
+
52b84b
+        if (target != USEC_INFINITY)
52b84b
+                xsprintf(buf, "%u:%u target=%" PRIu64 "\n", major(dev), minor(dev), target);
52b84b
+        else
52b84b
+                xsprintf(buf, "%u:%u target=max\n", major(dev), minor(dev));
52b84b
+
52b84b
+        r = cg_set_attribute("io", u->cgroup_path, "io.latency", buf);
52b84b
+        if (r < 0)
52b84b
+                log_unit_full(u, IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r,
52b84b
+                              "Failed to set io.latency on cgroup %s: %m", u->cgroup_path);
52b84b
+}
52b84b
+
52b84b
 static void cgroup_apply_io_device_limit(Unit *u, const char *dev_path, uint64_t *limits) {
52b84b
         char limit_bufs[_CGROUP_IO_LIMIT_TYPE_MAX][DECIMAL_STR_MAX(uint64_t)];
52b84b
         char buf[DECIMAL_STR_MAX(dev_t)*2+2+(6+DECIMAL_STR_MAX(uint64_t)+1)*4];
52b84b
@@ -827,13 +868,11 @@ static void cgroup_context_apply(
52b84b
                         if (has_io) {
52b84b
                                 CGroupIODeviceWeight *w;
52b84b
 
52b84b
-                                /* FIXME: no way to reset this list */
52b84b
                                 LIST_FOREACH(device_weights, w, c->io_device_weights)
52b84b
                                         cgroup_apply_io_device_weight(u, w->path, w->weight);
52b84b
                         } else if (has_blockio) {
52b84b
                                 CGroupBlockIODeviceWeight *w;
52b84b
 
52b84b
-                                /* FIXME: no way to reset this list */
52b84b
                                 LIST_FOREACH(device_weights, w, c->blockio_device_weights) {
52b84b
                                         weight = cgroup_weight_blkio_to_io(w->weight);
52b84b
 
52b84b
@@ -843,9 +882,15 @@ static void cgroup_context_apply(
52b84b
                                         cgroup_apply_io_device_weight(u, w->path, weight);
52b84b
                                 }
52b84b
                         }
52b84b
+
52b84b
+                        if (has_io) {
52b84b
+                                CGroupIODeviceLatency *l;
52b84b
+
52b84b
+                                LIST_FOREACH(device_latencies, l, c->io_device_latencies)
52b84b
+                                        cgroup_apply_io_device_latency(u, l->path, l->target_usec);
52b84b
+                        }
52b84b
                 }
52b84b
 
52b84b
-                /* Apply limits and free ones without config. */
52b84b
                 if (has_io) {
52b84b
                         CGroupIODeviceLimit *l;
52b84b
 
52b84b
@@ -902,7 +947,6 @@ static void cgroup_context_apply(
52b84b
                         if (has_io) {
52b84b
                                 CGroupIODeviceWeight *w;
52b84b
 
52b84b
-                                /* FIXME: no way to reset this list */
52b84b
                                 LIST_FOREACH(device_weights, w, c->io_device_weights) {
52b84b
                                         weight = cgroup_weight_io_to_blkio(w->weight);
52b84b
 
52b84b
@@ -914,13 +958,11 @@ static void cgroup_context_apply(
52b84b
                         } else if (has_blockio) {
52b84b
                                 CGroupBlockIODeviceWeight *w;
52b84b
 
52b84b
-                                /* FIXME: no way to reset this list */
52b84b
                                 LIST_FOREACH(device_weights, w, c->blockio_device_weights)
52b84b
                                         cgroup_apply_blkio_device_weight(u, w->path, w->weight);
52b84b
                         }
52b84b
                 }
52b84b
 
52b84b
-                /* Apply limits and free ones without config. */
52b84b
                 if (has_io) {
52b84b
                         CGroupIODeviceLimit *l;
52b84b
 
52b84b
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
52b84b
index da10575394..f7365b4c46 100644
52b84b
--- a/src/core/cgroup.h
52b84b
+++ b/src/core/cgroup.h
52b84b
@@ -13,6 +13,7 @@ typedef struct CGroupContext CGroupContext;
52b84b
 typedef struct CGroupDeviceAllow CGroupDeviceAllow;
52b84b
 typedef struct CGroupIODeviceWeight CGroupIODeviceWeight;
52b84b
 typedef struct CGroupIODeviceLimit CGroupIODeviceLimit;
52b84b
+typedef struct CGroupIODeviceLatency CGroupIODeviceLatency;
52b84b
 typedef struct CGroupBlockIODeviceWeight CGroupBlockIODeviceWeight;
52b84b
 typedef struct CGroupBlockIODeviceBandwidth CGroupBlockIODeviceBandwidth;
52b84b
 
52b84b
@@ -52,6 +53,12 @@ struct CGroupIODeviceLimit {
52b84b
         uint64_t limits[_CGROUP_IO_LIMIT_TYPE_MAX];
52b84b
 };
52b84b
 
52b84b
+struct CGroupIODeviceLatency {
52b84b
+        LIST_FIELDS(CGroupIODeviceLatency, device_latencies);
52b84b
+        char *path;
52b84b
+        usec_t target_usec;
52b84b
+};
52b84b
+
52b84b
 struct CGroupBlockIODeviceWeight {
52b84b
         LIST_FIELDS(CGroupBlockIODeviceWeight, device_weights);
52b84b
         char *path;
52b84b
@@ -85,6 +92,7 @@ struct CGroupContext {
52b84b
         uint64_t startup_io_weight;
52b84b
         LIST_HEAD(CGroupIODeviceWeight, io_device_weights);
52b84b
         LIST_HEAD(CGroupIODeviceLimit, io_device_limits);
52b84b
+        LIST_HEAD(CGroupIODeviceLatency, io_device_latencies);
52b84b
 
52b84b
         uint64_t memory_low;
52b84b
         uint64_t memory_high;
52b84b
@@ -137,6 +145,7 @@ CGroupMask cgroup_context_get_mask(CGroupContext *c);
52b84b
 void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a);
52b84b
 void cgroup_context_free_io_device_weight(CGroupContext *c, CGroupIODeviceWeight *w);
52b84b
 void cgroup_context_free_io_device_limit(CGroupContext *c, CGroupIODeviceLimit *l);
52b84b
+void cgroup_context_free_io_device_latency(CGroupContext *c, CGroupIODeviceLatency *l);
52b84b
 void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODeviceWeight *w);
52b84b
 void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockIODeviceBandwidth *b);
52b84b
 
52b84b
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
52b84b
index 30d4e83932..a1d3014d61 100644
52b84b
--- a/src/core/dbus-cgroup.c
52b84b
+++ b/src/core/dbus-cgroup.c
52b84b
@@ -140,6 +140,36 @@ static int property_get_io_device_limits(
52b84b
         return sd_bus_message_close_container(reply);
52b84b
 }
52b84b
 
52b84b
+static int property_get_io_device_latency(
52b84b
+                sd_bus *bus,
52b84b
+                const char *path,
52b84b
+                const char *interface,
52b84b
+                const char *property,
52b84b
+                sd_bus_message *reply,
52b84b
+                void *userdata,
52b84b
+                sd_bus_error *error) {
52b84b
+
52b84b
+        CGroupContext *c = userdata;
52b84b
+        CGroupIODeviceLatency *l;
52b84b
+        int r;
52b84b
+
52b84b
+        assert(bus);
52b84b
+        assert(reply);
52b84b
+        assert(c);
52b84b
+
52b84b
+        r = sd_bus_message_open_container(reply, 'a', "(st)");
52b84b
+        if (r < 0)
52b84b
+                return r;
52b84b
+
52b84b
+        LIST_FOREACH(device_latencies, l, c->io_device_latencies) {
52b84b
+                r = sd_bus_message_append(reply, "(st)", l->path, l->target_usec);
52b84b
+                if (r < 0)
52b84b
+                        return r;
52b84b
+        }
52b84b
+
52b84b
+        return sd_bus_message_close_container(reply);
52b84b
+}
52b84b
+
52b84b
 static int property_get_blockio_device_weight(
52b84b
                 sd_bus *bus,
52b84b
                 const char *path,
52b84b
@@ -314,6 +344,7 @@ const sd_bus_vtable bus_cgroup_vtable[] = {
52b84b
         SD_BUS_PROPERTY("IOWriteBandwidthMax", "a(st)", property_get_io_device_limits, 0, 0),
52b84b
         SD_BUS_PROPERTY("IOReadIOPSMax", "a(st)", property_get_io_device_limits, 0, 0),
52b84b
         SD_BUS_PROPERTY("IOWriteIOPSMax", "a(st)", property_get_io_device_limits, 0, 0),
52b84b
+        SD_BUS_PROPERTY("IODeviceLatencyTargetUSec", "a(st)", property_get_io_device_latency, 0, 0),
52b84b
         SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, blockio_accounting), 0),
52b84b
         SD_BUS_PROPERTY("BlockIOWeight", "t", NULL, offsetof(CGroupContext, blockio_weight), 0),
52b84b
         SD_BUS_PROPERTY("StartupBlockIOWeight", "t", NULL, offsetof(CGroupContext, startup_blockio_weight), 0),
52b84b
@@ -898,6 +929,86 @@ int bus_cgroup_set_property(
52b84b
 
52b84b
                 return 1;
52b84b
 
52b84b
+        } else if (streq(name, "IODeviceLatencyTargetUSec")) {
52b84b
+                const char *path;
52b84b
+                uint64_t target;
52b84b
+                unsigned n = 0;
52b84b
+
52b84b
+                r = sd_bus_message_enter_container(message, 'a', "(st)");
52b84b
+                if (r < 0)
52b84b
+                        return r;
52b84b
+
52b84b
+                while ((r = sd_bus_message_read(message, "(st)", &path, &target)) > 0) {
52b84b
+
52b84b
+                        if (!path_is_normalized(path))
52b84b
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Path '%s' specified in %s= is not normalized.", name, path);
52b84b
+
52b84b
+                        if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
52b84b
+                                CGroupIODeviceLatency *a = NULL, *b;
52b84b
+
52b84b
+                                LIST_FOREACH(device_latencies, b, c->io_device_latencies) {
52b84b
+                                        if (path_equal(b->path, path)) {
52b84b
+                                                a = b;
52b84b
+                                                break;
52b84b
+                                        }
52b84b
+                                }
52b84b
+
52b84b
+                                if (!a) {
52b84b
+                                        a = new0(CGroupIODeviceLatency, 1);
52b84b
+                                        if (!a)
52b84b
+                                                return -ENOMEM;
52b84b
+
52b84b
+                                        a->path = strdup(path);
52b84b
+                                        if (!a->path) {
52b84b
+                                                free(a);
52b84b
+                                                return -ENOMEM;
52b84b
+                                        }
52b84b
+                                        LIST_PREPEND(device_latencies, c->io_device_latencies, a);
52b84b
+                                }
52b84b
+
52b84b
+                                a->target_usec = target;
52b84b
+                        }
52b84b
+
52b84b
+                        n++;
52b84b
+                }
52b84b
+
52b84b
+                r = sd_bus_message_exit_container(message);
52b84b
+                if (r < 0)
52b84b
+                        return r;
52b84b
+
52b84b
+                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
52b84b
+                        _cleanup_free_ char *buf = NULL;
52b84b
+                        _cleanup_fclose_ FILE *f = NULL;
52b84b
+                        char ts[FORMAT_TIMESPAN_MAX];
52b84b
+                        CGroupIODeviceLatency *a;
52b84b
+                        size_t size = 0;
52b84b
+
52b84b
+                        if (n == 0) {
52b84b
+                                while (c->io_device_latencies)
52b84b
+                                        cgroup_context_free_io_device_latency(c, c->io_device_latencies);
52b84b
+                        }
52b84b
+
52b84b
+                        unit_invalidate_cgroup(u, CGROUP_MASK_IO);
52b84b
+
52b84b
+                        f = open_memstream(&buf, &size);
52b84b
+                        if (!f)
52b84b
+                                return -ENOMEM;
52b84b
+
52b84b
+                        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
52b84b
+
52b84b
+                        fputs("IODeviceLatencyTargetSec=\n", f);
52b84b
+                        LIST_FOREACH(device_latencies, a, c->io_device_latencies)
52b84b
+                                fprintf(f, "IODeviceLatencyTargetSec=%s %s\n",
52b84b
+                                        a->path, format_timespan(ts, sizeof(ts), a->target_usec, 1));
52b84b
+
52b84b
+                        r = fflush_and_check(f);
52b84b
+                        if (r < 0)
52b84b
+                                return r;
52b84b
+                        unit_write_setting(u, flags, name, buf);
52b84b
+                }
52b84b
+
52b84b
+                return 1;
52b84b
+
52b84b
         } else if (STR_IN_SET(name, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
52b84b
                 const char *path;
52b84b
                 bool read = true;
52b84b
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
52b84b
index 8883818ff2..23879c001f 100644
52b84b
--- a/src/core/load-fragment-gperf.gperf.m4
52b84b
+++ b/src/core/load-fragment-gperf.gperf.m4
52b84b
@@ -185,6 +185,7 @@ $1.IOReadBandwidthMax,           config_parse_io_limit,              0,
52b84b
 $1.IOWriteBandwidthMax,          config_parse_io_limit,              0,                             offsetof($1, cgroup_context)
52b84b
 $1.IOReadIOPSMax,                config_parse_io_limit,              0,                             offsetof($1, cgroup_context)
52b84b
 $1.IOWriteIOPSMax,               config_parse_io_limit,              0,                             offsetof($1, cgroup_context)
52b84b
+$1.IODeviceLatencyTargetSec,     config_parse_io_device_latency,     0,                             offsetof($1, cgroup_context)
52b84b
 $1.BlockIOAccounting,            config_parse_bool,                  0,                             offsetof($1, cgroup_context.blockio_accounting)
52b84b
 $1.BlockIOWeight,                config_parse_blockio_weight,        0,                             offsetof($1, cgroup_context.blockio_weight)
52b84b
 $1.StartupBlockIOWeight,         config_parse_blockio_weight,        0,                             offsetof($1, cgroup_context.startup_blockio_weight)
52b84b
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
52b84b
index 9b2724307d..1e22013b75 100644
52b84b
--- a/src/core/load-fragment.c
52b84b
+++ b/src/core/load-fragment.c
52b84b
@@ -3383,6 +3383,77 @@ int config_parse_io_device_weight(
52b84b
         return 0;
52b84b
 }
52b84b
 
52b84b
+int config_parse_io_device_latency(
52b84b
+                const char *unit,
52b84b
+                const char *filename,
52b84b
+                unsigned line,
52b84b
+                const char *section,
52b84b
+                unsigned section_line,
52b84b
+                const char *lvalue,
52b84b
+                int ltype,
52b84b
+                const char *rvalue,
52b84b
+                void *data,
52b84b
+                void *userdata) {
52b84b
+
52b84b
+        _cleanup_free_ char *path = NULL, *resolved = NULL;
52b84b
+        CGroupIODeviceLatency *l;
52b84b
+        CGroupContext *c = data;
52b84b
+        const char *p = rvalue;
52b84b
+        usec_t usec;
52b84b
+        int r;
52b84b
+
52b84b
+        assert(filename);
52b84b
+        assert(lvalue);
52b84b
+        assert(rvalue);
52b84b
+
52b84b
+        if (isempty(rvalue)) {
52b84b
+                while (c->io_device_latencies)
52b84b
+                        cgroup_context_free_io_device_latency(c, c->io_device_latencies);
52b84b
+
52b84b
+                return 0;
52b84b
+        }
52b84b
+
52b84b
+        r = extract_first_word(&p, &path, NULL, EXTRACT_QUOTES);
52b84b
+        if (r == -ENOMEM)
52b84b
+                return log_oom();
52b84b
+        if (r < 0) {
52b84b
+                log_syntax(unit, LOG_WARNING, filename, line, r,
52b84b
+                           "Invalid syntax, ignoring: %s", rvalue);
52b84b
+                return 0;
52b84b
+        }
52b84b
+        if (r == 0 || isempty(p)) {
52b84b
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
52b84b
+                           "Failed to extract device path and latency from '%s', ignoring.", rvalue);
52b84b
+                return 0;
52b84b
+        }
52b84b
+
52b84b
+        r = unit_full_printf(userdata, path, &resolved);
52b84b
+        if (r < 0) {
52b84b
+                log_syntax(unit, LOG_WARNING, filename, line, r,
52b84b
+                           "Failed to resolve unit specifiers in '%s', ignoring: %m", path);
52b84b
+                return 0;
52b84b
+        }
52b84b
+
52b84b
+        r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
52b84b
+        if (r < 0)
52b84b
+                return 0;
52b84b
+
52b84b
+        if (parse_sec(p, &usec) < 0) {
52b84b
+                log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse timer value, ignoring: %s", p);
52b84b
+                return 0;
52b84b
+        }
52b84b
+
52b84b
+        l = new0(CGroupIODeviceLatency, 1);
52b84b
+        if (!l)
52b84b
+                return log_oom();
52b84b
+
52b84b
+        l->path = TAKE_PTR(resolved);
52b84b
+        l->target_usec = usec;
52b84b
+
52b84b
+        LIST_PREPEND(device_latencies, c->io_device_latencies, l);
52b84b
+        return 0;
52b84b
+}
52b84b
+
52b84b
 int config_parse_io_limit(
52b84b
                 const char *unit,
52b84b
                 const char *filename,
52b84b
@@ -4572,6 +4643,7 @@ void unit_dump_config_items(FILE *f) {
52b84b
                 { config_parse_device_policy,         "POLICY" },
52b84b
                 { config_parse_io_limit,              "LIMIT" },
52b84b
                 { config_parse_io_device_weight,      "DEVICEWEIGHT" },
52b84b
+                { config_parse_io_device_latency,     "DEVICELATENCY" },
52b84b
                 { config_parse_blockio_bandwidth,     "BANDWIDTH" },
52b84b
                 { config_parse_blockio_weight,        "WEIGHT" },
52b84b
                 { config_parse_blockio_device_weight, "DEVICEWEIGHT" },
52b84b
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
52b84b
index 424fa478a7..65a94d53cc 100644
52b84b
--- a/src/core/load-fragment.h
52b84b
+++ b/src/core/load-fragment.h
52b84b
@@ -68,6 +68,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_tasks_max);
52b84b
 CONFIG_PARSER_PROTOTYPE(config_parse_delegate);
52b84b
 CONFIG_PARSER_PROTOTYPE(config_parse_device_policy);
52b84b
 CONFIG_PARSER_PROTOTYPE(config_parse_device_allow);
52b84b
+CONFIG_PARSER_PROTOTYPE(config_parse_io_device_latency);
52b84b
 CONFIG_PARSER_PROTOTYPE(config_parse_io_device_weight);
52b84b
 CONFIG_PARSER_PROTOTYPE(config_parse_io_limit);
52b84b
 CONFIG_PARSER_PROTOTYPE(config_parse_blockio_weight);
52b84b
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
52b84b
index e0b2cfb170..3c1ecf2027 100644
52b84b
--- a/src/shared/bus-unit-util.c
52b84b
+++ b/src/shared/bus-unit-util.c
52b84b
@@ -566,6 +566,37 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
52b84b
                 return 1;
52b84b
         }
52b84b
 
52b84b
+        if (streq(field, "IODeviceLatencyTargetSec")) {
52b84b
+                const char *field_usec = "IODeviceLatencyTargetUSec";
52b84b
+
52b84b
+                if (isempty(eq))
52b84b
+                        r = sd_bus_message_append(m, "(sv)", field_usec, "a(st)", USEC_INFINITY);
52b84b
+                else {
52b84b
+                        const char *path, *target, *e;
52b84b
+                        usec_t usec;
52b84b
+
52b84b
+                        e = strchr(eq, ' ');
52b84b
+                        if (!e) {
52b84b
+                                log_error("Failed to parse %s value %s.", field, eq);
52b84b
+                                return -EINVAL;
52b84b
+                        }
52b84b
+
52b84b
+                        path = strndupa(eq, e - eq);
52b84b
+                        target = e+1;
52b84b
+
52b84b
+                        r = parse_sec(target, &usec);
52b84b
+                        if (r < 0)
52b84b
+                                return log_error_errno(r, "Failed to parse %s value %s: %m", field, target);
52b84b
+
52b84b
+                        r = sd_bus_message_append(m, "(sv)", field_usec, "a(st)", 1, path, usec);
52b84b
+                }
52b84b
+
52b84b
+                if (r < 0)
52b84b
+                        return bus_log_create_error(r);
52b84b
+
52b84b
+                return 1;
52b84b
+        }
52b84b
+
52b84b
         if (STR_IN_SET(field, "IPAddressAllow", "IPAddressDeny")) {
52b84b
                 unsigned char prefixlen;
52b84b
                 union in_addr_union prefix = {};
52b84b
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
52b84b
index a3074bc5e3..559e49f104 100644
52b84b
--- a/src/systemctl/systemctl.c
52b84b
+++ b/src/systemctl/systemctl.c
52b84b
@@ -4875,6 +4875,28 @@ static int print_property(const char *name, sd_bus_message *m, bool value, bool
52b84b
 
52b84b
                         return 1;
52b84b
 
52b84b
+                }  else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN &&
52b84b
+                            streq(name, "IODeviceLatencyTargetUSec")) {
52b84b
+                        char ts[FORMAT_TIMESPAN_MAX];
52b84b
+                        const char *path;
52b84b
+                        uint64_t target;
52b84b
+
52b84b
+                        r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(st)");
52b84b
+                        if (r < 0)
52b84b
+                                return bus_log_parse_error(r);
52b84b
+
52b84b
+                        while ((r = sd_bus_message_read(m, "(st)", &path, &target)) > 0)
52b84b
+                                print_prop(name, "%s %s", strna(path),
52b84b
+                                           format_timespan(ts, sizeof(ts), target, 1));
52b84b
+                        if (r < 0)
52b84b
+                                return bus_log_parse_error(r);
52b84b
+
52b84b
+                        r = sd_bus_message_exit_container(m);
52b84b
+                        if (r < 0)
52b84b
+                                return bus_log_parse_error(r);
52b84b
+
52b84b
+                        return 1;
52b84b
+
52b84b
                 } else if (contents[0] == SD_BUS_TYPE_BYTE && streq(name, "StandardInputData")) {
52b84b
                         _cleanup_free_ char *h = NULL;
52b84b
                         const void *p;