Skip to content

Commit

Permalink
Dumping memory.stat in oomd
Browse files Browse the repository at this point in the history
Summary:
Commit [1 / 3]

Dumps the memory.stat of a cgroup to OLOG before killing the cgroup.

Reviewed By: lnyng

Differential Revision: D62042595

fbshipit-source-id: 3048a528f8b0198d0794feb955bae77a388f76ee
  • Loading branch information
Joshua Hahn authored and facebook-github-bot committed Sep 9, 2024
1 parent 566934a commit 914a864
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/oomd/plugins/BaseKillPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,20 @@ int BaseKillPlugin::getAndTryToKillPids(const CgroupContext& target) {
return nrKilled;
}

int BaseKillPlugin::dumpMemoryStat(const CgroupContext& target) {
auto stats =
Fs::readFileByLine(Fs::Fd::openat(target.fd(), Fs::kMemStatFile));
if (!stats) {
return 1;
}
OLOG << "memory.stat for " + target.cgroup().relativePath() + ": ";
for (auto& line : *stats) {
OLOG << line;
}

return 0;
}

int BaseKillPlugin::tryToKillCgroup(
const CgroupContext& target,
const KillUuid& killUuid,
Expand All @@ -462,8 +476,13 @@ int BaseKillPlugin::tryToKillCgroup(

OLOG << "Trying to kill " << cgroupPath;

if (dumpMemoryStat(target)) {
OLOG << "Failed to open " << cgroupPath << "/memory.stat";
}

reportKillUuidToXattr(cgroupPath, killUuid);
reportKillInitiationToXattr(cgroupPath);

while (tries--) {
// Descendent cgroups created during killing will be missed because
// getAndTryToKillPids reads cgroup children from OomdContext's cache
Expand Down
1 change: 1 addition & 0 deletions src/oomd/plugins/BaseKillPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class BaseKillPlugin : public Engine::BasePlugin {
* Override point for tests to control the clock
*/
virtual bool pastPrekillHookTimeout(const OomdContext& ctx) const;
virtual int dumpMemoryStat(const CgroupContext& target);

private:
virtual int getAndTryToKillPids(const CgroupContext& target);
Expand Down
9 changes: 8 additions & 1 deletion src/oomd/plugins/CorePluginsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ std::unique_ptr<Engine::BasePlugin> createPlugin(const std::string& name) {
namespace Oomd {
class BaseKillPluginMock : public BaseKillPlugin {
public:
/*
* We don't actually need to dump memory.stat since we won't
* actually be killing any live processes
*/
int dumpMemoryStat(const CgroupContext&) override {
return 0;
}

int tryToKillPids(const std::vector<int>& pids) override {
int ret = 0;
killed.reserve(pids.size());
Expand All @@ -58,7 +66,6 @@ class BaseKillPluginMock : public BaseKillPlugin {
++ret;
}
}

return ret;
}

Expand Down

0 comments on commit 914a864

Please sign in to comment.