valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0330-cgroup-introduce-support-for-cgroup-v2-CPUSET-contro.patch

5d2ee9
From b55c9b8e717d1967e6aa16c1e2646fc81d899ab7 Mon Sep 17 00:00:00 2001
5d2ee9
From: Pavel Hrdina <phrdina@redhat.com>
5d2ee9
Date: Mon, 29 Jul 2019 17:50:05 +0200
5d2ee9
Subject: [PATCH] cgroup: introduce support for cgroup v2 CPUSET controller
5d2ee9
5d2ee9
Introduce support for configuring cpus and mems for processes using
5d2ee9
cgroup v2 CPUSET controller.  This allows users to limit which cpus
5d2ee9
and memory NUMA nodes can be used by processes to better utilize
5d2ee9
system resources.
5d2ee9
5d2ee9
The cgroup v2 interfaces to control it are cpuset.cpus and cpuset.mems
5d2ee9
where the requested configuration is written.  However, it doesn't mean
5d2ee9
that the requested configuration will be actually used as parent cgroup
5d2ee9
may limit the cpus or mems as well.  In order to reflect the real
5d2ee9
configuration cgroup v2 provides read-only files cpuset.cpus.effective
5d2ee9
and cpuset.mems.effective which are exported to users as well.
5d2ee9
5d2ee9
(cherry picked from commit 047f5d63d7a1ab75073f8485e2f9b550d25b0772)
5d2ee9
5d2ee9
Related: #1724617
5d2ee9
---
5d2ee9
 doc/TRANSIENT-SETTINGS.md             |  2 +
5d2ee9
 man/systemd.resource-control.xml      | 30 +++++++++++++
5d2ee9
 src/basic/cgroup-util.c               |  1 +
5d2ee9
 src/basic/cgroup-util.h               |  2 +
5d2ee9
 src/core/cgroup.c                     | 63 +++++++++++++++++++++++++++
5d2ee9
 src/core/cgroup.h                     |  5 +++
5d2ee9
 src/core/dbus-cgroup.c                | 59 +++++++++++++++++++++++++
5d2ee9
 src/core/dbus-unit.c                  | 48 ++++++++++++++++++++
5d2ee9
 src/core/load-fragment-gperf.gperf.m4 |  2 +
5d2ee9
 src/core/load-fragment.c              | 38 ++++++++++++++++
5d2ee9
 src/core/load-fragment.h              |  2 +
5d2ee9
 src/shared/bus-unit-util.c            | 16 +++++++
5d2ee9
 src/systemctl/systemctl.c             |  2 +-
5d2ee9
 src/test/test-cgroup-mask.c           |  3 +-
5d2ee9
 14 files changed, 271 insertions(+), 2 deletions(-)
5d2ee9
5d2ee9
diff --git a/doc/TRANSIENT-SETTINGS.md b/doc/TRANSIENT-SETTINGS.md
5d2ee9
index c2b5c0dcce..0b2ad66dcb 100644
5d2ee9
--- a/doc/TRANSIENT-SETTINGS.md
5d2ee9
+++ b/doc/TRANSIENT-SETTINGS.md
5d2ee9
@@ -218,6 +218,8 @@ All cgroup/resource control settings are available for transient units
5d2ee9
 ✓ CPUShares=
5d2ee9
 ✓ StartupCPUShares=
5d2ee9
 ✓ CPUQuota=
5d2ee9
+✓ AllowedCPUs=
5d2ee9
+✓ AllowedMemoryNodes=
5d2ee9
 ✓ MemoryAccounting=
5d2ee9
 ✓ MemoryLow=
5d2ee9
 ✓ MemoryHigh=
5d2ee9
diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml
5d2ee9
index 370c110592..4329742e94 100644
5d2ee9
--- a/man/systemd.resource-control.xml
5d2ee9
+++ b/man/systemd.resource-control.xml
5d2ee9
@@ -201,6 +201,36 @@
5d2ee9
         </listitem>
5d2ee9
       </varlistentry>
5d2ee9
 
