Permalink
Browse files

add memavailable to MemInfo

Summary: MemAvailable more accurately describes available memory and is supported in recent Linux kernels.

Reviewed By: liuxuli

Differential Revision: D6783149

fbshipit-source-id: 279f3c38761a1aff493116f50d44736b89cfe88c
  • Loading branch information...
binliu19 authored and hhvm-bot committed Jan 30, 2018
1 parent 1fd3fec commit d2840faec2a276e310a5464f1e824fe04ed49950
Showing with 11 additions and 1 deletion.
  1. +9 −0 hphp/util/process.cpp
  2. +2 −1 hphp/util/process.h
@@ -152,8 +152,17 @@ bool Process::GetMemoryInfo(MemInfo& info) {
info.freeMb = std::max(info.freeMb, parseLine("MemFree", buf));
info.buffersMb = std::max(info.buffersMb, parseLine("Buffers", buf));
info.cachedMb = std::max(info.cachedMb, parseLine("Cached", buf));
info.availableMb =
std::max(info.availableMb, parseLine("MemAvailable", buf));
if (info.valid()) return true;
}
// If MemAvailable isn't available, which shouldn't be the case for kernel
// versions later than 3.14, we get a rough esitmation.
if (info.availableMb < 0 && info.freeMb >= 0 &&
info.cachedMb >= 0 && info.buffersMb >= 0) {
info.availableMb = info.freeMb + info.cachedMb;
return true;
}
}
return false;
}
@@ -41,8 +41,9 @@ struct MemInfo {
int64_t freeMb{-1};
int64_t cachedMb{-1};
int64_t buffersMb{-1};
int64_t availableMb{-1};
bool valid() const {
return freeMb >= 0 && cachedMb >= 0 && buffersMb >= 0;
return (freeMb | cachedMb | buffersMb | availableMb) >= 0;
}
};

0 comments on commit d2840fa

Please sign in to comment.