[Mesa-dev] [PATCH 2/2] anv: implement OpenBSD get_available_system_memory()

Jonathan Gray jsg at jsg.id.au
Sat Nov 30 15:21:49 UTC 2019


map linux /proc/meminfo "MemAvailable" to uvm free pages

Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
---
 src/intel/vulkan/anv_device.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 81e3905ae99..ce93718c106 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -370,6 +370,16 @@ anv_physical_device_free_disk_cache(struct anv_physical_device *device)
 static uint64_t
 get_available_system_memory()
 {
+#ifdef __OpenBSD__
+   int uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
+   struct uvmexp uvmexp;
+   size_t size;
+
+   size = sizeof(uvmexp);
+   if (sysctl(uvmexp_mib, 2, &uvmexp, &size, NULL, 0) == -1)
+      return 0;
+   return uvmexp.free * uvmexp.pagesize;
+#else
    char *meminfo = os_read_file("/proc/meminfo");
    if (!meminfo)
       return 0;
@@ -388,6 +398,7 @@ get_available_system_memory()
 
    free(meminfo);
    return 0;
+#endif
 }
 
 static VkResult
-- 
2.24.0



More information about the mesa-dev mailing list