2025-01-13 18:33:05 +08:00
|
|
|
#include "memory.h"
|
|
|
|
|
#include "common/sysctl.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
const char* ffDetectMemory(FFMemoryResult* ram) {
|
2025-01-13 18:33:05 +08:00
|
|
|
struct uvmexp_sysctl buf;
|
|
|
|
|
size_t length = sizeof(buf);
|
2026-03-30 10:27:23 +08:00
|
|
|
if (sysctl((int[]) { CTL_VM, VM_UVMEXP2 }, 2, &buf, &length, NULL, 0) < 0) {
|
2025-01-13 18:33:05 +08:00
|
|
|
return "sysctl(CTL_VM, VM_UVMEXP2) failed";
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-01-13 18:33:05 +08:00
|
|
|
|
2026-06-28 10:05:24 +08:00
|
|
|
int64_t bytesArc = ffSysctlGetInt64("kstat.zfs.misc.arcstats.size", 0);
|
|
|
|
|
if (bytesArc > 0) bytesArc -= ffSysctlGetInt64("kstat.zfs.misc.arcstats.c_min", 0);
|
|
|
|
|
if (bytesArc < 0) bytesArc = 0;
|
|
|
|
|
|
2025-01-13 18:33:05 +08:00
|
|
|
ram->bytesTotal = (uint64_t) buf.npages * instance.state.platform.sysinfo.pageSize;
|
2026-06-28 10:05:24 +08:00
|
|
|
ram->bytesUsed = ((uint64_t) buf.active + (uint64_t) buf.inactive + (uint64_t) buf.wired) * instance.state.platform.sysinfo.pageSize - (uint64_t) bytesArc;
|
2025-01-13 18:33:05 +08:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|