From 29725dbda78ac4a4a701599d8f1799da509687f1 Mon Sep 17 00:00:00 2001 From: Mingyang Li Date: Sun, 30 Nov 2025 17:42:06 -0800 Subject: [PATCH 1/3] Some SDKs may not have external and compressed page counts exposed in memory statistics (e.g., iPhoneOS6.1). --- configure.ac | 2 ++ darwin/Platform.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a5b49d9a1..e1d22612e 100644 --- a/configure.ac +++ b/configure.ac @@ -223,6 +223,8 @@ AC_CHECK_HEADERS([execinfo.h]) if test "$my_htop_platform" = darwin; then AC_CHECK_HEADERS([mach/mach_time.h]) AC_CHECK_TYPES([thread_extended_info_data_t], [], [], [[#include ]]) + AC_CHECK_MEMBERS([struct vm_statistics64.compressor_page_count], [], [], [[#include ]]) + AC_CHECK_MEMBERS([struct vm_statistics64.external_page_count], [], [], [[#include ]]) fi # ---------------------------------------------------------------------- diff --git a/darwin/Platform.c b/darwin/Platform.c index 72d262590..ae6845685 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -404,15 +404,26 @@ void Platform_setMemoryValues(Meter* mtr) { mtr->total = dhost->host_info.max_mem / 1024; #ifdef HAVE_STRUCT_VM_STATISTICS64 natural_t used = vm->active_count + vm->inactive_count + - vm->speculative_count + vm->wire_count + - vm->compressor_page_count - vm->purgeable_count - vm->external_page_count; + vm->speculative_count + vm->wire_count - vm->purgeable_count; +#ifdef HAVE_STRUCT_VM_STATISTICS64_EXTERNAL_PAGE_COUNT + used -= vm->external_page_count; +#endif +#ifdef HAVE_STRUCT_VM_STATISTICS64_COMPRESSOR_PAGE_COUNT + used += vm->compressor_page_count; mtr->values[MEMORY_METER_USED] = (double)(used - vm->compressor_page_count) * page_K; +#else + mtr->values[MEMORY_METER_USED] = (double)used * page_K; +#endif #else mtr->values[MEMORY_METER_USED] = (double)(vm->active_count + vm->wire_count) * page_K; #endif // mtr->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" #ifdef HAVE_STRUCT_VM_STATISTICS64 +#ifdef HAVE_STRUCT_VM_STATISTICS64_COMPRESSOR_PAGE_COUNT mtr->values[MEMORY_METER_COMPRESSED] = (double)vm->compressor_page_count * page_K; +#else + // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory not available" +#endif #else // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" #endif From ba98c8e97d71e970d0a77ef3436472a1acc4c492 Mon Sep 17 00:00:00 2001 From: Mingyang Li Date: Mon, 1 Dec 2025 16:15:35 -0800 Subject: [PATCH 2/3] Legacy SDKs may call `main` `master` (e.g., iPhoneOS6.1). --- configure.ac | 2 ++ darwin/DarwinMachine.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index e1d22612e..676aa42ca 100644 --- a/configure.ac +++ b/configure.ac @@ -225,6 +225,8 @@ if test "$my_htop_platform" = darwin; then AC_CHECK_TYPES([thread_extended_info_data_t], [], [], [[#include ]]) AC_CHECK_MEMBERS([struct vm_statistics64.compressor_page_count], [], [], [[#include ]]) AC_CHECK_MEMBERS([struct vm_statistics64.external_page_count], [], [], [[#include ]]) + + AC_CHECK_DECLS([kIOMainPortDefault], [], [], [[#include ]]) fi # ---------------------------------------------------------------------- diff --git a/darwin/DarwinMachine.c b/darwin/DarwinMachine.c index 4937be105..df50f2303 100644 --- a/darwin/DarwinMachine.c +++ b/darwin/DarwinMachine.c @@ -16,6 +16,7 @@ in the source distribution for its full text. #include #include #include +#include #include "CRT.h" #include "Machine.h" @@ -24,6 +25,10 @@ in the source distribution for its full text. #include "generic/openzfs_sysctl.h" #include "zfs/ZfsArcStats.h" +// Compatibility for older SDKs. +#if defined(HAVE_DECL_KIOMAINPORTDEFAULT) && !HAVE_DECL_KIOMAINPORTDEFAULT +#define kIOMainPortDefault kIOMasterPortDefault +#endif static void DarwinMachine_getHostInfo(host_basic_info_data_t* p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; From 8635db1ea38ade9e2a41ad6d7031c2008e664dc3 Mon Sep 17 00:00:00 2001 From: Mingyang Li Date: Thu, 4 Dec 2025 14:14:32 -0800 Subject: [PATCH 3/3] Some legacy SDKs may require a particular import order for net interface header to work (e.g., iPhoneOS6.1). --- darwin/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/darwin/Platform.c b/darwin/Platform.c index ae6845685..b871fc5aa 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -15,11 +15,11 @@ in the source distribution for its full text. #include #include #include -#include #include #include #include #include +#include // After `sys/socket.h` for struct `sockaddr` (for iOS6 SDK) #include #include