Skip to content

Commit

Permalink
Added cg-oom-killed meta entry
Browse files Browse the repository at this point in the history
It is hard to judge solely from the meta output whether a program has
been SIGKILL by the OOM killer or something else.

Since Linux 4.15, the cgroup API provides us with a memory.oom_control
file that contains a key "oom_kill" with the number of times the cgroup
has received an OOM kill. If this value is greater than 0, we report that
there was an OOM kill in the meta file with the cg-oom-killed entry.

Based on work by Antoine Pietri.
  • Loading branch information
gollux committed Mar 24, 2018
1 parent 2f5b70c commit cd542d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ cg_read(cg_controller controller, const char *attr, char *buf)
buf[n] = 0;

if (verbose > 1)
msg("CG: Read %s = %s\n", attr, buf);
msg("CG: Read %s = <%s>\n", attr, buf);

result = 1;
fail_close:
Expand Down Expand Up @@ -280,6 +280,24 @@ cg_stats(void)
}
if (mem)
meta_printf("cg-mem:%lld\n", mem >> 10);

// OOM kill detection
if (cg_read(CG_MEMORY, "?memory.oom_control", buf))
{
int oom_killed = 0;
char *s = buf;
while (s)
{
if (sscanf(s, "oom_kill %d", &oom_killed) == 1 && oom_killed)
{
meta_printf("cg-oom-killed:1\n");
break;
}
s = strchr(s, '\n');
if (s)
s++;
}
}
}

void
Expand Down
4 changes: 4 additions & 0 deletions isolate.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ of format 'key'*:*'value'. The following keys are defined:
*cg-mem*::
When control groups are enabled, this is the total memory use
by the whole control group (in kilobytes).
*cg-oom-killed*::
Present when the program was killed by the out-of-memory killer
(e.g., because it has exceeded the memory limit of its control group).
This is reported only on Linux 4.13 and later.
*csw-forced*::
Number of context switches forced by the kernel.
*csw-voluntary*::
Expand Down

0 comments on commit cd542d6

Please sign in to comment.