conmon: Disable OOM handling if cgroups not setup
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
7700a62347
commit
52b27da680
1 changed files with 21 additions and 14 deletions
|
@ -629,21 +629,26 @@ int main(int argc, char *argv[])
|
||||||
nexit("Failed to get memory cgroup path");
|
nexit("Failed to get memory cgroup path");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool oom_handling_enabled = true;
|
||||||
char memory_cgroup_file_path[PATH_MAX];
|
char memory_cgroup_file_path[PATH_MAX];
|
||||||
snprintf(memory_cgroup_file_path, PATH_MAX, "%s/cgroup.event_control", memory_cgroup_path);
|
snprintf(memory_cgroup_file_path, PATH_MAX, "%s/cgroup.event_control", memory_cgroup_path);
|
||||||
if ((cfd = open(memory_cgroup_file_path, O_WRONLY)) == -1)
|
if ((cfd = open(memory_cgroup_file_path, O_WRONLY)) == -1) {
|
||||||
pexit("Failed to open %s", memory_cgroup_file_path);
|
nwarn("Failed to open %s", memory_cgroup_file_path);
|
||||||
|
oom_handling_enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(memory_cgroup_file_path, PATH_MAX, "%s/memory.oom_control", memory_cgroup_path);
|
if (oom_handling_enabled) {
|
||||||
if ((ofd = open(memory_cgroup_file_path, O_RDONLY)) == -1)
|
snprintf(memory_cgroup_file_path, PATH_MAX, "%s/memory.oom_control", memory_cgroup_path);
|
||||||
pexit("Failed to open %s", memory_cgroup_file_path);
|
if ((ofd = open(memory_cgroup_file_path, O_RDONLY)) == -1)
|
||||||
|
pexit("Failed to open %s", memory_cgroup_file_path);
|
||||||
|
|
||||||
if ((efd = eventfd(0, 0)) == -1)
|
if ((efd = eventfd(0, 0)) == -1)
|
||||||
pexit("Failed to create eventfd");
|
pexit("Failed to create eventfd");
|
||||||
|
|
||||||
wb = snprintf(buf, BUF_SIZE, "%d %d", efd, ofd);
|
wb = snprintf(buf, BUF_SIZE, "%d %d", efd, ofd);
|
||||||
if (write(cfd, buf, wb) < 0)
|
if (write(cfd, buf, wb) < 0)
|
||||||
pexit("Failed to write to cgroup.event_control");
|
pexit("Failed to write to cgroup.event_control");
|
||||||
|
}
|
||||||
|
|
||||||
/* Create epoll_ctl so that we can handle read/write events. */
|
/* Create epoll_ctl so that we can handle read/write events. */
|
||||||
/*
|
/*
|
||||||
|
@ -669,9 +674,11 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the OOM event fd to epoll */
|
/* Add the OOM event fd to epoll */
|
||||||
ev.data.fd = efd;
|
if (oom_handling_enabled) {
|
||||||
if (epoll_ctl(epfd, EPOLL_CTL_ADD, ev.data.fd, &ev) < 0)
|
ev.data.fd = efd;
|
||||||
pexit("Failed to add OOM eventfd to epoll");
|
if (epoll_ctl(epfd, EPOLL_CTL_ADD, ev.data.fd, &ev) < 0)
|
||||||
|
pexit("Failed to add OOM eventfd to epoll");
|
||||||
|
}
|
||||||
|
|
||||||
/* Log all of the container's output. */
|
/* Log all of the container's output. */
|
||||||
while (num_stdio_fds > 0) {
|
while (num_stdio_fds > 0) {
|
||||||
|
@ -687,7 +694,7 @@ int main(int argc, char *argv[])
|
||||||
pipe = STDOUT_PIPE;
|
pipe = STDOUT_PIPE;
|
||||||
else if (masterfd == masterfd_stderr)
|
else if (masterfd == masterfd_stderr)
|
||||||
pipe = STDERR_PIPE;
|
pipe = STDERR_PIPE;
|
||||||
else if (masterfd == efd) {
|
else if (oom_handling_enabled && masterfd == efd) {
|
||||||
if (read(efd, &oom_event, sizeof(uint64_t)) != sizeof(uint64_t))
|
if (read(efd, &oom_event, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||||
nwarn("Failed to read event from eventfd");
|
nwarn("Failed to read event from eventfd");
|
||||||
ninfo("OOM received");
|
ninfo("OOM received");
|
||||||
|
|
Loading…
Reference in a new issue