Skip to content

Commit

Permalink
Refactor openzfs_sysctl_init() and ZfsArcMeter...
Browse files Browse the repository at this point in the history
openzfs_sysctl_init() now returns void instead of int.
The ZfsArcStats->enabled flag is set inside the init function
now, instead of having to be set from its return value.
Preparation for more flag setting in Compressed ARC commit.

ZfsArcMeter_readStats() added and all Meter->values[] setting
moved to it, eliminating duplicated code in
{darwin,freebsd,linux,solaris}/Platform.c.
  • Loading branch information
overhacked committed Sep 3, 2019
1 parent ff6914e commit e450b58
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 56 deletions.
2 changes: 1 addition & 1 deletion darwin/DarwinProcessList.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
ProcessList_getVMStats(&this->vm_stats);

/* Initialize the ZFS kstats, if zfs.kext loaded */
this->zfs.enabled = openzfs_sysctl_init();
openzfs_sysctl_init(&this->zfs);
openzfs_sysctl_updateArcStats(&this->zfs);

this->super.kernelThreads = 0;
Expand Down
13 changes: 1 addition & 12 deletions darwin/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,7 @@ void Platform_setSwapValues(Meter* mtr) {
void Platform_setZfsArcValues(Meter* this) {
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;

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->zfs.size;
ZfsArcMeter_readStats(this, &(dpl->zfs));
}

char* Platform_getProcessEnv(pid_t pid) {
Expand Down
2 changes: 1 addition & 1 deletion freebsd/FreeBSDProcessList.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui

len = 2; sysctlnametomib("vfs.bufspace", MIB_vfs_bufspace, &len);

fpl->zfs.enabled = openzfs_sysctl_init();
openzfs_sysctl_init(&fpl->zfs);
openzfs_sysctl_updateArcStats(&fpl->zfs);

int smp = 0;
Expand Down
13 changes: 1 addition & 12 deletions freebsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,7 @@ void Platform_setSwapValues(Meter* this) {
void Platform_setZfsArcValues(Meter* this) {
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl;

this->total = fpl->zfs.max;
this->values[0] = fpl->zfs.MFU;
this->values[1] = fpl->zfs.MRU;
this->values[2] = fpl->zfs.anon;
this->values[3] = fpl->zfs.header;
this->values[4] = fpl->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] = fpl->zfs.size;
ZfsArcMeter_readStats(this, &(fpl->zfs));
}

void Platform_setTasksValues(Meter* this) {
Expand Down
13 changes: 1 addition & 12 deletions linux/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,7 @@ void Platform_setSwapValues(Meter* this) {
void Platform_setZfsArcValues(Meter* this) {
LinuxProcessList* lpl = (LinuxProcessList*) this->pl;

this->total = lpl->zfs.max;
this->values[0] = lpl->zfs.MFU;
this->values[1] = lpl->zfs.MRU;
this->values[2] = lpl->zfs.anon;
this->values[3] = lpl->zfs.header;
this->values[4] = lpl->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] = lpl->zfs.size;
ZfsArcMeter_readStats(this, &(lpl->zfs));
}

char* Platform_getProcessEnv(pid_t pid) {
Expand Down
13 changes: 1 addition & 12 deletions solaris/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,7 @@ void Platform_setSwapValues(Meter* this) {
void Platform_setZfsArcValues(Meter* this) {
SolarisProcessList* spl = (SolarisProcessList*) this->pl;

this->total = spl->zfs.max;
this->values[0] = spl->zfs.MFU;
this->values[1] = spl->zfs.MRU;
this->values[2] = spl->zfs.anon;
this->values[3] = spl->zfs.header;
this->values[4] = spl->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] = spl->zfs.size;
ZfsArcMeter_readStats(this, &(spl->zfs));
}

static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) {
Expand Down
18 changes: 18 additions & 0 deletions zfs/ZfsArcMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ in the source distribution for its full text.
*/

#include "ZfsArcMeter.h"
#include "ZfsArcStats.h"

#include "CRT.h"
#include "Platform.h"
Expand All @@ -17,13 +18,30 @@ in the source distribution for its full text.
#include <assert.h>

/*{
#include "ZfsArcStats.h"
#include "Meter.h"
}*/

int ZfsArcMeter_attributes[] = {
ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER
};

void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
this->total = stats->max;
this->values[0] = stats->MFU;
this->values[1] = stats->MRU;
this->values[2] = stats->anon;
this->values[3] = stats->header;
this->values[4] = stats->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] = stats->size;
}

static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
int written;
Platform_setZfsArcValues(this);
Expand Down
4 changes: 4 additions & 0 deletions zfs/ZfsArcMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "ZfsArcStats.h"

#include "Meter.h"

extern int ZfsArcMeter_attributes[];

void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats);

extern MeterClass ZfsArcMeter_class;

#endif
6 changes: 3 additions & 3 deletions zfs/openzfs_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ static int MIB_kstat_zfs_misc_arcstats_other_size[5];
#include "zfs/ZfsArcStats.h"
}*/

int openzfs_sysctl_init() {
void openzfs_sysctl_init(ZfsArcStats *stats) {
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) {
stats->enabled = 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);
Expand All @@ -40,9 +41,8 @@ int openzfs_sysctl_init() {
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;
stats->enabled = 0;
}
}

Expand Down
6 changes: 3 additions & 3 deletions zfs/openzfs_sysctl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Do not edit this file. It was automatically generated. */

#ifndef HEADER_openzfs
#define HEADER_openzfs
#ifndef HEADER_openzfs_sysctl
#define HEADER_openzfs_sysctl
/*
htop - zfs/openzfs_sysctl.h
(C) 2014 Hisham H. Muhammad
Expand All @@ -11,7 +11,7 @@ in the source distribution for its full text.

#include "zfs/ZfsArcStats.h"

int openzfs_sysctl_init();
void openzfs_sysctl_init(ZfsArcStats *stats);

void openzfs_sysctl_updateArcStats(ZfsArcStats *stats);

Expand Down

0 comments on commit e450b58

Please sign in to comment.