[lxc-devel] [lxcfs/master] proc_fuse: fix swap calculations
brauner on Github
lxc-bot at linuxcontainers.org
Tue Mar 24 09:05:48 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 425 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200324/4c24e48a/attachment-0001.bin>
-------------- next part --------------
From 157231ab2af99bfd94d345d1e6955e9b8de48d8e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 24 Mar 2020 10:03:06 +0100
Subject: [PATCH] proc_fuse: fix swap calculations
The sscanf() line got removed on accident.
Closes #384.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/proc_fuse.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 4cec492..7851e03 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -1071,13 +1071,14 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
if (ret >= 0) {
memswlimit = get_min_memlimit(cgroup, true);
memswlimit = memswlimit / 1024;
+
if (safe_uint64(memswusage_str, &memswusage, 10) < 0)
lxcfs_error("Failed to convert memswusage %s", memswusage_str);
memswusage = memswusage / 1024;
}
if (safe_uint64(memusage_str, &memusage, 10) < 0)
- lxcfs_error("Failed to convert memusage %s", memswusage_str);
+ lxcfs_error("Failed to convert memusage %s", memusage_str);
memlimit /= 1024;
memusage /= 1024;
@@ -1103,10 +1104,16 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
snprintf(lbuf, 100, "MemAvailable: %8" PRIu64 " kB\n", memlimit - memusage + mstat.total_cache / 1024);
printme = lbuf;
} else if (startswith(line, "SwapTotal:") && memswlimit > 0 && opts && opts->swap_off == false) {
- snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n",
- (memswlimit >= memlimit)
- ? (memswlimit - memlimit)
- : 0);
+ uint64_t hostswtotal = 0;
+
+ sscanf(line + STRLITERALLEN("SwapTotal:"), "%" PRIu64, &hostswtotal);
+ if (hostswtotal < memswlimit)
+ memswlimit = hostswtotal;
+
+ if (memswlimit >= memlimit)
+ memswlimit -= memlimit;
+
+ snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", memswlimit);
printme = lbuf;
} else if (startswith(line, "SwapTotal:") && opts && opts->swap_off == true) {
snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", (uint64_t)0);
More information about the lxc-devel
mailing list