Skip to content

util: Add support for more BSDs in os_get_available_system_memory

nia requested to merge nia/mesa:sysctl-sysmem into main

Make the BSD-ish code no longer exclusive to FreeBSD and OpenBSD, but instead enable it on all BSD systems.

This code has two requirements:

  1. The resource limit RLIMIT_DATA, which is defined in POSIX1 and supported in all the relevant systems.

  2. The sysctl variable HW_USERMEM, which is an old BSD feature.

    NetBSD-like systems (NetBSD and OpenBSD) prefer HW_USERMEM64 to get the system memory as a 64-bit integer2, while FreeBSD-like systems (macOS3, FreeBSD, DragonFly4) all only have HW_USERMEM.

    On FreeBSD and DragonFly, HW_USERMEM is a 64-bit integer, but it is unfortunately 32-bit on macOS and thus returns overflowed values on modern hardware...

    macOS does have 64-bit HW_MEMSIZE, but I'm unsure how this code could be adapted to use it. So let's not do this on macOS for now.

Merge request reports

Loading