diff options
author | Adrien Mahieux <adrien.mahieux@gmail.com> | 2019-09-20 12:47:47 +0200 |
---|---|---|
committer | Markos Fountoulakis <44345837+mfundul@users.noreply.github.com> | 2019-09-20 13:47:47 +0300 |
commit | 46c4b8809cad6a0dc65d91e54429e8a7a581c5a2 (patch) | |
tree | 40cd1575222ff922e5e46bb285e7f2daef14be07 /collectors/slabinfo.plugin | |
parent | 5d479b67c3080fd39c1ffc6d0db67c6946fc7536 (diff) |
[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)
Diffstat (limited to 'collectors/slabinfo.plugin')
-rw-r--r-- | collectors/slabinfo.plugin/slabinfo.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/collectors/slabinfo.plugin/slabinfo.c b/collectors/slabinfo.plugin/slabinfo.c index 96ea813c58..b92bc8ac2f 100644 --- a/collectors/slabinfo.plugin/slabinfo.c +++ b/collectors/slabinfo.plugin/slabinfo.c @@ -3,9 +3,6 @@ #include "libnetdata/libnetdata.h" #include "daemon/common.h" -// For PAGE_SIZE -#include <sys/user.h> - #define PLUGIN_SLABINFO_NAME "slabinfo.plugin" #define PLUGIN_SLABINFO_PROCFILE "/proc/slabinfo" @@ -13,10 +10,6 @@ #define CHART_FAMILY "slab" #define CHART_PRIO 3000 -// As we're talking about kernel-pagesize, there's no hugepage. -// So it's reliable to use it as an arch constant -#define SLAB_PAGE_SIZE PAGE_SIZE - // #define slabdebug(...) if (debug) { fprintf(stderr, __VA_ARGS__); } #define slabdebug(args...) if (debug) { \ fprintf(stderr, "slabinfo.plugin DEBUG (%04d@%-10.10s:%-15.15s)::", __LINE__, __FILE__, __FUNCTION__); \ @@ -170,6 +163,12 @@ struct slabinfo *read_file_slabinfo() { slabdebug("-> Reading procfile %s", PLUGIN_SLABINFO_PROCFILE); static procfile *ff = NULL; + static long slab_pagesize = 0; + + if (unlikely(!slab_pagesize)) { + slab_pagesize = sysconf(_SC_PAGESIZE); + slabdebug(" Discovered pagesize: %ld", slab_pagesize); + } if(unlikely(!ff)) { ff = procfile_reopen(ff, PLUGIN_SLABINFO_PROCFILE, " ,:" , PROCFILE_FLAG_DEFAULT); @@ -213,7 +212,7 @@ struct slabinfo *read_file_slabinfo() { s->data_num_slabs = str2uint64_t(procfile_lineword(ff, l, 12)); s->data_shared_avail = str2uint64_t(procfile_lineword(ff, l, 13)); - uint32_t memperslab = s->pages_per_slab * SLAB_PAGE_SIZE; + uint32_t memperslab = s->pages_per_slab * slab_pagesize; // Internal fragmentation: loss per slab, due to objects not being a multiple of pagesize //uint32_t lossperslab = memperslab - s->obj_per_slab * s->obj_size; |