diff options
author | Ross Williams <ross@ross-williams.net> | 2019-07-07 23:27:00 +0000 |
---|---|---|
committer | Ross Williams <ross@ross-williams.net> | 2019-07-07 23:10:54 -0400 |
commit | a88d2e313df7f5f2b781d5b14ffe0e7710018c10 (patch) | |
tree | 623e2c81c9335e37653c870f64190b2ed22cc365 /darwin | |
parent | fc8e9a2d3e25e35c0f9903baa345b1744b12b6cb (diff) |
Refactor common OpenZFS sysctl access
Darwin and FreeBSD export zfs kstats through the
same APIs, so moving functions into a common file.
Diffstat (limited to 'darwin')
-rw-r--r-- | darwin/DarwinProcessList.c | 82 | ||||
-rw-r--r-- | darwin/DarwinProcessList.h | 11 | ||||
-rw-r--r-- | darwin/Platform.c | 14 | ||||
-rw-r--r-- | darwin/Platform.h | 2 |
4 files changed, 16 insertions, 93 deletions
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 267e8e94..122e0188 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -9,6 +9,8 @@ in the source distribution for its full text. #include "DarwinProcess.h" #include "DarwinProcessList.h" #include "CRT.h" +#include "zfs/ZfsArcStats.h" +#include "zfs/openzfs_sysctl.h" #include <stdlib.h> #include <string.h> @@ -69,27 +71,11 @@ typedef struct DarwinProcessList_ { uint64_t user_threads; uint64_t global_diff; - int zfsArcEnabled; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcSize; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; - + ZfsArcStats zfs; } DarwinProcessList; }*/ -static int MIB_kstat_zfs_misc_arcstats_c_max[5]; -static int MIB_kstat_zfs_misc_arcstats_size[5]; -static int MIB_kstat_zfs_misc_arcstats_mfu_size[5]; -static int MIB_kstat_zfs_misc_arcstats_mru_size[5]; -static int MIB_kstat_zfs_misc_arcstats_anon_size[5]; -static int MIB_kstat_zfs_misc_arcstats_hdr_size[5]; -static int MIB_kstat_zfs_misc_arcstats_other_size[5]; - void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; @@ -150,48 +136,6 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { return processes; } -static inline void DarwinProcessList_scanZfsArcstats(DarwinProcessList* dpl) { - size_t len; - - if (dpl->zfsArcEnabled) { - len = sizeof(dpl->zfsArcSize); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(dpl->zfsArcSize), &len , NULL, 0); - /* TODO: adjust reported memory in use to move ARC from wired to inactive - Like: - // In bytes - dpl->vm_stats.wire_count -= dpl->zfsArcSize / vm_page_size; - dpl->vm_stats.inactive_count += dpl->zfsArcSize / vm_page_size; - // Would purgable_count be more true? - // Then convert to KB: - */ - dpl->zfsArcSize /= 1024; - - len = sizeof(dpl->zfsArcMax); - sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(dpl->zfsArcMax), &len , NULL, 0); - dpl->zfsArcMax /= 1024; - - len = sizeof(dpl->zfsArcMFU); - sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(dpl->zfsArcMFU), &len , NULL, 0); - dpl->zfsArcMFU /= 1024; - - len = sizeof(dpl->zfsArcMRU); - sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(dpl->zfsArcMRU), &len , NULL, 0); - dpl->zfsArcMRU /= 1024; - - len = sizeof(dpl->zfsArcAnon); - sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(dpl->zfsArcAnon), &len , NULL, 0); - dpl->zfsArcAnon /= 1024; - - len = sizeof(dpl->zfsArcHeader); - sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(dpl->zfsArcHeader), &len , NULL, 0); - dpl->zfsArcHeader /= 1024; - - len = sizeof(dpl->zfsArcOther); - sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(dpl->zfsArcOther), &len , NULL, 0); - dpl->zfsArcOther /= 1024; - } -} - ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { size_t len; DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList)); @@ -207,22 +151,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui ProcessList_getVMStats(&this->vm_stats); /* Initialize the ZFS kstats, if zfs.kext loaded */ - len = sizeof(this->zfsArcSize); - if (sysctlbyname("kstat.zfs.misc.arcstats.size", &this->zfsArcSize, &len, - NULL, 0) == 0 && this->zfsArcSize != 0) { - this->zfsArcEnabled = 1; - - len = 5; - sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); - } else { - this->zfsArcEnabled = 0; - } + this->zfs.enabled = openzfs_sysctl_init(); + openzfs_sysctl_updateArcStats(&this->zfs); this->super.kernelThreads = 0; this->super.userlandThreads = 0; @@ -252,7 +182,7 @@ void ProcessList_goThroughEntries(ProcessList* super) { dpl->prev_load = dpl->curr_load; ProcessList_allocateCPULoadInfo(&dpl->curr_load); ProcessList_getVMStats(&dpl->vm_stats); - DarwinProcessList_scanZfsArcstats(dpl); + openzfs_sysctl_updateArcStats(&dpl->zfs); /* Get the time difference */ dpl->global_diff = 0; diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 6686d05c..73fbd34f 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -21,6 +21,7 @@ negative value if more than the installed version int CompareKernelVersion(short int major, short int minor, short int component); #include "ProcessList.h" +#include "zfs/ZfsArcStats.h" #include <mach/mach_host.h> #include <sys/sysctl.h> @@ -35,15 +36,7 @@ typedef struct DarwinProcessList_ { uint64_t user_threads; uint64_t global_diff; - int zfsArcEnabled; - unsigned long long int zfsArcMax; - unsigned long long int zfsArcSize; - unsigned long long int zfsArcMFU; - unsigned long long int zfsArcMRU; - unsigned long long int zfsArcAnon; - unsigned long long int zfsArcHeader; - unsigned long long int zfsArcOther; - + ZfsArcStats zfs; } DarwinProcessList; diff --git a/darwin/Platform.c b/darwin/Platform.c index 52d60a9b..8fbb9c93 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -246,18 +246,18 @@ void Platform_setSwapValues(Meter* mtr) { void Platform_setZfsArcValues(Meter* this) { DarwinProcessList* dpl = (DarwinProcessList*) this->pl; - this->total = dpl->zfsArcMax; - this->values[0] = dpl->zfsArcMFU; - this->values[1] = dpl->zfsArcMRU; - this->values[2] = dpl->zfsArcAnon; - this->values[3] = dpl->zfsArcHeader; - this->values[4] = dpl->zfsArcOther; + this->total = dpl->zfs.max; + this->values[0] = dpl->zfs.MFU; + this->values[1] = dpl->zfs.MRU; + this->values[2] = dpl->zfs.anon; + this->values[3] = dpl->zfs.header; + this->values[4] = dpl->zfs.other; // "Hide" the last value so it can // only be accessed by index and is not // displayed by the Bar or Graph style Meter_setItems(this, 5); - this->values[5] = dpl->zfsArcSize; + this->values[5] = dpl->zfs.size; } char* Platform_getProcessEnv(pid_t pid) { diff --git a/darwin/Platform.h b/darwin/Platform.h index 4acda2c4..f8360775 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -48,7 +48,7 @@ void Platform_setMemoryValues(Meter* mtr); void Platform_setSwapValues(Meter* mtr); -void Platform_setZfsArcValues(Meter* mtr); +void Platform_setZfsArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); |