Skip to content

Commit

Permalink
[cgroups2] Use OomListener in MemoryControllerProcess.
Browse files Browse the repository at this point in the history
The MemoryControllerProcess needs an OomListener to ensure that it does
not need to listen for oom events by polling, which causes race
conditions with the oom killer.

We spawn an OomListener in the MemoryControllerProcess and use it
to listen for oom events in any cgroup via oomListen().

Review: https://reviews.apache.org/r/75185/
  • Loading branch information
ZhouJas authored and bmahler committed Aug 22, 2024
1 parent 9d187ce commit 5ced878
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using process::PID;
using process::Owned;

using cgroups2::memory::Stats;
using cgroups2::memory::OomListener;

using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLimitation;
Expand All @@ -48,13 +49,22 @@ namespace slave {

Try<Owned<ControllerProcess>> MemoryControllerProcess::create(const Flags& flags)
{
return Owned<ControllerProcess>(new MemoryControllerProcess(flags));
Try<OomListener> listener = OomListener::create();
if (listener.isError()) {
return Error(
"Could not create oom listener for MemoryControllerProcess: "
+ listener.error());
}
return Owned<ControllerProcess>(
new MemoryControllerProcess(flags, std::move(*listener)));
}


MemoryControllerProcess::MemoryControllerProcess(const Flags& _flags)
MemoryControllerProcess::MemoryControllerProcess(
const Flags& _flags, OomListener&& _oomListener)
: ProcessBase(process::ID::generate("cgroups-v2-memory-controller")),
ControllerProcess(_flags) {}
ControllerProcess(_flags),
oomListener(std::move(_oomListener)) {}


string MemoryControllerProcess::name() const
Expand Down Expand Up @@ -277,7 +287,7 @@ void MemoryControllerProcess::oomListen(
return;
}

infos[containerId].oom = cgroups2::memory::oom(cgroup);
infos[containerId].oom = oomListener.listen(cgroup);

LOG(INFO) << "Listening for OOM events for container "
<< containerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "slave/flags.hpp"
#include "slave/containerizer/mesos/isolators/cgroups2/controller.hpp"
#include "linux/cgroups2.hpp"

namespace mesos {
namespace internal {
Expand Down Expand Up @@ -85,7 +86,9 @@ class MemoryControllerProcess : public ControllerProcess
bool hardLimitUpdated = false;
};

MemoryControllerProcess(const Flags& flags);
MemoryControllerProcess(
const Flags& flags,
cgroups2::memory::OomListener&& oomListener);

void oomListen(
const ContainerID& containerId,
Expand All @@ -97,6 +100,8 @@ class MemoryControllerProcess : public ControllerProcess
const process::Future<Nothing>& oomFuture);

hashmap<ContainerID, Info> infos;

cgroups2::memory::OomListener oomListener;
};

} // namespace slave {
Expand Down

0 comments on commit 5ced878

Please sign in to comment.