5d2ee9
+      <varlistentry>
5d2ee9
+        <term><varname>AllowedCPUs=</varname></term>
5d2ee9
+
5d2ee9
+        <listitem>
5d2ee9
+          <para>Restrict processes to be executed on specific CPUs. Takes a list of CPU indices or ranges separated by either
5d2ee9
+          whitespace or commas. CPU ranges are specified by the lower and upper CPU indices separated by a dash.</para>
5d2ee9
+
5d2ee9
+          <para>Setting <varname>AllowedCPUs=</varname> doesn't guarantee that all of the CPUs will be used by the processes
5d2ee9
+          as it may be limited by parent units. The effective configuration is reported as <varname>EffectiveCPUs=</varname>.</para>
5d2ee9
+
5d2ee9
+          <para>This setting is supported only with the unified control group hierarchy.</para>
5d2ee9
+        </listitem>
5d2ee9
+      </varlistentry>
5d2ee9
+
5d2ee9
+      <varlistentry>
5d2ee9
+        <term><varname>AllowedMemoryNodes=</varname></term>
5d2ee9
+
5d2ee9
+        <listitem>
5d2ee9
+          <para>Restrict processes to be executed on specific memory NUMA nodes. Takes a list of memory NUMA nodes indices
5d2ee9
+          or ranges separated by either whitespace or commas. Memory NUMA nodes ranges are specified by the lower and upper
5d2ee9
+          CPU indices separated by a dash.</para>
5d2ee9
+
5d2ee9
+          <para>Setting <varname>AllowedMemoryNodes=</varname> doesn't guarantee that all of the memory NUMA nodes will
5d2ee9
+          be used by the processes as it may be limited by parent units. The effective configuration is reported as
5d2ee9
+          <varname>EffectiveMemoryNodes=</varname>.</para>
5d2ee9
+
5d2ee9
+          <para>This setting is supported only with the unified control group hierarchy.</para>
5d2ee9
+        </listitem>
5d2ee9
+      </varlistentry>
5d2ee9
+
5d2ee9
       <varlistentry>
5d2ee9
         <term><varname>MemoryAccounting=</varname></term>
5d2ee9
 
5d2ee9
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
5d2ee9
index 038ece4b06..6f47c3aacb 100644
5d2ee9
--- a/src/basic/cgroup-util.c
5d2ee9
+++ b/src/basic/cgroup-util.c
5d2ee9
@@ -2763,6 +2763,7 @@ bool fd_is_cgroup_fs(int fd) {
5d2ee9
 static const char *cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = {
5d2ee9
         [CGROUP_CONTROLLER_CPU] = "cpu",
5d2ee9
         [CGROUP_CONTROLLER_CPUACCT] = "cpuacct",
5d2ee9
+        [CGROUP_CONTROLLER_CPUSET] = "cpuset",
5d2ee9
         [CGROUP_CONTROLLER_IO] = "io",
5d2ee9
         [CGROUP_CONTROLLER_BLKIO] = "blkio",
5d2ee9
         [CGROUP_CONTROLLER_MEMORY] = "memory",
5d2ee9
diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h
5d2ee9
index 26e3ae0404..b414600dca 100644
5d2ee9
--- a/src/basic/cgroup-util.h
5d2ee9
+++ b/src/basic/cgroup-util.h
5d2ee9
@@ -21,6 +21,7 @@
5d2ee9
 typedef enum CGroupController {
5d2ee9
         CGROUP_CONTROLLER_CPU,
5d2ee9
         CGROUP_CONTROLLER_CPUACCT,    /* v1 only */
5d2ee9
+        CGROUP_CONTROLLER_CPUSET,     /* v2 only */
5d2ee9
         CGROUP_CONTROLLER_IO,         /* v2 only */
5d2ee9
         CGROUP_CONTROLLER_BLKIO,      /* v1 only */
5d2ee9
         CGROUP_CONTROLLER_MEMORY,
5d2ee9
@@ -36,6 +37,7 @@ typedef enum CGroupController {
5d2ee9
 typedef enum CGroupMask {
5d2ee9
         CGROUP_MASK_CPU = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPU),
5d2ee9
         CGROUP_MASK_CPUACCT = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUACCT),
5d2ee9
+        CGROUP_MASK_CPUSET = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET),
5d2ee9
         CGROUP_MASK_IO = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_IO),
5d2ee9
         CGROUP_MASK_BLKIO = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BLKIO),
5d2ee9
         CGROUP_MASK_MEMORY = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_MEMORY),
