diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-05-26 20:16:48 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-06-08 15:05:56 +0200 |
commit | 93ff34e44aa6cfae2b3723ec57862ce54c1721eb (patch) | |
tree | 2d11fcaefbe32142045e71b785649e46e270fe0f /src/core/dbus-unit.c | |
parent | po: Translated using Weblate (Spanish) (diff) | |
download | systemd-93ff34e44aa6cfae2b3723ec57862ce54c1721eb.tar.xz systemd-93ff34e44aa6cfae2b3723ec57862ce54c1721eb.zip |
core: add MemoryAvailable unit property
Try to infer the unused memory that a unit can claim before the
memory.max limit is reached, including any limit set on any parent
slice above the unit itself.
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r-- | src/core/dbus-unit.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 6c04c6e5db..aa10939a04 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1097,6 +1097,30 @@ static int property_get_current_memory( return sd_bus_message_append(reply, "t", sz); } +static int property_get_available_memory( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + uint64_t sz = UINT64_MAX; + Unit *u = userdata; + int r; + + assert(bus); + assert(reply); + assert(u); + + r = unit_get_memory_available(u, &sz); + if (r < 0 && r != -ENODATA) + log_unit_warning_errno(u, r, "Failed to get total available memory from cgroup: %m"); + + return sd_bus_message_append(reply, "t", sz); +} + static int property_get_current_tasks( sd_bus *bus, const char *path, @@ -1541,6 +1565,7 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = { SD_BUS_PROPERTY("Slice", "s", property_get_slice, 0, 0), SD_BUS_PROPERTY("ControlGroup", "s", property_get_cgroup, 0, 0), SD_BUS_PROPERTY("MemoryCurrent", "t", property_get_current_memory, 0, 0), + SD_BUS_PROPERTY("MemoryAvailable", "t", property_get_available_memory, 0, 0), SD_BUS_PROPERTY("CPUUsageNSec", "t", property_get_cpu_usage, 0, 0), SD_BUS_PROPERTY("EffectiveCPUs", "ay", property_get_cpuset_cpus, 0, 0), SD_BUS_PROPERTY("EffectiveMemoryNodes", "ay", property_get_cpuset_mems, 0, 0), |