mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
Platform: detect system page size
This commit is contained in:
@@ -11,17 +11,12 @@ const char* ffDetectMemory(FFMemoryResult* ram)
|
||||
if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0))
|
||||
return "Failed to read hw.memsize";
|
||||
|
||||
uint32_t pagesize;
|
||||
length = sizeof(pagesize);
|
||||
if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pagesize, &length, NULL, 0))
|
||||
return "Failed to read hw.pagesize";
|
||||
|
||||
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
|
||||
vm_statistics64_data_t vmstat;
|
||||
if(host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS)
|
||||
return "Failed to read host_statistics64";
|
||||
|
||||
ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * pagesize;
|
||||
ram->bytesUsed = ((uint64_t) vmstat.active_count + vmstat.wire_count) * instance.state.platform.pageSize;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -7,17 +7,12 @@ const char* ffDetectMemory(FFMemoryResult* ram)
|
||||
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0))
|
||||
return "Failed to read hw.physmem";
|
||||
|
||||
uint32_t pageSize;
|
||||
length = sizeof(pageSize);
|
||||
if (sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &pageSize, &length, NULL, 0))
|
||||
return "Failed to read hw.pagesize";
|
||||
|
||||
// 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);
|
||||
|
||||
ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * pageSize;
|
||||
ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * instance.state.platform.pageSize;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user