Skip to content

Commit

Permalink
lrun: detect OOM directly
Browse files Browse the repository at this point in the history
This should work more reliably than testing cg.memory_peak() >= config.memory_limit.
  • Loading branch information
quark-zju committed Jan 9, 2019
1 parent f93775f commit 76063ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/cgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ long long Cgroup::memory_limit() const {
return strconv::to_longlong(limit);
}

bool Cgroup::is_under_oom() const {
string content = get(CG_MEMORY, "memory.oom_control");
return content.find("under_oom 1") != string::npos;

}

long long Cgroup::set_memory_limit(long long bytes) {
int e = 1;

Expand Down
7 changes: 7 additions & 0 deletions src/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ namespace lrun {
*/
long long memory_limit() const;

/**
* test if the cgroup is under OOM
* @return true if under OOM
* false otherwise
*/
bool is_under_oom() const;

/**
* get cpu usage
* @return cpu usage in seconds
Expand Down
6 changes: 5 additions & 1 deletion src/lrun.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ static int run_command() {
}

// check memory limit
if (cg.memory_peak() >= config.memory_limit && config.memory_limit > 0) {
if (cg.is_under_oom()) {
INFO("OOM detected");
exceeded_limit = "MEMORY";
break;
} else if (cg.memory_peak() >= config.memory_limit && config.memory_limit > 0) {
exceeded_limit = "MEMORY";
break;
}
Expand Down

0 comments on commit 76063ef

Please sign in to comment.