From 1776d0a796773b7db240ab73a393a6d6956b0c1b Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 19 Mar 2024 17:52:03 +0100 Subject: [PATCH] is_larger: propage meminto_t We will use this to estimate the rss for zombie main threads. --- kill.c | 6 +++--- kill.h | 2 +- main.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/kill.c b/kill.c index 8f13863..305c5da 100644 --- a/kill.c +++ b/kill.c @@ -264,7 +264,7 @@ int kill_wait(const poll_loop_args_t* args, pid_t pid, int sig) // than our current `victim`. // In the process, it fills the `cur` structure. It does so lazily, meaning // it only fills the fields it needs to make a decision. -bool is_larger(const poll_loop_args_t* args, const procinfo_t* victim, procinfo_t* cur) +bool is_larger(const poll_loop_args_t* args, const meminfo_t* m, const procinfo_t* victim, procinfo_t* cur) { if (cur->pid <= 1) { // Let's not kill init. @@ -398,7 +398,7 @@ void debug_print_procinfo(const procinfo_t* cur) /* * Find the process with the largest oom_score or rss(when flag --sort-by-rss is set). */ -procinfo_t find_largest_process(const poll_loop_args_t* args) +procinfo_t find_largest_process(const poll_loop_args_t* args, const meminfo_t* m) { DIR* procdir = opendir(procdir_path); if (procdir == NULL) { @@ -434,7 +434,7 @@ procinfo_t find_largest_process(const poll_loop_args_t* args) /* omitted fields are set to zero */ }; - bool larger = is_larger(args, &victim, &cur); + bool larger = is_larger(args, m, &victim, &cur); debug_print_procinfo(&cur); diff --git a/kill.h b/kill.h index a8ddfc3..05bd7dc 100644 --- a/kill.h +++ b/kill.h @@ -36,6 +36,6 @@ typedef struct { } poll_loop_args_t; void kill_process(const poll_loop_args_t* args, int sig, const procinfo_t* victim); -procinfo_t find_largest_process(const poll_loop_args_t* args); +procinfo_t find_largest_process(const poll_loop_args_t* args, const meminfo_t* m); #endif diff --git a/main.c b/main.c index 8540654..e70793a 100644 --- a/main.c +++ b/main.c @@ -64,11 +64,11 @@ double min(double x, double y) // Dry-run oom kill to make sure that // (1) it works (meaning /proc is accessible) // (2) the stack grows to maximum size before calling mlockall() -static void startup_selftests(poll_loop_args_t* args) +static void startup_selftests(poll_loop_args_t* args, const meminfo_t *m) { { debug("%s: dry-running oom kill...\n", __func__); - procinfo_t victim = find_largest_process(args); + procinfo_t victim = find_largest_process(args, m); kill_process(args, 0, &victim); } if (args->notify_ext) { @@ -362,7 +362,7 @@ int main(int argc, char* argv[]) fprintf(stderr, " SIGKILL when mem <= " PRIPCT " and swap <= " PRIPCT "\n", args.mem_kill_percent, args.swap_kill_percent); - startup_selftests(&args); + startup_selftests(&args, &m); int err = mlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT); // kernels older than 4.4 don't support MCL_ONFAULT. Retry without it. @@ -470,7 +470,7 @@ static void poll_loop(const poll_loop_args_t* args) args->mem_term_percent, args->swap_term_percent); } if (sig) { - procinfo_t victim = find_largest_process(args); + procinfo_t victim = find_largest_process(args, &m); /* The run time of find_largest_process is proportional to the number * of processes, and takes 2.5ms on my box with a running Gnome desktop (try "make bench"). * This is long enough that the situation may have changed in the meantime,