2019-07-07 23:27:00 +00:00
|
|
|
/*
|
2021-03-02 23:59:28 +00:00
|
|
|
htop - generic/openzfs_sysctl.c
|
2019-07-07 23:27:00 +00:00
|
|
|
(C) 2014 Hisham H. Muhammad
|
2021-09-22 09:33:00 +00:00
|
|
|
Released under the GNU GPLv2+, see the COPYING file
|
2019-07-07 23:27:00 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2021-03-02 23:59:28 +00:00
|
|
|
#include "generic/openzfs_sysctl.h"
|
2019-07-07 23:27:00 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2020-11-18 14:12:18 +00:00
|
|
|
#include <sys/types.h> // IWYU pragma: keep
|
|
|
|
#include <sys/sysctl.h> // needs <sys/types.h> for u_int with gcc
|
|
|
|
|
|
|
|
#include "zfs/ZfsArcStats.h"
|
|
|
|
|
2019-07-07 23:27:00 +00:00
|
|
|
|
|
|
|
static int MIB_kstat_zfs_misc_arcstats_size[5];
|
2022-05-29 19:10:26 +00:00
|
|
|
static int MIB_kstat_zfs_misc_arcstats_c_min[5];
|
2019-07-07 23:27:00 +00:00
|
|
|
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];
|
2019-09-03 18:26:02 +00:00
|
|
|
static int MIB_kstat_zfs_misc_arcstats_compressed_size[5];
|
|
|
|
static int MIB_kstat_zfs_misc_arcstats_uncompressed_size[5];
|
2019-07-07 23:27:00 +00:00
|
|
|
|
2020-10-31 22:28:02 +00:00
|
|
|
void openzfs_sysctl_init(ZfsArcStats* stats) {
|
2019-07-07 23:27:00 +00:00
|
|
|
size_t len;
|
|
|
|
unsigned long long int arcSize;
|
|
|
|
|
|
|
|
len = sizeof(arcSize);
|
2020-10-20 11:14:32 +00:00
|
|
|
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) {
|
2020-10-31 21:14:27 +00:00
|
|
|
stats->enabled = 1;
|
2019-07-07 23:27:00 +00:00
|
|
|
|
2020-10-31 21:14:27 +00:00
|
|
|
len = 5;
|
|
|
|
sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
|
|
|
|
|
2022-05-29 19:10:26 +00:00
|
|
|
sysctlnametomib("kstat.zfs.misc.arcstats.c_min", MIB_kstat_zfs_misc_arcstats_c_min, &len);
|
2020-10-31 21:14:27 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) {
|
|
|
|
stats->isCompressed = 1;
|
|
|
|
sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len);
|
|
|
|
} else {
|
|
|
|
stats->isCompressed = 0;
|
|
|
|
}
|
2019-07-07 23:27:00 +00:00
|
|
|
} else {
|
2019-09-03 18:21:33 +00:00
|
|
|
stats->enabled = 0;
|
2019-07-07 23:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 22:28:02 +00:00
|
|
|
void openzfs_sysctl_updateArcStats(ZfsArcStats* stats) {
|
2019-07-07 23:27:00 +00:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (stats->enabled) {
|
|
|
|
len = sizeof(stats->size);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->size /= 1024;
|
|
|
|
|
2022-05-29 19:10:26 +00:00
|
|
|
len = sizeof(stats->min);
|
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_c_min, 5, &(stats->min), &len, NULL, 0);
|
|
|
|
stats->min /= 1024;
|
|
|
|
|
2019-07-07 23:27:00 +00:00
|
|
|
len = sizeof(stats->max);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->max /= 1024;
|
|
|
|
|
|
|
|
len = sizeof(stats->MFU);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->MFU /= 1024;
|
|
|
|
|
|
|
|
len = sizeof(stats->MRU);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->MRU /= 1024;
|
|
|
|
|
|
|
|
len = sizeof(stats->anon);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->anon /= 1024;
|
|
|
|
|
|
|
|
len = sizeof(stats->header);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->header /= 1024;
|
|
|
|
|
|
|
|
len = sizeof(stats->other);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len, NULL, 0);
|
2019-07-07 23:27:00 +00:00
|
|
|
stats->other /= 1024;
|
2019-09-03 18:26:02 +00:00
|
|
|
|
|
|
|
if (stats->isCompressed) {
|
|
|
|
len = sizeof(stats->compressed);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_compressed_size, 5, &(stats->compressed), &len, NULL, 0);
|
2019-09-03 18:26:02 +00:00
|
|
|
stats->compressed /= 1024;
|
|
|
|
|
|
|
|
len = sizeof(stats->uncompressed);
|
2020-10-31 22:28:02 +00:00
|
|
|
sysctl(MIB_kstat_zfs_misc_arcstats_uncompressed_size, 5, &(stats->uncompressed), &len, NULL, 0);
|
2019-09-03 18:26:02 +00:00
|
|
|
stats->uncompressed /= 1024;
|
|
|
|
}
|
2019-07-07 23:27:00 +00:00
|
|
|
}
|
|
|
|
}
|