daandemeyer / rpms / systemd

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