[collector/slabinfo] Fix pagesize not defined in non-x86 arches (#6897)
* [collector/slabinfo] Fix pagesize not defined in non-x86 arches Fixes #6896 : Fail to build on raspberry pi Some arches does not export PAGE_SIZE in sys/user.h Changed constant to static var fetched from POSIX sysconf(_SC_PAGESIZE)
Adrien Mahieux committed
Sep 20, 2019 at 12:47 UTC
46c4b8809cad6a0dc65d91e54429e8a7a581c5a2
1 file changed
+7
-8
collectors/slabinfo.plugin/slabinfo.c
+7
-8
@@ -3,9 +3,6 @@
3
#include "libnetdata/libnetdata.h"
4
#include "daemon/common.h"
5
6
-// For PAGE_SIZE
7
-#include <sys/user.h>
8
-
6
#define PLUGIN_SLABINFO_NAME "slabinfo.plugin"
7
#define PLUGIN_SLABINFO_PROCFILE "/proc/slabinfo"
8
@@ -13,10 +10,6 @@
10
#define CHART_FAMILY "slab"
11
#define CHART_PRIO 3000
12
16
-// As we're talking about kernel-pagesize, there's no hugepage.
17
-// So it's reliable to use it as an arch constant
18
-#define SLAB_PAGE_SIZE PAGE_SIZE
19
-
13
// #define slabdebug(...) if (debug) { fprintf(stderr, __VA_ARGS__); }
14
#define slabdebug(args...) if (debug) { \
15
fprintf(stderr, "slabinfo.plugin DEBUG (%04d@%-10.10s:%-15.15s)::", __LINE__, __FILE__, __FUNCTION__); \
@@ -170,6 +163,12 @@ struct slabinfo *read_file_slabinfo() {
163
slabdebug("-> Reading procfile %s", PLUGIN_SLABINFO_PROCFILE);
164
165
static procfile *ff = NULL;
166
+ static long slab_pagesize = 0;
167
+
168
+ if (unlikely(!slab_pagesize)) {
169
+ slab_pagesize = sysconf(_SC_PAGESIZE);
170
+ slabdebug(" Discovered pagesize: %ld", slab_pagesize);
171
+ }
172
173
if(unlikely(!ff)) {
174
ff = procfile_reopen(ff, PLUGIN_SLABINFO_PROCFILE, " ,:" , PROCFILE_FLAG_DEFAULT);
@@ -213,7 +212,7 @@ struct slabinfo *read_file_slabinfo() {
212
s->data_num_slabs = str2uint64_t(procfile_lineword(ff, l, 12));
213
s->data_shared_avail = str2uint64_t(procfile_lineword(ff, l, 13));
214
216
- uint32_t memperslab = s->pages_per_slab * SLAB_PAGE_SIZE;
215
+ uint32_t memperslab = s->pages_per_slab * slab_pagesize;
216
// Internal fragmentation: loss per slab, due to objects not being a multiple of pagesize
217
//uint32_t lossperslab = memperslab - s->obj_per_slab * s->obj_size;
218