about summary refs log tree commit diff
path: root/users/multi/pkgs/htop/zfs-arc-cache/0001-Linux-consider-ZFS-ARC-to-be-cache.patch
blob: 50b2abd2b803d2ea46e3cf044dae0d48b10c8cc1 (plain) (blame)
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
From d1dadae5674222a0134092b3313383e088deda89 Mon Sep 17 00:00:00 2001
From: multiplexd <multi@in-addr.xyz>
Date: Sat, 9 May 2020 20:13:09 +0100
Subject: [PATCH] Linux: consider ZFS ARC to be cache

---
 ProcessList.c            |  1 +
 ProcessList.h            |  1 +
 linux/LinuxProcessList.c | 27 +++++++++++++++++++++++++++
 linux/LinuxProcessList.h |  4 ++++
 linux/Platform.c         |  5 +++--
 5 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/ProcessList.c b/ProcessList.c
index 7482b03..7083957 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -67,6 +67,7 @@ typedef struct ProcessList_ {
    unsigned long long int totalSwap;
    unsigned long long int usedSwap;
    unsigned long long int freeSwap;
+   unsigned long long int arcSize;
 
    int cpuCount;
 
diff --git a/ProcessList.h b/ProcessList.h
index 572d484..65029f1 100644
--- a/ProcessList.h
+++ b/ProcessList.h
@@ -61,6 +61,7 @@ typedef struct ProcessList_ {
    unsigned long long int totalSwap;
    unsigned long long int usedSwap;
    unsigned long long int freeSwap;
+   unsigned long long int arcSize;
 
    int cpuCount;
 
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 5f38540..507ebd2 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -104,6 +104,10 @@ typedef struct LinuxProcessList_ {
 #define PROCSTATFILE PROCDIR "/stat"
 #endif
 
+#ifndef ARCSTATFILE
+#define ARCSTATFILE PROCDIR "/spl/kstat/zfs/arcstats"
+#endif
+
 #ifndef PROCMEMINFOFILE
 #define PROCMEMINFOFILE PROCDIR "/meminfo"
 #endif
@@ -962,6 +966,29 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
    this->cachedMem = this->cachedMem + sreclaimable - shmem;
    this->usedSwap = this->totalSwap - swapFree;
    fclose(file);
+
+   file = fopen(ARCSTATFILE, "r");
+   if (file == NULL && errno != ENOENT) {
+      CRT_fatalError("Cannot open " ARCSTATFILE);
+   }
+
+   if (file != NULL) {
+      // skip the first two lines
+      fgets(buffer, sizeof buffer, file);
+      fgets(buffer, sizeof buffer, file);
+
+      unsigned long long int arcsize = 0;
+      while (fgets(buffer, sizeof buffer, file)) {
+         #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*d %llu", variable)) { break; } } while(0)
+         if (buffer[0] == 's') tryRead("size", &arcsize);
+      }
+
+      this->arcSize = arcsize / 1024;
+
+      fclose(file);
+   } else {
+      this->arcSize = 0;
+   }
 }
 
 static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h
index f30b487..8f2edbb 100644
--- a/linux/LinuxProcessList.h
+++ b/linux/LinuxProcessList.h
@@ -77,6 +77,10 @@ typedef struct LinuxProcessList_ {
 #define PROCSTATFILE PROCDIR "/stat"
 #endif
 
+#ifndef ARCSTATFILE
+#define ARCSTATFILE PROCDIR "/spl/kstat/zfs/arcstats"
+#endif
+
 #ifndef PROCMEMINFOFILE
 #define PROCMEMINFOFILE PROCDIR "/meminfo"
 #endif
diff --git a/linux/Platform.c b/linux/Platform.c
index ab90ca7..fb78c4c 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -200,11 +200,12 @@ void Platform_setMemoryValues(Meter* this) {
    long int usedMem = pl->usedMem;
    long int buffersMem = pl->buffersMem;
    long int cachedMem = pl->cachedMem;
-   usedMem -= buffersMem + cachedMem;
+   long int arcSize = pl->arcSize;
+   usedMem -= buffersMem + cachedMem + arcSize;
    this->total = pl->totalMem;
    this->values[0] = usedMem;
    this->values[1] = buffersMem;
-   this->values[2] = cachedMem;
+   this->values[2] = cachedMem + arcSize;
 }
 
 void Platform_setSwapValues(Meter* this) {
-- 
2.20.1