Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ 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 <mach/thread_info.h>]])
AC_CHECK_MEMBERS([struct vm_statistics64.compressor_page_count], [], [], [[#include <mach/mach_host.h>]])
AC_CHECK_MEMBERS([struct vm_statistics64.external_page_count], [], [], [[#include <mach/mach_host.h>]])

AC_CHECK_DECLS([kIOMainPortDefault], [], [], [[#include <IOKit/IOKitLib.h>]])
fi

# ----------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions darwin/DarwinMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ in the source distribution for its full text.
#include <unistd.h>
#include <sys/mman.h>
#include <sys/sysctl.h>
#include <Availability.h>

#include "CRT.h"
#include "Machine.h"
Expand All @@ -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;
Expand Down
24 changes: 17 additions & 7 deletions darwin/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ in the source distribution for its full text.
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/route.h>
#include <sys/socket.h>
#include <mach/port.h>
#include <net/if.h> // After `sys/socket.h` for struct `sockaddr` (for iOS6 SDK)

#include <CoreFoundation/CFBase.h>
#include <CoreFoundation/CFDictionary.h>
Expand Down Expand Up @@ -397,17 +397,27 @@ void Platform_setMemoryValues(Meter* mtr) {
double page_K = (double)vm_page_size / (double)1024;

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;
mtr->values[MEMORY_METER_USED] = (double)(used - vm->compressor_page_count) * page_K;
#ifdef HAVE_STRUCT_VM_STATISTICS64_EXTERNAL_PAGE_COUNT
const natural_t external_page_count = vm->external_page_count;
#else
const natural_t external_page_count = 0;
#endif
const natural_t used_counts_from_statistics64 = vm->inactive_count + vm->speculative_count
- vm->purgeable_count - external_page_count;
#else
mtr->values[MEMORY_METER_USED] = (double)(vm->active_count + vm->wire_count) * page_K;
#endif
const natural_t used_counts_from_statistics64 = 0;
#endif // HAVE_STRUCT_VM_STATISTICS64
const natural_t used_count = vm->active_count + vm->wire_count + used_counts_from_statistics64;
mtr->values[MEMORY_METER_USED] = (double)used_count * page_K;
// 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
Expand Down