summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2024-07-07 16:53:20 +0300
committerAustin S. Hemmelgarn <ahferroin7@gmail.com>2024-07-10 08:47:30 -0400
commit98a627adafca0e79f21a3124b13c5fbc1d649c18 (patch)
tree671adda3121901f8ee045520a0b9cb67c67bfe07
parentb49e6d39aa9aa5a04ba439228c4a2871be23e81f (diff)
proc: collect ksm/swap/cma/zswap only when feature enabled (#18076)
(cherry picked from commit 54d05d31ab80f72506c14a84ca6848fe7d832ddd)
-rw-r--r--src/collectors/proc.plugin/plugin_proc.c61
-rw-r--r--src/collectors/proc.plugin/plugin_proc.h4
-rw-r--r--src/collectors/proc.plugin/proc_meminfo.c16
-rw-r--r--src/collectors/proc.plugin/proc_vmstat.c7
4 files changed, 77 insertions, 11 deletions
diff --git a/src/collectors/proc.plugin/plugin_proc.c b/src/collectors/proc.plugin/plugin_proc.c
index 8ae4aace50..095cd73891 100644
--- a/src/collectors/proc.plugin/plugin_proc.c
+++ b/src/collectors/proc.plugin/plugin_proc.c
@@ -102,6 +102,9 @@ static void proc_main_cleanup(void *pptr)
}
bool inside_lxc_container = false;
+bool is_mem_swap_enabled = false;
+bool is_mem_zswap_enabled = false;
+bool is_mem_ksm_enabled = false;
static bool is_lxcfs_proc_mounted() {
procfile *ff = NULL;
@@ -136,6 +139,61 @@ static bool is_lxcfs_proc_mounted() {
return false;
}
+static bool is_ksm_enabled() {
+ unsigned long long ksm_run = 0;
+
+ char filename[FILENAME_MAX + 1];
+ snprintfz(filename, FILENAME_MAX, "%s/sys/kernel/mm/ksm/run", netdata_configured_host_prefix);
+
+ return !read_single_number_file(filename, &ksm_run) && ksm_run == 1;
+}
+
+static bool is_zswap_enabled() {
+ char filename[FILENAME_MAX + 1];
+ snprintfz(filename, FILENAME_MAX, "/sys/module/zswap/parameters/enabled"); // host prefix is not needed here
+ char state[1 + 1]; // Y or N
+
+ int ret = read_txt_file(filename, state, sizeof(state));
+
+ return !ret && !strcmp(state, "Y");
+}
+
+static bool is_swap_enabled() {
+ char filename[FILENAME_MAX + 1];
+ snprintfz(filename, FILENAME_MAX, "%s/proc/meminfo", netdata_configured_host_prefix);
+
+ procfile *ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
+ if (!ff) {
+ return false;
+ }
+
+ ff = procfile_readall(ff);
+ if (!ff) {
+ procfile_close(ff);
+ return false;
+ }
+
+ unsigned long long swap_total = 0;
+
+ size_t lines = procfile_lines(ff), l;
+
+ for (l = 0; l < lines; l++) {
+ size_t words = procfile_linewords(ff, l);
+ if (words < 2)
+ continue;
+
+ const char *key = procfile_lineword(ff, l, 0);
+ if (strcmp(key, "SwapTotal") == 0) {
+ swap_total = str2ull(procfile_lineword(ff, l, 1), NULL);
+ break;
+ }
+ }
+
+ procfile_close(ff);
+
+ return swap_total > 0;
+}
+
static bool log_proc_module(BUFFER *wb, void *data) {
struct proc_module *pm = data;
buffer_sprintf(wb, "proc.plugin[%s]", pm->name);
@@ -174,6 +232,9 @@ void *proc_main(void *ptr)
heartbeat_init(&hb);
inside_lxc_container = is_lxcfs_proc_mounted();
+ is_mem_swap_enabled = is_swap_enabled();
+ is_mem_zswap_enabled = is_zswap_enabled();
+ is_mem_ksm_enabled = is_ksm_enabled();
#define LGS_MODULE_ID 0
diff --git a/src/collectors/proc.plugin/plugin_proc.h b/src/collectors/proc.plugin/plugin_proc.h
index 25b9e3a941..a5f7ce6ec4 100644
--- a/src/collectors/proc.plugin/plugin_proc.h
+++ b/src/collectors/proc.plugin/plugin_proc.h
@@ -53,6 +53,10 @@ int get_numa_node_count(void);
extern unsigned long long zfs_arcstats_shrinkable_cache_size_bytes;
extern bool inside_lxc_container;
+extern bool is_mem_swap_enabled;
+extern bool is_mem_zswap_enabled;
+extern bool is_mem_ksm_enabled;
+
// netdev renames
void cgroup_rename_task_add(
const char *host_device,
diff --git a/src/collectors/proc.plugin/proc_meminfo.c b/src/collectors/proc.plugin/proc_meminfo.c
index 4421d05897..c11b4f6422 100644
--- a/src/collectors/proc.plugin/proc_meminfo.c
+++ b/src/collectors/proc.plugin/proc_meminfo.c
@@ -101,18 +101,18 @@ int do_proc_meminfo(int update_every, usec_t dt) {
;
if(unlikely(!arl_base)) {
- do_ram = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "system ram", 1);
+ do_ram = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "system ram", CONFIG_BOOLEAN_YES);
do_swap = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "system swap", CONFIG_BOOLEAN_AUTO);
do_hwcorrupt = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "hardware corrupted ECC", CONFIG_BOOLEAN_AUTO);
- do_committed = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "committed memory", 1);
- do_writeback = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "writeback memory", 1);
- do_kernel = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "kernel memory", 1);
- do_slab = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "slab memory", 1);
+ do_committed = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "committed memory", CONFIG_BOOLEAN_YES);
+ do_writeback = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "writeback memory", CONFIG_BOOLEAN_YES);
+ do_kernel = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "kernel memory", CONFIG_BOOLEAN_YES);
+ do_slab = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "slab memory", CONFIG_BOOLEAN_YES);
do_hugepages = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "hugepages", CONFIG_BOOLEAN_AUTO);
do_transparent_hugepages = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "transparent hugepages", CONFIG_BOOLEAN_AUTO);
do_reclaiming = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "memory reclaiming", CONFIG_BOOLEAN_AUTO);
do_high_low = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "high low memory", CONFIG_BOOLEAN_AUTO);
- do_cma = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "cma memory", CONFIG_BOOLEAN_AUTO);
+ do_cma = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "cma memory", CONFIG_BOOLEAN_AUTO);
do_directmap = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_MEMINFO, "direct maps", CONFIG_BOOLEAN_AUTO);
// https://github.com/torvalds/linux/blob/master/fs/proc/meminfo.c
@@ -285,7 +285,7 @@ int do_proc_meminfo(int update_every, usec_t dt) {
rrdset_done(st_mem_swap_cached);
}
- if(arl_zswapped->flags & ARL_ENTRY_FLAG_FOUND) {
+ if (is_mem_zswap_enabled && (arl_zswapped->flags & ARL_ENTRY_FLAG_FOUND)) {
static RRDSET *st_mem_zswap = NULL;
static RRDDIM *rd_zswap = NULL, *rd_zswapped = NULL;
@@ -673,7 +673,7 @@ int do_proc_meminfo(int update_every, usec_t dt) {
rrdset_done(st_mem_high_low);
}
- if(do_cma == CONFIG_BOOLEAN_YES || (do_cma == CONFIG_BOOLEAN_AUTO && (arl_cma_total->flags & ARL_ENTRY_FLAG_FOUND) && CmaTotal)) {
+ if (CmaTotal && do_cma != CONFIG_BOOLEAN_NO) {
do_cma = CONFIG_BOOLEAN_YES;
static RRDSET *st_mem_cma = NULL;
diff --git a/src/collectors/proc.plugin/proc_vmstat.c b/src/collectors/proc.plugin/proc_vmstat.c
index 7b43fe25b3..050086689f 100644
--- a/src/collectors/proc.plugin/proc_vmstat.c
+++ b/src/collectors/proc.plugin/proc_vmstat.c
@@ -10,6 +10,7 @@
#define _COMMON_PLUGIN_MODULE_NAME PLUGIN_PROC_MODULE_VMSTAT_NAME
#include "../common-contexts/common-contexts.h"
+
int do_proc_vmstat(int update_every, usec_t dt) {
(void)dt;
@@ -262,7 +263,7 @@ int do_proc_vmstat(int update_every, usec_t dt) {
// --------------------------------------------------------------------
- if (do_swapio == CONFIG_BOOLEAN_YES || do_swapio == CONFIG_BOOLEAN_AUTO) {
+ if (is_mem_swap_enabled && (do_swapio == CONFIG_BOOLEAN_YES || do_swapio == CONFIG_BOOLEAN_AUTO)) {
do_swapio = CONFIG_BOOLEAN_YES;
static RRDSET *st_swapio = NULL;
@@ -465,7 +466,7 @@ int do_proc_vmstat(int update_every, usec_t dt) {
// --------------------------------------------------------------------
- if (do_zswapio == CONFIG_BOOLEAN_YES || do_zswapio == CONFIG_BOOLEAN_AUTO) {
+ if (is_mem_zswap_enabled && (do_zswapio == CONFIG_BOOLEAN_YES || do_zswapio == CONFIG_BOOLEAN_AUTO)) {
do_zswapio = CONFIG_BOOLEAN_YES;
static RRDSET *st_zswapio = NULL;
@@ -498,7 +499,7 @@ int do_proc_vmstat(int update_every, usec_t dt) {
// --------------------------------------------------------------------
- if (do_ksm == CONFIG_BOOLEAN_YES || do_ksm == CONFIG_BOOLEAN_AUTO) {
+ if (is_mem_ksm_enabled && (do_ksm == CONFIG_BOOLEAN_YES || do_ksm == CONFIG_BOOLEAN_AUTO)) {
do_ksm = CONFIG_BOOLEAN_YES;
static RRDSET *st_ksm_cow = NULL;