Merge pull request #29990 from Flowdalic/memory-zswap-current

cgroup: add support for memory.zswap.current
This commit is contained in:
Mike Yuan
2023-11-13 16:40:18 +08:00
committed by GitHub
5 changed files with 93 additions and 16 deletions
+4
View File
@@ -4111,6 +4111,10 @@ 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);
}
int unit_get_memory_zswap_current(Unit *u, uint64_t *ret) {
return unit_get_memory_attr_raw(u, "memory.zswap.current", ret);
}
int unit_get_tasks_current(Unit *u, uint64_t *ret) {
assert(u);
assert(ret);
+1
View File
@@ -356,6 +356,7 @@ 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_zswap_current(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);
int unit_get_cpu_usage(Unit *u, nsec_t *ret);
+24
View File
@@ -1149,6 +1149,29 @@ static int property_get_peak_swap_memory(
return sd_bus_message_append(reply, "t", sz);
}
static int property_get_current_zswap_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.zswap.current attribute: %m");
return sd_bus_message_append(reply, "t", sz);
}
static int property_get_available_memory(
sd_bus *bus,
const char *path,
@@ -1608,6 +1631,7 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
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("MemoryZswapCurrent", "t", property_get_current_zswap_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),
+10 -4
View File
@@ -253,6 +253,7 @@ typedef struct UnitStatusInfo {
uint64_t memory_peak;
uint64_t memory_swap_current;
uint64_t memory_swap_peak;
uint64_t memory_zswap_current;
uint64_t memory_min;
uint64_t memory_low;
uint64_t startup_memory_low;
@@ -707,9 +708,11 @@ static void print_status_info(
/* 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);
bool show_memory_swap = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX),
show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX);
if (i->memory_peak != CGROUP_LIMIT_MAX ||
show_memory_swap ||
show_memory_zswap_current ||
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 ||
@@ -778,11 +781,12 @@ static void print_status_info(
prefix = " ";
}
if (show_memory_swap) {
printf("%sswap: %s", prefix, FORMAT_BYTES(i->memory_swap_current));
printf("%sswap: %s swap peak: %s", prefix,
FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak));
prefix = " ";
}
if (show_memory_swap) {
printf("%sswap peak: %s", prefix, FORMAT_BYTES(i->memory_swap_peak));
if (show_memory_zswap_current) {
printf("%szswap: %s", prefix, FORMAT_BYTES(i->memory_zswap_current));
prefix = " ";
}
printf(")");
@@ -2054,6 +2058,7 @@ static int show_one(
{ "MemoryPeak", "t", NULL, offsetof(UnitStatusInfo, memory_peak) },
{ "MemorySwapCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_swap_current) },
{ "MemorySwapPeak", "t", NULL, offsetof(UnitStatusInfo, memory_swap_peak) },
{ "MemoryZswapCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_zswap_current) },
{ "MemoryAvailable", "t", NULL, offsetof(UnitStatusInfo, memory_available) },
{ "DefaultMemoryMin", "t", NULL, offsetof(UnitStatusInfo, default_memory_min) },
{ "DefaultMemoryLow", "t", NULL, offsetof(UnitStatusInfo, default_memory_low) },
@@ -2113,6 +2118,7 @@ static int show_one(
.memory_peak = CGROUP_LIMIT_MAX,
.memory_swap_current = CGROUP_LIMIT_MAX,
.memory_swap_peak = CGROUP_LIMIT_MAX,
.memory_zswap_current = CGROUP_LIMIT_MAX,
.memory_available = CGROUP_LIMIT_MAX,
.cpu_usage_nsec = UINT64_MAX,
.tasks_current = UINT64_MAX,