Skip to content

Commit

Permalink
is_larger: propage meminto_t
Browse files Browse the repository at this point in the history
We will use this to estimate the rss for zombie main
threads.
  • Loading branch information
rfjakob committed Mar 19, 2024
1 parent 6c0f54f commit 1776d0a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion kill.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1776d0a

Please sign in to comment.