From: Jonathan Gray Date: Thu, 5 Dec 2019 14:21:07 +0000 (+1100) Subject: util/os_misc: os_get_available_system_memory() for OpenBSD X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b30bd6fe5f254d895c1dec780f24518b3e880ed4;p=mesa.git util/os_misc: os_get_available_system_memory() for OpenBSD Return the smallest value of available non-kernel physical memory and the static per process data size limit as the amount of available system memory on OpenBSD. Fixes: b80930a6fea ("anv: add support for VK_EXT_memory_budget") Signed-off-by: Jonathan Gray Acked-by: Jason Ekstrand Part-of: --- diff --git a/src/util/os_misc.c b/src/util/os_misc.c index 954900e3c5d..e184edc893d 100644 --- a/src/util/os_misc.c +++ b/src/util/os_misc.c @@ -28,6 +28,7 @@ #include "os_misc.h" #include "os_file.h" +#include "macros.h" #include @@ -57,6 +58,9 @@ # include #elif DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD # include +#elif DETECT_OS_OPENBSD +# include +# include #elif DETECT_OS_APPLE || DETECT_OS_BSD # include #elif DETECT_OS_HAIKU @@ -209,6 +213,22 @@ os_get_available_system_memory(uint64_t *size) free(meminfo); return false; +#elif DETECT_OS_OPENBSD + struct rlimit rl; + int mib[] = { CTL_HW, HW_USERMEM64 }; + int64_t mem_available; + size_t len = sizeof(mem_available); + + /* physmem - wired */ + if (sysctl(mib, 2, &mem_available, &len, NULL, 0) == -1) + return false; + + /* static login.conf limit */ + if (getrlimit(RLIMIT_DATA, &rl) == -1) + return false; + + *size = MIN2(mem_available, rl.rlim_cur); + return true; #else return false; #endif