1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
From fc8e9a2d3e25e35c0f9903baa345b1744b12b6cb Mon Sep 17 00:00:00 2001
From: Ross Williams <ross@ross-williams.net>
Date: Sun, 7 Jul 2019 17:30:37 -0400
Subject: [PATCH 4/9] ZFS arcstats for Darwin (macOS / OS X)
---
Makefile.am | 6 ++-
darwin/DarwinProcessList.c | 80 ++++++++++++++++++++++++++++++++++++++
darwin/DarwinProcessList.h | 21 ++++++++++
darwin/Platform.c | 19 +++++++++
darwin/Platform.h | 2 +
5 files changed, 126 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index b850815..b6d2117 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -134,14 +134,16 @@ darwin_platform_headers = \
darwin/DarwinProcess.h \
darwin/DarwinProcessList.h \
darwin/DarwinCRT.h \
- darwin/Battery.h
+ darwin/Battery.h \
+ $(zfs_platform_headers)
all_platform_headers += $(darwin_platform_headers)
if HTOP_DARWIN
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
-darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
+darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c \
+$(zfs_platform_sources)
myhtopplatheaders = $(darwin_platform_headers)
endif
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c
index 0988448..267e8e9 100644
--- a/darwin/DarwinProcessList.c
+++ b/darwin/DarwinProcessList.c
@@ -54,6 +54,7 @@ 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>
@@ -67,10 +68,28 @@ typedef struct DarwinProcessList_ {
uint64_t kernel_threads;
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;
+
} 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;
@@ -131,8 +150,50 @@ 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));
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
@@ -145,6 +206,24 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
/* Initialize the VM statistics */
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->super.kernelThreads = 0;
this->super.userlandThreads = 0;
this->super.totalTasks = 0;
@@ -173,6 +252,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);
/* Get the time difference */
dpl->global_diff = 0;
diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h
index c216a80..6686d05 100644
--- a/darwin/DarwinProcessList.h
+++ b/darwin/DarwinProcessList.h
@@ -9,6 +9,17 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
+struct kern;
+
+void GetKernelVersion(struct kern *k);
+
+/* compare the given os version with the one installed returns:
+0 if equals the installed version
+positive value if less than the installed version
+negative value if more than the installed version
+*/
+int CompareKernelVersion(short int major, short int minor, short int component);
+
#include "ProcessList.h"
#include <mach/mach_host.h>
#include <sys/sysctl.h>
@@ -23,6 +34,16 @@ typedef struct DarwinProcessList_ {
uint64_t kernel_threads;
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;
+
} DarwinProcessList;
diff --git a/darwin/Platform.c b/darwin/Platform.c
index 1dce8b6..52d60a9 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -15,6 +15,7 @@ in the source distribution for its full text.
#include "ClockMeter.h"
#include "HostnameMeter.h"
#include "UptimeMeter.h"
+#include "zfs/ZfsArcMeter.h"
#include "DarwinProcessList.h"
#include <stdlib.h>
@@ -117,6 +118,7 @@ MeterClass* Platform_meterTypes[] = {
&RightCPUsMeter_class,
&LeftCPUs2Meter_class,
&RightCPUs2Meter_class,
+ &ZfsArcMeter_class,
&BlankMeter_class,
NULL
};
@@ -241,6 +243,23 @@ void Platform_setSwapValues(Meter* mtr) {
mtr->values[0] = swapused.xsu_used / 1024;
}
+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;
+
+ // "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;
+}
+
char* Platform_getProcessEnv(pid_t pid) {
char* env = NULL;
diff --git a/darwin/Platform.h b/darwin/Platform.h
index 1231217..4acda2c 100644
--- a/darwin/Platform.h
+++ b/darwin/Platform.h
@@ -48,6 +48,8 @@ void Platform_setMemoryValues(Meter* mtr);
void Platform_setSwapValues(Meter* mtr);
+void Platform_setZfsArcValues(Meter* mtr);
+
char* Platform_getProcessEnv(pid_t pid);
#endif
--
2.20.1
|