diff --git a/src/oomd/plugins/BaseKillPlugin.cpp b/src/oomd/plugins/BaseKillPlugin.cpp index 40770516..536aa3c6 100644 --- a/src/oomd/plugins/BaseKillPlugin.cpp +++ b/src/oomd/plugins/BaseKillPlugin.cpp @@ -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, @@ -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 diff --git a/src/oomd/plugins/BaseKillPlugin.h b/src/oomd/plugins/BaseKillPlugin.h index ee9dd168..0a9cc327 100644 --- a/src/oomd/plugins/BaseKillPlugin.h +++ b/src/oomd/plugins/BaseKillPlugin.h @@ -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); diff --git a/src/oomd/plugins/CorePluginsTest.cpp b/src/oomd/plugins/CorePluginsTest.cpp index 836830c1..50129534 100644 --- a/src/oomd/plugins/CorePluginsTest.cpp +++ b/src/oomd/plugins/CorePluginsTest.cpp @@ -48,6 +48,14 @@ std::unique_ptr 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& pids) override { int ret = 0; killed.reserve(pids.size()); @@ -58,7 +66,6 @@ class BaseKillPluginMock : public BaseKillPlugin { ++ret; } } - return ret; }