Merge pull request #34671 from yuwata/memory

tree-wide: several memory accounting cleanups
This commit is contained in:
Lennart Poettering
2024-10-09 10:24:10 +02:00
committed by GitHub
4 changed files with 32 additions and 26 deletions
+5 -1
View File
@@ -5309,7 +5309,11 @@ static int service_can_live_mount(const Unit *u, sd_bus_error *error) {
/* Ensure that the unit runs in a private mount namespace */
if (!exec_needs_mount_namespace(unit_get_exec_context(u), /* params= */ NULL, unit_get_exec_runtime(u))) {
log_unit_debug(u, "Unit not running in private mount namespace, cannot live mount");
/* This is also called in property_get_can_live_mount(). Suppress the debugging log when called in it. */
if (error)
log_unit_debug(u, "Unit not running in private mount namespace, cannot live mount");
return sd_bus_error_setf(
error,
SD_BUS_ERROR_INVALID_ARGS,
+7 -5
View File
@@ -340,17 +340,12 @@ static int acquire_managed_oom_connect(Manager *m) {
static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void *userdata) {
Manager *m = ASSERT_PTR(userdata);
usec_t usec_now;
int r;
assert(s);
assert(!hashmap_isempty(m->monitored_swap_cgroup_contexts));
/* Reset timer */
r = sd_event_now(sd_event_source_get_event(s), CLOCK_MONOTONIC, &usec_now);
if (r < 0)
return log_error_errno(r, "Failed to reset event timer: %m");
r = sd_event_source_set_time_relative(s, SWAP_INTERVAL_USEC);
if (r < 0)
return log_error_errno(r, "Failed to set relative time for timer: %m");
@@ -804,10 +799,17 @@ int manager_get_dump_string(Manager *m, char **ret) {
_cleanup_(memstream_done) MemStream ms = {};
OomdCGroupContext *c;
FILE *f;
int r;
assert(m);
assert(ret);
/* Always reread memory/swap info here. Otherwise it may be outdated if swap monitoring is off.
* Let's make sure to always report up-to-date data. */
r = oomd_system_context_acquire("/proc/meminfo", &m->system_context);
if (r < 0)
log_debug_errno(r, "Failed to acquire system context, ignoring: %m");
f = memstream_init(&ms);
if (!f)
return -ENOMEM;
+3 -3
View File
@@ -607,7 +607,7 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE
fprintf(f,
"%sPath: %s\n"
"%s\tMemory Pressure Limit: %lu.%02lu%%\n"
"%s\tPressure: Avg10: %lu.%02lu Avg60: %lu.%02lu Avg300: %lu.%02lu Total: %s\n"
"%s\tPressure: Avg10: %lu.%02lu, Avg60: %lu.%02lu, Avg300: %lu.%02lu, Total: %s\n"
"%s\tCurrent Memory Usage: %s\n",
strempty(prefix), ctx->path,
strempty(prefix), LOADAVG_INT_SIDE(ctx->mem_pressure_limit), LOADAVG_DECIMAL_SIDE(ctx->mem_pressure_limit),
@@ -635,8 +635,8 @@ void oomd_dump_system_context(const OomdSystemContext *ctx, FILE *f, const char
assert(f);
fprintf(f,
"%sMemory: Used: %s Total: %s\n"
"%sSwap: Used: %s Total: %s\n",
"%sMemory: Used: %s, Total: %s\n"
"%sSwap: Used: %s, Total: %s\n",
strempty(prefix),
FORMAT_BYTES(ctx->mem_used),
FORMAT_BYTES(ctx->mem_total),
+17 -17
View File
@@ -758,68 +758,68 @@ static void print_status_info(
printf(" (");
if (i->memory_min > 0) {
printf("%smin: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_min));
prefix = " ";
prefix = ", ";
}
if (i->memory_low > 0) {
printf("%slow: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_low));
prefix = " ";
prefix = ", ";
}
if (i->startup_memory_low > 0) {
printf("%slow (startup): %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->startup_memory_low));
prefix = " ";
prefix = ", ";
}
if (i->memory_high != CGROUP_LIMIT_MAX) {
printf("%shigh: %s", prefix, FORMAT_BYTES(i->memory_high));
prefix = " ";
prefix = ", ";
}
if (i->startup_memory_high != CGROUP_LIMIT_MAX) {
printf("%shigh (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_high));
prefix = " ";
prefix = ", ";
}
if (i->memory_max != CGROUP_LIMIT_MAX) {
printf("%smax: %s", prefix, FORMAT_BYTES(i->memory_max));
prefix = " ";
prefix = ", ";
}
if (i->startup_memory_max != CGROUP_LIMIT_MAX) {
printf("%smax (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_max));
prefix = " ";
prefix = ", ";
}
if (i->memory_swap_max != CGROUP_LIMIT_MAX) {
printf("%sswap max: %s", prefix, FORMAT_BYTES(i->memory_swap_max));
prefix = " ";
prefix = ", ";
}
if (i->startup_memory_swap_max != CGROUP_LIMIT_MAX) {
printf("%sswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_swap_max));
prefix = " ";
prefix = ", ";
}
if (i->memory_zswap_max != CGROUP_LIMIT_MAX) {
printf("%szswap max: %s", prefix, FORMAT_BYTES(i->memory_zswap_max));
prefix = " ";
prefix = ", ";
}
if (i->startup_memory_zswap_max != CGROUP_LIMIT_MAX) {
printf("%szswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_zswap_max));
prefix = " ";
prefix = ", ";
}
if (i->memory_limit != CGROUP_LIMIT_MAX) {
printf("%slimit: %s", prefix, FORMAT_BYTES(i->memory_limit));
prefix = " ";
prefix = ", ";
}
if (show_memory_available) {
printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available));
prefix = " ";
prefix = ", ";
}
if (show_memory_peak) {
printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak));
prefix = " ";
prefix = ", ";
}
if (show_memory_swap_peak) {
printf("%sswap: %s swap peak: %s", prefix,
printf("%sswap: %s, swap peak: %s", prefix,
FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak));
prefix = " ";
prefix = ", ";
}
if (show_memory_zswap_current) {
printf("%szswap: %s", prefix, FORMAT_BYTES(i->memory_zswap_current));
prefix = " ";
prefix = ", ";
}
printf(")");
}