Skip to content

Commit

Permalink
don't fail the build if /proc/meminfo is missing or unexpected
Browse files Browse the repository at this point in the history
Summary:
Occasionally we see reports [1] that /proc/meminfo is missing or has
unexpected values on Linux. Instead of failing the build, guess a
reasonable value, at the risk that this will unnecessarily limit the
build's concurrency.

[1] facebook/watchman#1040

Reviewed By: genevievehelsel

Differential Revision: D38126612

fbshipit-source-id: 9d9d9f6003703acf6dffcdd5b2022f0f7b3aa691
  • Loading branch information
chadaustin authored and facebook-github-bot committed Jul 25, 2022
1 parent a615a4f commit 6198adf
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions build/fbcode_builder/getdeps/platform.py
Expand Up @@ -56,21 +56,32 @@ def get_linux_type() -> Tuple[Optional[str], Optional[str], Optional[str]]:
def _get_available_ram_linux() -> int:
# TODO: Ideally, this function would inspect the current cgroup for any
# limits, rather than solely relying on system RAM.
with open("/proc/meminfo") as f:
for line in f:
try:
key, value = line.split(":", 1)
except ValueError:
continue
suffix = " kB\n"
if key == "MemAvailable" and value.endswith(suffix):
value = value[: -len(suffix)]

meminfo_path = "/proc/meminfo"
try:
with open(meminfo_path) as f:
for line in f:
try:
return int(value) // 1024
key, value = line.split(":", 1)
except ValueError:
continue
suffix = " kB\n"
if key == "MemAvailable" and value.endswith(suffix):
value = value[: -len(suffix)]
try:
return int(value) // 1024
except ValueError:
continue
except OSError:
print("error opening {}".format(meminfo_path), end="", file=sys.stderr)
else:
print(
"{} had no valid MemAvailable".format(meminfo_path), end="", file=sys.stderr
)

raise NotImplementedError("/proc/meminfo had no valid MemAvailable")
guess = 8
print(", guessing {} GiB".format(guess), file=sys.stderr)
return guess * 1024


def _get_available_ram_macos() -> int:
Expand Down

0 comments on commit 6198adf

Please sign in to comment.