]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
[collectd 6] port Do not account reclaimable slab as used
authorWeiping Zhang <zhangweiping@didiglobal.com>
Mon, 17 May 2021 07:59:50 +0000 (15:59 +0800)
committerMatthias Runge <mrunge@matthias-runge.de>
Fri, 10 Feb 2023 13:12:00 +0000 (14:12 +0100)
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

src/memory.c

index 439b32b37acd019a0ccffeab0b64dd74a13335c5..5752a76ce329e3c111431c7e72b3acffd6a015fd 100644 (file)
@@ -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;
   }