From: Weiping Zhang Date: Mon, 17 May 2021 07:59:50 +0000 (+0800) Subject: [collectd 6] port Do not account reclaimable slab as used X-Git-Tag: 6.0.0-rc0~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65ac979bc0082a38dae62b7c72ac45fc33b5b0c2;p=thirdparty%2Fcollectd.git [collectd 6] port Do not account reclaimable slab as used This ports "Do not account reclaimable slab as used" (77e2fcd91e27) from the main branch to collectd-6.0 ChangeLog: memory plugin: do not account reclaimable slab as used. Align this counter with free(1). https://gitlab.com/procps-ng/procps/-/blob/v3.3.17/proc/sysinfo.c#L789 --- diff --git a/src/memory.c b/src/memory.c index 439b32b37..5752a76ce 100644 --- a/src/memory.c +++ b/src/memory.c @@ -429,7 +429,6 @@ static int memory_read_internal(gauge_t values[COLLECTD_MEMORY_TYPE_MAX]) { mem_not_used += v; } else if (strcmp(fields[0], "Slab:") == 0) { values[COLLECTD_MEMORY_TYPE_SLAB_TOTAL] = v; - mem_not_used += v; } else if (strcmp(fields[0], "SReclaimable:") == 0) { values[COLLECTD_MEMORY_TYPE_SLAB_RECL] = v; } else if (strcmp(fields[0], "SUnreclaim:") == 0) { @@ -443,6 +442,15 @@ static int memory_read_internal(gauge_t values[COLLECTD_MEMORY_TYPE_MAX]) { WARNING("memory plugin: fclose failed: %s", STRERRNO); } + /* If SReclaimable (introduced in kernel 2.6.19) is available count it + * (but not SUnreclaim) towards the unused memory. + * If we do not have detailed slab info count the total as unused. */ + if (!isnan(values[COLLECTD_MEMORY_TYPE_SLAB_RECL])) { + mem_not_used += values[COLLECTD_MEMORY_TYPE_SLAB_RECL]; + } else if (!isnan(values[COLLECTD_MEMORY_TYPE_SLAB_TOTAL])) { + mem_not_used += values[COLLECTD_MEMORY_TYPE_SLAB_TOTAL]; + } + if (isnan(mem_total) || (mem_total == 0) || (mem_total < mem_not_used)) { return EINVAL; }