in src/oomd/plugins/Senpai.cpp [417:447]
std::optional<int64_t> Senpai::getLimitMaxBytes(
const CgroupContext& cgroup_ctx) {
auto memcurr_opt = cgroup_ctx.current_usage();
if (!memcurr_opt) {
return std::nullopt;
}
auto limit_max_bytes =
std::min(host_mem_total_, limit_max_bytes_ + *memcurr_opt);
// Don't let memory.high.tmp go above memory.high as kernel ignores the
// latter when the former is set.
auto has_memory_high_tmp_opt = hasMemoryHighTmp(cgroup_ctx);
if (!has_memory_high_tmp_opt) {
return std::nullopt;
}
if (*has_memory_high_tmp_opt) {
auto memhigh_opt = cgroup_ctx.memory_high();
if (!memhigh_opt) {
return std::nullopt;
}
limit_max_bytes = std::min(limit_max_bytes, *memhigh_opt);
}
auto memmax_opt = cgroup_ctx.memory_max();
if (!memmax_opt) {
return std::nullopt;
}
limit_max_bytes = std::min(limit_max_bytes, *memmax_opt);
return limit_max_bytes;
}