return 0;
}
- r = oomd_cgroup_kill_mark(m, selected);
+ r = oomd_cgroup_kill_mark(m, selected, "memory-used");
if (r == -ENOMEM)
return log_oom();
if (r < 0)
return 0;
}
- r = oomd_cgroup_kill_mark(m, selected);
+ r = oomd_cgroup_kill_mark(m, selected, "memory-pressure");
if (r == -ENOMEM)
return log_oom();
if (r < 0)
typedef struct OomdKillState {
Manager *manager;
OomdCGroupContext *ctx;
+ const char *reason;
/* This holds sd_varlink references */
Set *links;
} OomdKillState;
return (int) k;
}
-int oomd_cgroup_kill(Manager *m, OomdCGroupContext *ctx, bool recurse) {
+int oomd_cgroup_kill(Manager *m, OomdCGroupContext *ctx, bool recurse, const char *reason) {
_cleanup_set_free_ Set *pids_killed = NULL;
int r;
assert(ctx);
+ assert(!m || reason);
pids_killed = set_new(NULL);
if (!pids_killed)
"Killed",
"ss",
ctx->path,
- "oom");
+ reason);
return !set_isempty(pids_killed);
}
if (!set_isempty(ks->links))
return;
- r = oomd_cgroup_kill(ks->manager, ks->ctx, /* recurse= */ true);
+ r = oomd_cgroup_kill(ks->manager, ks->ctx, /* recurse= */ true, ks->reason);
if (r < 0)
log_debug_errno(r, "Failed to kill cgroup '%s', ignoring: %m", ks->ctx->path);
oomd_kill_state_free(ks);
return 0;
}
-int oomd_cgroup_kill_mark(Manager *m, OomdCGroupContext *ctx) {
+int oomd_cgroup_kill_mark(Manager *m, OomdCGroupContext *ctx, const char *reason) {
int r;
assert(ctx);
assert(m);
+ assert(reason);
if (m->dry_run) {
_cleanup_free_ char *cg_path = NULL;
*ks = (OomdKillState) {
.manager = m,
.ctx = oomd_cgroup_context_ref(ctx),
+ .reason = reason,
};
r = set_ensure_put(&m->kill_states, &oomd_kill_state_hash_ops, ks);
int oomd_fetch_cgroup_oom_preference(OomdCGroupContext *ctx, const char *prefix);
/* Returns a negative value on error, 0 if no processes were killed, or 1 if processes were killed. */
-int oomd_cgroup_kill(Manager *m, OomdCGroupContext *ctx, bool recurse);
-int oomd_cgroup_kill_mark(Manager *m, OomdCGroupContext *ctx);
+int oomd_cgroup_kill(Manager *m, OomdCGroupContext *ctx, bool recurse, const char *reason);
+int oomd_cgroup_kill_mark(Manager *m, OomdCGroupContext *ctx, const char *reason);
/* The following oomd_kill_by_* functions return 1 if processes were killed, or negative otherwise. */
/* If `prefix` is supplied, only cgroups whose paths start with `prefix` are eligible candidates. Otherwise,
ASSERT_OK(fork_and_sleep(5, &two));
ASSERT_OK(cg_attach(subcgroup, two.pid));
- ASSERT_OK_POSITIVE(oomd_cgroup_kill(NULL /* manager */, &(OomdCGroupContext){ .path = subcgroup }, false /* recurse */));
+ ASSERT_OK_POSITIVE(oomd_cgroup_kill(
+ /* m= */ NULL,
+ &(OomdCGroupContext){ .path = subcgroup },
+ /* recurse= */ false,
+ /* reason= */ NULL));
ASSERT_OK(cg_get_xattr(subcgroup, "user.oomd_ooms", &v, /* ret_size= */ NULL));
ASSERT_STREQ(v, i == 0 ? "1" : "2");