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

Jonathan Gray jsg at jsg.id.au
Sat Nov 30 16:22:01 UTC 2019


On Sun, Dec 01, 2019 at 02:21:49AM +1100, Jonathan Gray wrote:
> map linux /proc/meminfo "MemAvailable" to uvm free pages

On second thought HW_USERMEM64 may be a better fit here.

"The amount of available non-kernel memory in bytes"

Which ends up being physmem - uvmexp.wired (memory that can't be paged
out) instead of the current amount of free memory.

> 
> 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
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list