5d2ee9
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
5d2ee9
index 76eafdc082..664d269483 100644
5d2ee9
--- a/src/core/cgroup.c
5d2ee9
+++ b/src/core/cgroup.c
5d2ee9
@@ -161,9 +161,14 @@ void cgroup_context_done(CGroupContext *c) {
5d2ee9
 
5d2ee9
         c->ip_address_allow = ip_address_access_free_all(c->ip_address_allow);
5d2ee9
         c->ip_address_deny = ip_address_access_free_all(c->ip_address_deny);
5d2ee9
+
5d2ee9
+        cpu_set_reset(&c->cpuset_cpus);
5d2ee9
+        cpu_set_reset(&c->cpuset_mems);
5d2ee9
 }
5d2ee9
 
5d2ee9
 void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
5d2ee9
+        _cleanup_free_ char *cpuset_cpus = NULL;
5d2ee9
+        _cleanup_free_ char *cpuset_mems = NULL;
5d2ee9
         CGroupIODeviceLimit *il;
5d2ee9
         CGroupIODeviceWeight *iw;
5d2ee9
         CGroupBlockIODeviceBandwidth *b;
5d2ee9
@@ -177,6 +182,9 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
5d2ee9
 
5d2ee9
         prefix = strempty(prefix);
5d2ee9
 
5d2ee9
+        cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
5d2ee9
+        cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
5d2ee9
+
5d2ee9
         fprintf(f,
5d2ee9
                 "%sCPUAccounting=%s\n"
5d2ee9
                 "%sIOAccounting=%s\n"
5d2ee9
@@ -189,6 +197,8 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
5d2ee9
                 "%sCPUShares=%" PRIu64 "\n"
5d2ee9
                 "%sStartupCPUShares=%" PRIu64 "\n"
5d2ee9
                 "%sCPUQuotaPerSecSec=%s\n"
5d2ee9
+                "%sAllowedCPUs=%s\n"
5d2ee9
+                "%sAllowedMemoryNodes=%s\n"
5d2ee9
                 "%sIOWeight=%" PRIu64 "\n"
5d2ee9
                 "%sStartupIOWeight=%" PRIu64 "\n"
5d2ee9
                 "%sBlockIOWeight=%" PRIu64 "\n"
5d2ee9
@@ -212,6 +222,8 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
5d2ee9
                 prefix, c->cpu_shares,
5d2ee9
                 prefix, c->startup_cpu_shares,
5d2ee9
                 prefix, format_timespan(u, sizeof(u), c->cpu_quota_per_sec_usec, 1),
5d2ee9
+                prefix, cpuset_cpus,
5d2ee9
+                prefix, cpuset_mems,
5d2ee9
                 prefix, c->io_weight,
5d2ee9
                 prefix, c->startup_io_weight,
5d2ee9
                 prefix, c->blockio_weight,
5d2ee9
@@ -541,6 +553,21 @@ static uint64_t cgroup_cpu_weight_to_shares(uint64_t weight) {
5d2ee9
                      CGROUP_CPU_SHARES_MIN, CGROUP_CPU_SHARES_MAX);
5d2ee9
 }
5d2ee9
 
5d2ee9
+static void cgroup_apply_unified_cpuset(Unit *u, CPUSet cpus, const char *name) {
5d2ee9
+        _cleanup_free_ char *buf = NULL;
5d2ee9
+        int r;
5d2ee9
+
5d2ee9
+        buf = cpu_set_to_range_string(&cpus);
5d2ee9
+        if (!buf)
5d2ee9
+            return;
5d2ee9
+
5d2ee9
+        r = cg_set_attribute("cpuset", u->cgroup_path, name, buf);
5d2ee9
+        if (r < 0)
5d2ee9
+                log_unit_full(u, IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r,
5d2ee9
+                              "Failed to set %s: %m", name);
5d2ee9
+
5d2ee9
+}
5d2ee9
+
5d2ee9
 static bool cgroup_context_has_io_config(CGroupContext *c) {
5d2ee9
         return c->io_accounting ||
5d2ee9
                 c->io_weight != CGROUP_WEIGHT_INVALID ||
5d2ee9
@@ -766,6 +793,11 @@ static void cgroup_context_apply(
5d2ee9
                 }
5d2ee9
         }
5d2ee9
 
