2022-09-19 22:23:31 +02:00
|
|
|
#include "memory.h"
|
2022-09-19 23:16:43 +02:00
|
|
|
#include "common/sysctl.h"
|
2022-09-19 22:23:31 +02:00
|
|
|
|
2023-05-11 20:39:54 +08:00
|
|
|
const char* ffDetectMemory(FFMemoryResult* ram)
|
2022-09-19 22:23:31 +02:00
|
|
|
{
|
2023-08-25 08:47:02 +08:00
|
|
|
size_t length = sizeof(ram->bytesTotal);
|
2023-06-15 11:19:53 +08:00
|
|
|
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0))
|
|
|
|
|
return "Failed to read hw.physmem";
|
|
|
|
|
|
|
|
|
|
// vm.stats.vm.* are int values
|
|
|
|
|
int32_t pagesFree = ffSysctlGetInt("vm.stats.vm.v_free_count", 0)
|
|
|
|
|
+ ffSysctlGetInt("vm.stats.vm.v_inactive_count", 0)
|
|
|
|
|
+ ffSysctlGetInt("vm.stats.vm.v_cache_count", 0);
|
2022-09-20 15:12:24 +02:00
|
|
|
|
2023-11-08 00:02:00 +08:00
|
|
|
ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * instance.state.platform.pageSize;
|
2023-05-11 20:39:54 +08:00
|
|
|
|
|
|
|
|
return NULL;
|
2022-09-20 15:12:24 +02:00
|
|
|
}
|