]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
Fix wrong calc of swaptoal and swapfree
authoryuwang.yuwang <yuwang.yuwang@alibaba-inc.com>
Fri, 20 Oct 2017 06:28:03 +0000 (14:28 +0800)
committeryuwang.yuwang <yuwang.yuwang@alibaba-inc.com>
Fri, 20 Oct 2017 06:34:07 +0000 (14:34 +0800)
it make the value of (memswlimit - memlimit) to be swaptotal,
it is wrong, because swapsize in cgroup/container can up to
[0,memswlimit], sometimes if the memsize(unless swap) of all tasks in
cgroup/container is very small, the swaptoal can to be memswlimit
so make the swaptotal to be min(host swtoal,memswlimit)

Signed-off-by: yuwang.yuwang <yuwang.yuwang@alibaba-inc.com>
bindings.c

index d7c2d1da7fd067b7c6b3c6efcc35b0193d2b906c..fe521a3317625bb0e7afddc935ed399f8368ad74 100644 (file)
@@ -3169,12 +3169,12 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset,
                        printme = lbuf;
                } else if (startswith(line, "SwapTotal:") && memswlimit > 0) {
                        sscanf(line+sizeof("SwapTotal:")-1, "%lu", &hostswtotal);
-                       if (hostswtotal < memswlimit - memlimit)
-                               memswlimit = hostswtotal + memlimit;
-                       snprintf(lbuf, 100, "SwapTotal:      %8lu kB\n", memswlimit - memlimit);
+                       if (hostswtotal < memswlimit)
+                               memswlimit = hostswtotal;
+                       snprintf(lbuf, 100, "SwapTotal:      %8lu kB\n", memswlimit);
                        printme = lbuf;
                } else if (startswith(line, "SwapFree:") && memswlimit > 0 && memswusage > 0) {
-                       unsigned long swaptotal = memswlimit - memlimit,
+                       unsigned long swaptotal = memswlimit,
                                        swapusage = memswusage - memusage,
                                        swapfree = swapusage < swaptotal ? swaptotal - swapusage : 0;
                        snprintf(lbuf, 100, "SwapFree:       %8lu kB\n", swapfree);