cgroup: add support for memory.swap.current
In systemctl-show we only show current swap if ever swapped or non-zero. This reduces the noise on swapless systems, that would otherwise always show a swap value that never has the chance to become non-zero. It further reduces the noise for services that never swapped.
This commit is contained in:
@@ -4047,6 +4047,9 @@ static int unit_get_memory_attr_raw(Unit *u, const char* mem_attribute, uint64_t
|
||||
assert(mem_attribute);
|
||||
assert(ret);
|
||||
|
||||
if (!UNIT_CGROUP_BOOL(u, memory_accounting))
|
||||
return -ENODATA;
|
||||
|
||||
if (!u->cgroup_path)
|
||||
return -ENODATA;
|
||||
|
||||
@@ -4100,6 +4103,10 @@ int unit_get_memory_peak(Unit *u, uint64_t *ret) {
|
||||
return unit_get_memory_attr_cached(u, "memory.peak", &u->memory_peak_last, ret);
|
||||
}
|
||||
|
||||
int unit_get_memory_swap_current(Unit *u, uint64_t *ret) {
|
||||
return unit_get_memory_attr_raw(u, "memory.swap.current", ret);
|
||||
}
|
||||
|
||||
int unit_get_memory_swap_peak(Unit *u, uint64_t *ret) {
|
||||
return unit_get_memory_attr_cached(u, "memory.swap.peak", &u->memory_swap_peak_last, ret);
|
||||
}
|
||||
|
||||
@@ -354,6 +354,7 @@ int unit_synthesize_cgroup_empty_event(Unit *u);
|
||||
|
||||
int unit_get_memory_current(Unit *u, uint64_t *ret);
|
||||
int unit_get_memory_peak(Unit *u, uint64_t *ret);
|
||||
int unit_get_memory_swap_current(Unit *u, uint64_t *ret);
|
||||
int unit_get_memory_swap_peak(Unit *u, uint64_t *ret);
|
||||
int unit_get_memory_available(Unit *u, uint64_t *ret);
|
||||
int unit_get_tasks_current(Unit *u, uint64_t *ret);
|
||||
|
||||
@@ -1103,6 +1103,29 @@ static int property_get_peak_memory(
|
||||
return sd_bus_message_append(reply, "t", sz);
|
||||
}
|
||||
|
||||
static int property_get_current_swap_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 = ASSERT_PTR(userdata);
|
||||
int r;
|
||||
|
||||
assert(bus);
|
||||
assert(reply);
|
||||
|
||||
r = unit_get_memory_swap_current(u, &sz);
|
||||
if (r < 0 && r != -ENODATA)
|
||||
log_unit_warning_errno(u, r, "Failed to get memory.swap.current attribute: %m");
|
||||
|
||||
return sd_bus_message_append(reply, "t", sz);
|
||||
}
|
||||
|
||||
static int property_get_peak_swap_memory(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
@@ -1583,6 +1606,7 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
|
||||
SD_BUS_PROPERTY("ControlGroupId", "t", NULL, offsetof(Unit, cgroup_id), 0),
|
||||
SD_BUS_PROPERTY("MemoryCurrent", "t", property_get_current_memory, 0, 0),
|
||||
SD_BUS_PROPERTY("MemoryPeak", "t", property_get_peak_memory, 0, 0),
|
||||
SD_BUS_PROPERTY("MemorySwapCurrent", "t", property_get_current_swap_memory, 0, 0),
|
||||
SD_BUS_PROPERTY("MemorySwapPeak", "t", property_get_peak_swap_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),
|
||||
|
||||
@@ -251,6 +251,7 @@ typedef struct UnitStatusInfo {
|
||||
/* CGroup */
|
||||
uint64_t memory_current;
|
||||
uint64_t memory_peak;
|
||||
uint64_t memory_swap_current;
|
||||
uint64_t memory_swap_peak;
|
||||
uint64_t memory_min;
|
||||
uint64_t memory_low;
|
||||
@@ -704,9 +705,11 @@ static void print_status_info(
|
||||
if (i->memory_current != UINT64_MAX) {
|
||||
printf(" Memory: %s", FORMAT_BYTES(i->memory_current));
|
||||
|
||||
bool show_memory_swap_peak = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX);
|
||||
/* Only show current swap if it ever was non-zero or is currently non-zero. In both cases
|
||||
memory_swap_peak will be non-zero (and not CGROUP_LIMIT_MAX). */
|
||||
bool show_memory_swap = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX);
|
||||
if (i->memory_peak != CGROUP_LIMIT_MAX ||
|
||||
show_memory_swap_peak ||
|
||||
show_memory_swap ||
|
||||
i->memory_min > 0 ||
|
||||
i->memory_low > 0 || i->startup_memory_low > 0 ||
|
||||
i->memory_high != CGROUP_LIMIT_MAX || i->startup_memory_high != CGROUP_LIMIT_MAX ||
|
||||
@@ -774,7 +777,11 @@ static void print_status_info(
|
||||
printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak));
|
||||
prefix = " ";
|
||||
}
|
||||
if (show_memory_swap_peak) {
|
||||
if (show_memory_swap) {
|
||||
printf("%sswap: %s", prefix, FORMAT_BYTES(i->memory_swap_current));
|
||||
prefix = " ";
|
||||
}
|
||||
if (show_memory_swap) {
|
||||
printf("%sswap peak: %s", prefix, FORMAT_BYTES(i->memory_swap_peak));
|
||||
prefix = " ";
|
||||
}
|
||||
@@ -2045,6 +2052,7 @@ static int show_one(
|
||||
{ "What", "s", NULL, offsetof(UnitStatusInfo, what) },
|
||||
{ "MemoryCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_current) },
|
||||
{ "MemoryPeak", "t", NULL, offsetof(UnitStatusInfo, memory_peak) },
|
||||
{ "MemorySwapCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_swap_current) },
|
||||
{ "MemorySwapPeak", "t", NULL, offsetof(UnitStatusInfo, memory_swap_peak) },
|
||||
{ "MemoryAvailable", "t", NULL, offsetof(UnitStatusInfo, memory_available) },
|
||||
{ "DefaultMemoryMin", "t", NULL, offsetof(UnitStatusInfo, default_memory_min) },
|
||||
@@ -2103,6 +2111,7 @@ static int show_one(
|
||||
.startup_memory_zswap_max = CGROUP_LIMIT_MAX,
|
||||
.memory_limit = CGROUP_LIMIT_MAX,
|
||||
.memory_peak = CGROUP_LIMIT_MAX,
|
||||
.memory_swap_current = CGROUP_LIMIT_MAX,
|
||||
.memory_swap_peak = CGROUP_LIMIT_MAX,
|
||||
.memory_available = CGROUP_LIMIT_MAX,
|
||||
.cpu_usage_nsec = UINT64_MAX,
|
||||
|
||||
Reference in New Issue
Block a user