mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
Memory (macOS): updates algorithm in order not to use hw.memsize_usable which is available on newer macOS version
Adds a new CMake option to use usable memory size at the same time Fixes #2171
This commit is contained in:
@@ -9,30 +9,25 @@
|
||||
const char* ffDetectMemory(FFMemoryResult* ram)
|
||||
{
|
||||
size_t length = sizeof(ram->bytesTotal);
|
||||
|
||||
#if FF_APPLE_MEMSIZE_USABLE
|
||||
if (sysctlbyname("hw.memsize_usable", &ram->bytesTotal, &length, NULL, 0) != 0)
|
||||
return "Failed to read hw.memsize_usable";
|
||||
#else
|
||||
if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0) != 0)
|
||||
return "Failed to read hw.memsize";
|
||||
uint64_t usableMemory = 0;
|
||||
length = sizeof(usableMemory);
|
||||
if (sysctlbyname("hw.memsize_usable", &usableMemory, &length, NULL, 0) != 0)
|
||||
usableMemory = ram->bytesTotal;
|
||||
#endif
|
||||
|
||||
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";
|
||||
|
||||
uint64_t pageSize = instance.state.platform.sysinfo.pageSize;
|
||||
uint64_t appMemory = vmstat.internal_page_count * pageSize; // memory allocated by `mmap(..., MAP_ANON | MAP_PRIVATE, ...)`, i.e. malloc(3)
|
||||
uint64_t wiredMemory = vmstat.wire_count * pageSize;
|
||||
uint64_t compressed = vmstat.compressor_page_count * pageSize;
|
||||
uint64_t reserved = ram->bytesTotal - usableMemory;
|
||||
// https://github.com/st3fan/osx-10.9/blob/34e34a6a539b5a822cda4074e56a7ced9b57da71/system_cmds-597.1.1/vm_stat.tproj/vm_stat.c#L139
|
||||
|
||||
FF_DEBUG("App: %.2f GiB", (double) appMemory / 1024. / 1024. / 1024.);
|
||||
FF_DEBUG("Wired: %.2f GiB", (double) wiredMemory / 1024. / 1024. / 1024.);
|
||||
FF_DEBUG("Compressed: %.2f GiB", (double) compressed / 1024. / 1024. / 1024.);
|
||||
FF_DEBUG("Reserved: %.2f GiB", (double) reserved / 1024. / 1024. / 1024.);
|
||||
|
||||
ram->bytesUsed = appMemory + wiredMemory + compressed + reserved;
|
||||
uint64_t pagesFree = vmstat.free_count - vmstat.speculative_count;
|
||||
uint64_t pagesFileBacked = vmstat.external_page_count; // Cached files
|
||||
ram->bytesUsed = ram->bytesTotal - (pagesFree + pagesFileBacked) * instance.state.platform.sysinfo.pageSize;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user