[lxc-devel] [lxcfs/master] meminfo: read shmem from memory cgroup

aither64 on Github lxc-bot at linuxcontainers.org
Wed Jul 4 16:13:51 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 726 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180704/e66397f9/attachment.bin>
-------------- next part --------------
From 559eaa8f9b352105a1118c3f11be7a27c8864d36 Mon Sep 17 00:00:00 2001
From: Jakub Skokan <jakub.skokan at havefun.cz>
Date: Wed, 4 Jul 2018 17:48:52 +0200
Subject: [PATCH 1/2] meminfo: read shmem from cgroup parameter memory.stat

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 at havefun.cz>
---
 bindings.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/bindings.c b/bindings.c
index 4ecd275..f57fca7 100644
--- a/bindings.c
+++ b/bindings.c
@@ -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;
 

From 28cdea9b6be4aa51f00a76538f3748d015d6c2b6 Mon Sep 17 00:00:00 2001
From: Jakub Skokan <jakub.skokan at havefun.cz>
Date: Wed, 4 Jul 2018 17:50:30 +0200
Subject: [PATCH 2/2] meminfo: set ShmemHugePages and ShmemPmdMapped to zero

Signed-off-by: Jakub Skokan <jakub.skokan at havefun.cz>
---
 bindings.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/bindings.c b/bindings.c
index f57fca7..e0832a4 100644
--- a/bindings.c
+++ b/bindings.c
@@ -3434,6 +3434,12 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
 		} else if (startswith(line, "Shmem:")) {
 			snprintf(lbuf, 100, "Shmem:          %8lu kB\n", shmem);
 			printme = lbuf;
+		} else if (startswith(line, "ShmemHugePages")) {
+			snprintf(lbuf, 100, "ShmemHugePages: %8lu kB\n", 0UL);
+			printme = lbuf;
+		} else if (startswith(line, "ShmemPmdMapped")) {
+			snprintf(lbuf, 100, "ShmemPmdMapped: %8lu kB\n", 0UL);
+			printme = lbuf;
 		} else
 			printme = line;
 


More information about the lxc-devel mailing list