5d2ee9
+        if ((apply_mask & CGROUP_MASK_CPUSET) && !is_root) {
5d2ee9
+                cgroup_apply_unified_cpuset(u, c->cpuset_cpus, "cpuset.cpus");
5d2ee9
+                cgroup_apply_unified_cpuset(u, c->cpuset_mems, "cpuset.mems");
5d2ee9
+        }
5d2ee9
+
5d2ee9
         if (apply_mask & CGROUP_MASK_IO) {
5d2ee9
                 bool has_io = cgroup_context_has_io_config(c);
5d2ee9
                 bool has_blockio = cgroup_context_has_blockio_config(c);
5d2ee9
@@ -1068,6 +1100,9 @@ CGroupMask cgroup_context_get_mask(CGroupContext *c) {
5d2ee9
             c->cpu_quota_per_sec_usec != USEC_INFINITY)
5d2ee9
                 mask |= CGROUP_MASK_CPUACCT | CGROUP_MASK_CPU;
5d2ee9
 
5d2ee9
+        if (c->cpuset_cpus.set || c->cpuset_mems.set)
5d2ee9
+                mask |= CGROUP_MASK_CPUSET;
5d2ee9
+
5d2ee9
         if (cgroup_context_has_io_config(c) || cgroup_context_has_blockio_config(c))
5d2ee9
                 mask |= CGROUP_MASK_IO | CGROUP_MASK_BLKIO;
5d2ee9
 
5d2ee9
@@ -2697,4 +2732,32 @@ static const char* const cgroup_device_policy_table[_CGROUP_DEVICE_POLICY_MAX] =
5d2ee9
         [CGROUP_STRICT] = "strict",
5d2ee9
 };
5d2ee9
 
5d2ee9
+int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) {
5d2ee9
+        _cleanup_free_ char *v = NULL;
5d2ee9
+        int r;
5d2ee9
+
5d2ee9
+        assert(u);
5d2ee9
+        assert(cpus);
5d2ee9
+
5d2ee9
+        if (!u->cgroup_path)
5d2ee9
+                return -ENODATA;
5d2ee9
+
5d2ee9
+        if ((u->cgroup_realized_mask & CGROUP_MASK_CPUSET) == 0)
5d2ee9
+                return -ENODATA;
5d2ee9
+
5d2ee9
+        r = cg_all_unified();
5d2ee9
+        if (r < 0)
5d2ee9
+                return r;
5d2ee9
+        if (r == 0)
5d2ee9
+                return -ENODATA;
5d2ee9
+        if (r > 0)
5d2ee9
+                r = cg_get_attribute("cpuset", u->cgroup_path, name, &v);
5d2ee9
+        if (r == -ENOENT)
5d2ee9
+                return -ENODATA;
5d2ee9
+        if (r < 0)
5d2ee9
+                return r;
5d2ee9
+
5d2ee9
+        return parse_cpu_set_full(v, cpus, false, NULL, NULL, 0, NULL);
5d2ee9
+}
5d2ee9
+
5d2ee9
 DEFINE_STRING_TABLE_LOOKUP(cgroup_device_policy, CGroupDevicePolicy);
5d2ee9
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
5d2ee9
index 2d2ff6fc3c..da10575394 100644
5d2ee9
--- a/src/core/cgroup.h
5d2ee9
+++ b/src/core/cgroup.h
5d2ee9
@@ -4,6 +4,7 @@
5d2ee9
 #include <stdbool.h>
5d2ee9
 
5d2ee9
 #include "cgroup-util.h"
5d2ee9
+#include "cpu-set-util.h"
5d2ee9
 #include "ip-address-access.h"
5d2ee9
 #include "list.h"
5d2ee9
 #include "time-util.h"
5d2ee9
@@ -77,6 +78,9 @@ struct CGroupContext {
5d2ee9
         uint64_t startup_cpu_weight;
5d2ee9
         usec_t cpu_quota_per_sec_usec;
5d2ee9
 
5d2ee9
+        CPUSet cpuset_cpus;
5d2ee9
+        CPUSet cpuset_mems;
5d2ee9
+
5d2ee9
         uint64_t io_weight;
5d2ee9
         uint64_t startup_io_weight;
5d2ee9
         LIST_HEAD(CGroupIODeviceWeight, io_device_weights);
5d2ee9
@@ -205,3 +209,4 @@ const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_;
5d2ee9
 CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_;
5d2ee9
 
5d2ee9
 bool unit_cgroup_delegate(Unit *u);
5d2ee9
+int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name);
5d2ee9
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
5d2ee9
index 540bc77aed..30d4e83932 100644
5d2ee9
--- a/src/core/dbus-cgroup.c
5d2ee9
+++ b/src/core/dbus-cgroup.c
5d2ee9
@@ -53,6 +53,27 @@ static int property_get_delegate_controllers(
5d2ee9
         return sd_bus_message_close_container(reply);
5d2ee9
 }
