Skip to content

Commit 19e2c99

Browse files
authored
Merge pull request #671 from asainkujovic/excludesrecl
meminfo: Add slab_reclaimable to MemAvailable
2 parents 341c43c + abdecf1 commit 19e2c99

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/proc_fuse.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct memory_stat {
6363
uint64_t total_inactive_file;
6464
uint64_t total_active_file;
6565
uint64_t total_unevictable;
66+
uint64_t slab;
67+
uint64_t slab_reclaimable;
68+
uint64_t slab_unreclaimable;
6669
};
6770

6871
static off_t get_procfile_size(const char *path)
@@ -1368,6 +1371,12 @@ static bool cgroup_parse_memory_stat(const char *cgroup, struct memory_stat *mst
13681371
sscanf(line, unified ? "active_file %" PRIu64 : "total_active_file %" PRIu64, &(mstat->total_active_file));
13691372
} else if (startswith(line, unified ? "unevictable" : "total_unevictable")) {
13701373
sscanf(line, unified ? "unevictable %" PRIu64 : "total_unevictable %" PRIu64, &(mstat->total_unevictable));
1374+
} else if (unified && startswith(line, "slab ")) {
1375+
sscanf(line, "slab %" PRIu64, &(mstat->slab));
1376+
} else if (unified && startswith(line, "slab_reclaimable")) {
1377+
sscanf(line, "slab_reclaimable %" PRIu64, &(mstat->slab_reclaimable));
1378+
} else if (unified && startswith(line, "slab_unreclaimable")) {
1379+
sscanf(line, "slab_unreclaimable %" PRIu64, &(mstat->slab_unreclaimable));
13711380
}
13721381
}
13731382

@@ -1464,7 +1473,8 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
14641473
snprintf(lbuf, 100, "MemFree: %8" PRIu64 " kB\n", memlimit - memusage);
14651474
printme = lbuf;
14661475
} else if (startswith(line, "MemAvailable:")) {
1467-
snprintf(lbuf, 100, "MemAvailable: %8" PRIu64 " kB\n", memlimit - memusage + (mstat.total_active_file + mstat.total_inactive_file) / 1024);
1476+
snprintf(lbuf, 100, "MemAvailable: %8" PRIu64 " kB\n", memlimit - memusage +
1477+
(mstat.total_active_file + mstat.total_inactive_file + mstat.slab_reclaimable) / 1024);
14681478
printme = lbuf;
14691479
} else if (startswith(line, "SwapTotal:")) {
14701480
if (wants_swap) {
@@ -1499,7 +1509,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
14991509
snprintf(lbuf, 100, "SwapFree: %8" PRIu64 " kB\n", swfree);
15001510
printme = lbuf;
15011511
} else if (startswith(line, "Slab:")) {
1502-
snprintf(lbuf, 100, "Slab: %8" PRIu64 " kB\n", (uint64_t)0);
1512+
snprintf(lbuf, 100, "Slab: %8" PRIu64 " kB\n", mstat.slab / 1024);
15031513
printme = lbuf;
15041514
} else if (startswith(line, "Buffers:")) {
15051515
snprintf(lbuf, 100, "Buffers: %8" PRIu64 " kB\n", (uint64_t)0);
@@ -1562,10 +1572,10 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
15621572
mstat.total_mapped_file / 1024);
15631573
printme = lbuf;
15641574
} else if (startswith(line, "SReclaimable:")) {
1565-
snprintf(lbuf, 100, "SReclaimable: %8" PRIu64 " kB\n", (uint64_t)0);
1575+
snprintf(lbuf, 100, "SReclaimable: %8" PRIu64 " kB\n", mstat.slab_reclaimable / 1024);
15661576
printme = lbuf;
15671577
} else if (startswith(line, "SUnreclaim:")) {
1568-
snprintf(lbuf, 100, "SUnreclaim: %8" PRIu64 " kB\n", (uint64_t)0);
1578+
snprintf(lbuf, 100, "SUnreclaim: %8" PRIu64 " kB\n", mstat.slab_unreclaimable / 1024);
15691579
printme = lbuf;
15701580
} else if (startswith(line, "Shmem:")) {
15711581
snprintf(lbuf, 100, "Shmem: %8" PRIu64 " kB\n",

0 commit comments

Comments
 (0)