def _get_available_ram_linux()

in build/fbcode_builder/getdeps/platform.py [0:0]


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)]
                try:
                    return int(value) // 1024
                except ValueError:
                    continue

    raise NotImplementedError("/proc/meminfo had no valid MemAvailable")