5d2ee9
 
5d2ee9
+static int property_get_cpuset(
5d2ee9
+                sd_bus *bus,
5d2ee9
+                const char *path,
5d2ee9
+                const char *interface,
5d2ee9
+                const char *property,
5d2ee9
+                sd_bus_message *reply,
5d2ee9
+                void *userdata,
5d2ee9
+                sd_bus_error *error) {
5d2ee9
+
5d2ee9
+        CPUSet *cpus = userdata;
5d2ee9
+        _cleanup_free_ uint8_t *array = NULL;
5d2ee9
+        size_t allocated;
5d2ee9
+
5d2ee9
+        assert(bus);
5d2ee9
+        assert(reply);
5d2ee9
+        assert(cpus);
5d2ee9
+
5d2ee9
+        (void) cpu_set_to_dbus(cpus, &array, &allocated);
5d2ee9
+        return sd_bus_message_append_array(reply, 'y', array, allocated);
5d2ee9
+}
5d2ee9
+
5d2ee9
 static int property_get_io_device_weight(
5d2ee9
                 sd_bus *bus,
5d2ee9
                 const char *path,
5d2ee9
@@ -283,6 +304,8 @@ const sd_bus_vtable bus_cgroup_vtable[] = {
5d2ee9
         SD_BUS_PROPERTY("CPUShares", "t", NULL, offsetof(CGroupContext, cpu_shares), 0),
5d2ee9
         SD_BUS_PROPERTY("StartupCPUShares", "t", NULL, offsetof(CGroupContext, startup_cpu_shares), 0),
5d2ee9
         SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0),
5d2ee9
+        SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_cpus), 0),
5d2ee9
+        SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_mems), 0),
5d2ee9
         SD_BUS_PROPERTY("IOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, io_accounting), 0),
5d2ee9
         SD_BUS_PROPERTY("IOWeight", "t", NULL, offsetof(CGroupContext, io_weight), 0),
5d2ee9
         SD_BUS_PROPERTY("StartupIOWeight", "t", NULL, offsetof(CGroupContext, startup_io_weight), 0),
5d2ee9
@@ -671,6 +694,42 @@ int bus_cgroup_set_property(
5d2ee9
 
5d2ee9
                 return 1;
5d2ee9
 
5d2ee9
+        } else if (STR_IN_SET(name, "AllowedCPUs", "AllowedMemoryNodes")) {
5d2ee9
+                const void *a;
5d2ee9
+                size_t n;
5d2ee9
+                _cleanup_(cpu_set_reset) CPUSet new_set = {};
5d2ee9
+
5d2ee9
+                r = sd_bus_message_read_array(message, 'y', &a, &n);
5d2ee9
+                if (r < 0)
5d2ee9
+                        return r;
5d2ee9
+
5d2ee9
+                r = cpu_set_from_dbus(a, n, &new_set);
5d2ee9
+                if (r < 0)
5d2ee9
+                        return r;
5d2ee9
+
5d2ee9
+                if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
5d2ee9
+                        _cleanup_free_ char *setstr = NULL;
5d2ee9
+                        _cleanup_free_ char *data = NULL;
5d2ee9
+                        CPUSet *set;
5d2ee9
+
5d2ee9
+                        setstr = cpu_set_to_range_string(&new_set);
5d2ee9
+
5d2ee9
+                        if (streq(name, "AllowedCPUs"))
5d2ee9
+                                set = &c->cpuset_cpus;
5d2ee9
+                        else
5d2ee9
+                                set = &c->cpuset_mems;
5d2ee9
+
5d2ee9
+                        if (asprintf(&data, "%s=%s", name, setstr) < 0)
5d2ee9
+                                return -ENOMEM;
5d2ee9
+
5d2ee9
+                        cpu_set_reset(set);
5d2ee9
+                        cpu_set_add_all(set, &new_set);
5d2ee9
+                        unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET);
5d2ee9
+                        unit_write_setting(u, flags, name, data);
5d2ee9
+                }
5d2ee9
+
5d2ee9
+                return 1;
5d2ee9
+
5d2ee9
         } else if ((iol_type = cgroup_io_limit_type_from_string(name)) >= 0) {
5d2ee9
                 const char *path;
5d2ee9
                 unsigned n = 0;
5d2ee9
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
5d2ee9
index c5bca10979..aa15e47754 100644
5d2ee9
--- a/src/core/dbus-unit.c
5d2ee9
+++ b/src/core/dbus-unit.c
5d2ee9
@@ -752,6 +752,52 @@ static int property_get_cpu_usage(
5d2ee9
         return sd_bus_message_append(reply, "t", ns);
5d2ee9
 }
5d2ee9
 
5d2ee9
+static int property_get_cpuset_cpus(
5d2ee9
+                sd_bus *bus,
5d2ee9
+                const char *path,
5d2ee9
+                const char *interface,
5d2ee9
+                const char *property,
5d2ee9
+                sd_bus_message *reply,
5d2ee9
+                void *userdata,
5d2ee9
+                sd_bus_error *error) {
5d2ee9
+
5d2ee9
+        Unit *u = userdata;
5d2ee9
+        _cleanup_(cpu_set_reset) CPUSet cpus = {};
5d2ee9
+        _cleanup_free_ uint8_t *array = NULL;
5d2ee9
+        size_t allocated;
5d2ee9
+
5d2ee9
+        assert(bus);
5d2ee9
+        assert(reply);
5d2ee9
+        assert(u);
5d2ee9
+
5d2ee9
+        (void) unit_get_cpuset(u, &cpus, "cpuset.cpus.effective");
5d2ee9
+        (void) cpu_set_to_dbus(&cpus, &array, &allocated);
5d2ee9
+        return sd_bus_message_append_array(reply, 'y', array, allocated);
5d2ee9
+}
5d2ee9
+
5d2ee9
+static int property_get_cpuset_mems(
5d2ee9
+                sd_bus *bus,
5d2ee9
+                const char *path,
5d2ee9
+                const char *interface,
5d2ee9
+                const char *property,
5d2ee9
+                sd_bus_message *reply,
5d2ee9
+                void *userdata,
5d2ee9
+                sd_bus_error *error) {
5d2ee9
+
5d2ee9
+        Unit *u = userdata;
5d2ee9
+        _cleanup_(cpu_set_reset) CPUSet mems = {};
5d2ee9
+        _cleanup_free_ uint8_t *array = NULL;
5d2ee9
+        size_t allocated;
5d2ee9
+
5d2ee9
+        assert(bus);
5d2ee9
+        assert(reply);
5d2ee9
+        assert(u);
5d2ee9
+
5d2ee9
+        (void) unit_get_cpuset(u, &mems, "cpuset.mems.effective");
5d2ee9
+        (void) cpu_set_to_dbus(&mems, &array, &allocated);
5d2ee9
+        return sd_bus_message_append_array(reply, 'y', array, allocated);
5d2ee9
+}
5d2ee9
+
5d2ee9
 static int property_get_cgroup(
5d2ee9
                 sd_bus *bus,
5d2ee9
                 const char *path,
5d2ee9
@@ -1074,6 +1120,8 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
5d2ee9
         SD_BUS_PROPERTY("ControlGroup", "s", property_get_cgroup, 0, 0),
5d2ee9
         SD_BUS_PROPERTY("MemoryCurrent", "t", property_get_current_memory, 0, 0),
5d2ee9
         SD_BUS_PROPERTY("CPUUsageNSec", "t", property_get_cpu_usage, 0, 0),
5d2ee9
+        SD_BUS_PROPERTY("EffectiveCPUs", "ay", property_get_cpuset_cpus, 0, 0),
5d2ee9
+        SD_BUS_PROPERTY("EffectiveMemoryNodes", "ay", property_get_cpuset_mems, 0, 0),
5d2ee9
         SD_BUS_PROPERTY("TasksCurrent", "t", property_get_current_tasks, 0, 0),
5d2ee9
         SD_BUS_PROPERTY("IPIngressBytes", "t", property_get_ip_counter, 0, 0),
5d2ee9
         SD_BUS_PROPERTY("IPIngressPackets", "t", property_get_ip_counter, 0, 0),
5d2ee9
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
5d2ee9
index 49e938d0ce..ebb44df487 100644
5d2ee9
--- a/src/core/load-fragment-gperf.gperf.m4
5d2ee9
+++ b/src/core/load-fragment-gperf.gperf.m4
5d2ee9
@@ -167,6 +167,8 @@ $1.StartupCPUWeight,             config_parse_cg_weight,             0,
5d2ee9
 $1.CPUShares,                    config_parse_cpu_shares,            0,                             offsetof($1, cgroup_context.cpu_shares)
5d2ee9
 $1.StartupCPUShares,             config_parse_cpu_shares,            0,                             offsetof($1, cgroup_context.startup_cpu_shares)
5d2ee9
 $1.CPUQuota,                     config_parse_cpu_quota,             0,                             offsetof($1, cgroup_context)
5d2ee9
+$1.CPUSetCpus,                   config_parse_cpuset_cpus,           0,                             offsetof($1, cgroup_context)
5d2ee9
+$1.CPUSetMems,                   config_parse_cpuset_mems,           0,                             offsetof($1, cgroup_context)
5d2ee9
 $1.MemoryAccounting,             config_parse_bool,                  0,                             offsetof($1, cgroup_context.memory_accounting)
5d2ee9
 $1.MemoryLow,                    config_parse_memory_limit,          0,                             offsetof($1, cgroup_context)
5d2ee9
 $1.MemoryHigh,                   config_parse_memory_limit,          0,                             offsetof($1, cgroup_context)
5d2ee9
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
5d2ee9
index 35dd595098..6debf82401 100644
5d2ee9
--- a/src/core/load-fragment.c
5d2ee9
+++ b/src/core/load-fragment.c
5d2ee9
@@ -3011,6 +3011,44 @@ int config_parse_cpu_quota(
5d2ee9
         return 0;
5d2ee9
 }
5d2ee9
 
5d2ee9
+int config_parse_cpuset_cpus(
5d2ee9
+                const char *unit,
5d2ee9
+                const char *filename,
5d2ee9
+                unsigned line,
5d2ee9
+                const char *section,
5d2ee9
+                unsigned section_line,
5d2ee9
+                const char *lvalue,
5d2ee9
+                int ltype,
5d2ee9
+                const char *rvalue,
5d2ee9
+                void *data,
5d2ee9
+                void *userdata) {
5d2ee9
+
5d2ee9
+        CGroupContext *c = data;
5d2ee9
+
5d2ee9
+        (void) parse_cpu_set_extend(rvalue, &c->cpuset_cpus, true, unit, filename, line, lvalue);
5d2ee9
+
5d2ee9
+        return 0;
5d2ee9
+}
5d2ee9
+
5d2ee9
+int config_parse_cpuset_mems(
5d2ee9
+                const char *unit,
5d2ee9
+                const char *filename,
5d2ee9
+                unsigned line,
5d2ee9
+                const char *section,
5d2ee9
+                unsigned section_line,
5d2ee9
+                const char *lvalue,
5d2ee9
+                int ltype,
5d2ee9
+                const char *rvalue,
5d2ee9
+                void *data,
5d2ee9
+                void *userdata) {
5d2ee9
+
5d2ee9
+        CGroupContext *c = data;
5d2ee9
+
5d2ee9
+        (void) parse_cpu_set_extend(rvalue, &c->cpuset_mems, true, unit, filename, line, lvalue);
5d2ee9
+
5d2ee9
+        return 0;
5d2ee9
+}
5d2ee9
+
5d2ee9
 int config_parse_memory_limit(
5d2ee9
                 const char *unit,
5d2ee9
                 const char *filename,
5d2ee9
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
5d2ee9
index f2ca1b8ee7..6612e1fb32 100644
5d2ee9
--- a/src/core/load-fragment.h
5d2ee9
+++ b/src/core/load-fragment.h
5d2ee9
@@ -86,6 +86,8 @@ CONFIG_PARSER_PROTOTYPE(config_parse_set_status);
5d2ee9
 CONFIG_PARSER_PROTOTYPE(config_parse_namespace_path_strv);
5d2ee9
 CONFIG_PARSER_PROTOTYPE(config_parse_temporary_filesystems);
5d2ee9
 CONFIG_PARSER_PROTOTYPE(config_parse_cpu_quota);
5d2ee9
+CONFIG_PARSER_PROTOTYPE(config_parse_cpuset_cpus);
5d2ee9
+CONFIG_PARSER_PROTOTYPE(config_parse_cpuset_mems);
5d2ee9
 CONFIG_PARSER_PROTOTYPE(config_parse_protect_home);
5d2ee9
 CONFIG_PARSER_PROTOTYPE(config_parse_protect_system);
5d2ee9
 CONFIG_PARSER_PROTOTYPE(config_parse_bus_name);
5d2ee9
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
5d2ee9
index 3c42e97b7a..8f3b463c6b 100644
5d2ee9
--- a/src/shared/bus-unit-util.c
5d2ee9
+++ b/src/shared/bus-unit-util.c
5d2ee9
@@ -396,6 +396,22 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
5d2ee9
 
5d2ee9
                 return bus_append_cg_cpu_shares_parse(m, field, eq);
5d2ee9
 
5d2ee9
+        if (STR_IN_SET(field, "AllowedCPUs", "AllowedMemoryNodes")) {
5d2ee9
+                _cleanup_(cpu_set_reset) CPUSet cpuset = {};
5d2ee9
+                _cleanup_free_ uint8_t *array = NULL;
5d2ee9
+                size_t allocated;
5d2ee9
+
5d2ee9
+                r = parse_cpu_set(eq, &cpuset);
5d2ee9
+                if (r < 0)
5d2ee9
+                        return log_error_errno(r, "Failed to parse %s value: %s", field, eq);
5d2ee9
+
5d2ee9
+                r = cpu_set_to_dbus(&cpuset, &array, &allocated);
5d2ee9
+                if (r < 0)
5d2ee9
+                        return log_error_errno(r, "Failed to serialize CPUSet: %m");
5d2ee9
+
5d2ee9
+                return bus_append_byte_array(m, field, array, allocated);
5d2ee9
+        }
5d2ee9
+
5d2ee9
         if (STR_IN_SET(field, "BlockIOWeight", "StartupBlockIOWeight"))
5d2ee9
 
5d2ee9
                 return bus_append_cg_blkio_weight_parse(m, field, eq);
5d2ee9
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
5d2ee9
index 7274921e6d..a3074bc5e3 100644
5d2ee9
--- a/src/systemctl/systemctl.c
5d2ee9
+++ b/src/systemctl/systemctl.c
5d2ee9
@@ -4892,7 +4892,7 @@ static int print_property(const char *name, sd_bus_message *m, bool value, bool
5d2ee9
                         print_prop(name, "%s", h);
5d2ee9
 
5d2ee9
                         return 1;
5d2ee9
-                } else if (contents[0] == SD_BUS_TYPE_BYTE && STR_IN_SET(name, "CPUAffinity", "NUMAMask")) {
5d2ee9
+                } else if (contents[0] == SD_BUS_TYPE_BYTE && STR_IN_SET(name, "CPUAffinity", "NUMAMask", "AllowedCPUs", "AllowedMemoryNodes", "EffectiveCPUs", "EffectiveMemoryNodes")) {
5d2ee9
                         _cleanup_free_ char *affinity = NULL;
5d2ee9
                         _cleanup_(cpu_set_reset) CPUSet set = {};
5d2ee9
                         const void *a;
5d2ee9
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
5d2ee9
index d65959edf1..93c3f5d856 100644
5d2ee9
--- a/src/test/test-cgroup-mask.c
5d2ee9
+++ b/src/test/test-cgroup-mask.c
5d2ee9
@@ -104,9 +104,10 @@ static void test_cg_mask_to_string_one(CGroupMask mask, const char *t) {
5d2ee9
 
5d2ee9
 static void test_cg_mask_to_string(void) {
5d2ee9
         test_cg_mask_to_string_one(0, NULL);
5d2ee9
-        test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct io blkio memory devices pids");
5d2ee9
+        test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset io blkio memory devices pids");
5d2ee9
         test_cg_mask_to_string_one(CGROUP_MASK_CPU, "cpu");
5d2ee9
         test_cg_mask_to_string_one(CGROUP_MASK_CPUACCT, "cpuacct");
5d2ee9
+        test_cg_mask_to_string_one(CGROUP_MASK_CPUSET, "cpuset");
5d2ee9
         test_cg_mask_to_string_one(CGROUP_MASK_IO, "io");
5d2ee9
         test_cg_mask_to_string_one(CGROUP_MASK_BLKIO, "blkio");
5d2ee9
         test_cg_mask_to_string_one(CGROUP_MASK_MEMORY, "memory");