summaryrefslogtreecommitdiffstats
path: root/zfs
diff options
context:
space:
mode:
authorRoss Williams <ross@ross-williams.net>2019-07-07 23:27:00 +0000
committerRoss Williams <ross@ross-williams.net>2019-07-07 23:10:54 -0400
commita88d2e313df7f5f2b781d5b14ffe0e7710018c10 (patch)
tree623e2c81c9335e37653c870f64190b2ed22cc365 /zfs
parentfc8e9a2d3e25e35c0f9903baa345b1744b12b6cb (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 'zfs')
-rw-r--r--zfs/ZfsArcStats.c19
-rw-r--r--zfs/ZfsArcStats.h23
-rw-r--r--zfs/openzfs_sysctl.c81
-rw-r--r--zfs/openzfs_sysctl.h18
4 files changed, 141 insertions, 0 deletions
diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c
new file mode 100644
index 00000000..c33076a4
--- /dev/null
+++ b/zfs/ZfsArcStats.c
@@ -0,0 +1,19 @@
+/*
+htop - ZfsArcStats.c
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+/*{
+typedef struct ZfsArcStats_ {
+ int enabled;
+ unsigned long long int max;
+ unsigned long long int size;
+ unsigned long long int MFU;
+ unsigned long long int MRU;
+ unsigned long long int anon;
+ unsigned long long int header;
+ unsigned long long int other;
+} ZfsArcStats;
+}*/
diff --git a/zfs/ZfsArcStats.h b/zfs/ZfsArcStats.h
new file mode 100644
index 00000000..3697af23
--- /dev/null
+++ b/zfs/ZfsArcStats.h
@@ -0,0 +1,23 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_ZfsArcStats
+#define HEADER_ZfsArcStats
+/*
+htop - ZfsArcStats.h
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+typedef struct ZfsArcStats_ {
+ int enabled;
+ unsigned long long int max;
+ unsigned long long int size;
+ unsigned long long int MFU;
+ unsigned long long int MRU;
+ unsigned long long int anon;
+ unsigned long long int header;
+ unsigned long long int other;
+} ZfsArcStats;
+
+#endif
diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c
new file mode 100644
index 00000000..ce48f233
--- /dev/null
+++ b/zfs/openzfs_sysctl.c
@@ -0,0 +1,81 @@
+/*
+htop - zfs/openzfs_sysctl.c
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "zfs/openzfs_sysctl.h"
+#include "zfs/ZfsArcStats.h"
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+static int MIB_kstat_zfs_misc_arcstats_size[5];
+static int MIB_kstat_zfs_misc_arcstats_c_max[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];
+
+/*{
+#include "zfs/ZfsArcStats.h"
+}*/
+
+int openzfs_sysctl_init() {
+ size_t len;
+ unsigned long long int arcSize;
+
+ len = sizeof(arcSize);
+ if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len,
+ NULL, 0) == 0 && arcSize != 0) {
+ 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);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+void openzfs_sysctl_updateArcStats(ZfsArcStats *stats) {
+ size_t len;
+
+ if (stats->enabled) {
+ len = sizeof(stats->size);
+ sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len , NULL, 0);
+ stats->size /= 1024;
+
+ len = sizeof(stats->max);
+ sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len , NULL, 0);
+ stats->max /= 1024;
+
+ len = sizeof(stats->MFU);
+ sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len , NULL, 0);
+ stats->MFU /= 1024;
+
+ len = sizeof(stats->MRU);
+ sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len , NULL, 0);
+ stats->MRU /= 1024;
+
+ len = sizeof(stats->anon);
+ sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len , NULL, 0);
+ stats->anon /= 1024;
+
+ len = sizeof(stats->header);
+ sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len , NULL, 0);
+ stats->header /= 1024;
+
+ len = sizeof(stats->other);
+ sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len , NULL, 0);
+ stats->other /= 1024;
+ }
+}
diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h
new file mode 100644
index 00000000..7c04bd79
--- /dev/null
+++ b/zfs/openzfs_sysctl.h
@@ -0,0 +1,18 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_openzfs
+#define HEADER_openzfs
+/*
+htop - zfs/openzfs_sysctl.h
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "zfs/ZfsArcStats.h"
+
+int openzfs_sysctl_init();
+
+void openzfs_sysctl_updateArcStats(ZfsArcStats *stats);
+
+#endif

© 2014-2024 Faster IT GmbH | imprint | privacy policy