]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
meminfo: read shmem from cgroup parameter memory.stat
authorJakub Skokan <jakub.skokan@havefun.cz>
Wed, 4 Jul 2018 15:48:52 +0000 (17:48 +0200)
committerJakub Skokan <jakub.skokan@havefun.cz>
Wed, 4 Jul 2018 15:54:12 +0000 (17:54 +0200)
Shmem was passed as-is from the host, but other fields weren't (such as
Cached and SReclaimed), which has caused htop to show incorrect memory usage.
If `total_shmem` is found in `memory.stat`, it is used, otherwise `Shmem`
is reported as zero.

Signed-off-by: Jakub Skokan <jakub.skokan@havefun.cz>
bindings.c

index 4ecd2753608e2302a30a26c4631d00085611d69a..f57fca7d7a081a3491f42e3fc75b12d79b7d52dd 100644 (file)
@@ -3162,7 +3162,7 @@ static bool startswith(const char *line, const char *pref)
 static void parse_memstat(char *memstat, unsigned long *cached,
                unsigned long *active_anon, unsigned long *inactive_anon,
                unsigned long *active_file, unsigned long *inactive_file,
-               unsigned long *unevictable)
+               unsigned long *unevictable, unsigned long *shmem)
 {
        char *eol;
 
@@ -3185,6 +3185,9 @@ static void parse_memstat(char *memstat, unsigned long *cached,
                } else if (startswith(memstat, "total_unevictable")) {
                        sscanf(memstat + 17, "%lu", unevictable);
                        *unevictable /= 1024;
+               } else if (startswith(memstat, "total_shmem")) {
+                       sscanf(memstat + 11, "%lu", shmem);
+                       *shmem /= 1024;
                }
                eol = strchr(memstat, '\n');
                if (!eol)
@@ -3301,7 +3304,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                *memswlimit_str = NULL, *memswusage_str = NULL;
        unsigned long memlimit = 0, memusage = 0, memswlimit = 0, memswusage = 0,
                cached = 0, hosttotal = 0, active_anon = 0, inactive_anon = 0,
-               active_file = 0, inactive_file = 0, unevictable = 0,
+               active_file = 0, inactive_file = 0, unevictable = 0, shmem = 0,
                hostswtotal = 0;
        char *line = NULL;
        size_t linelen = 0, total_len = 0, rv = 0;
@@ -3352,7 +3355,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
 
        parse_memstat(memstat_str, &cached, &active_anon,
                        &inactive_anon, &active_file, &inactive_file,
-                       &unevictable);
+                       &unevictable, &shmem);
 
        f = fopen("/proc/meminfo", "r");
        if (!f)
@@ -3428,6 +3431,9 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                } else if (startswith(line, "SUnreclaim")) {
                        snprintf(lbuf, 100, "SUnreclaim:     %8lu kB\n", 0UL);
                        printme = lbuf;
+               } else if (startswith(line, "Shmem:")) {
+                       snprintf(lbuf, 100, "Shmem:          %8lu kB\n", shmem);
+                       printme = lbuf;
                } else
                        printme = line;