The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/316

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Changed the logic used for SwapFree when swap accounting is enabled to better handle situations where memswusage is less than memusage, caused by the fuzziness of the usage_in_bytes counters used as the source.

Signed-off-by: Kellen Renshaw <kellen.rens...@canonical.com>
From 56a6b30b18aadd839a49eefb716a41d7fcda85d9 Mon Sep 17 00:00:00 2001
From: Kellen Renshaw <kellen.rens...@canonical.com>
Date: Fri, 24 Jan 2020 13:28:43 -0700
Subject: [PATCH 1/2] bindings: Adjusts the logic for calculating SwapFree to
 better handle conditions where swap usage is reported to be <0.

Signed-off-by: Kellen Renshaw <kellen.rens...@canonical.com>
---
 bindings.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bindings.c b/bindings.c
index d11f0e5..3e939f5 100644
--- a/bindings.c
+++ b/bindings.c
@@ -3599,8 +3599,8 @@ static int proc_meminfo_read(char *buf, size_t size, 
off_t offset,
                        printme = lbuf;
                } else if (startswith(line, "SwapFree:") && memswlimit > 0 && 
memswusage > 0 && opts && opts->swap_off == false) {
                        unsigned long swaptotal = memswlimit,
-                                       swapusage = memswusage - memusage,
-                                       swapfree = swapusage < swaptotal ? 
swaptotal - swapusage : 0;
+                                       swapusage = memusage > memswusage ? 0 : 
memswusage - memusage,
+                                       swapfree = swaptotal - swapusage;
                        snprintf(lbuf, 100, "SwapFree:       %8lu kB\n", 
swapfree);
                        printme = lbuf;
                } else if (startswith(line, "SwapFree:") && opts && 
opts->swap_off == true) {

From b6ae646f1fad3ac8fa5d7af114c0362b88f878f9 Mon Sep 17 00:00:00 2001
From: Kellen Renshaw <kellen.rens...@canonical.com>
Date: Fri, 24 Jan 2020 13:38:21 -0700
Subject: [PATCH 2/2] Restored the previous logic involving swaptotal, since it
 protects against swapusage > swaptotal

Signed-off-by: Kellen Renshaw <kellen.rens...@canonical.com>
---
 bindings.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bindings.c b/bindings.c
index 3e939f5..4a8a421 100644
--- a/bindings.c
+++ b/bindings.c
@@ -3600,7 +3600,7 @@ static int proc_meminfo_read(char *buf, size_t size, 
off_t offset,
                } else if (startswith(line, "SwapFree:") && memswlimit > 0 && 
memswusage > 0 && opts && opts->swap_off == false) {
                        unsigned long swaptotal = memswlimit,
                                        swapusage = memusage > memswusage ? 0 : 
memswusage - memusage,
-                                       swapfree = swaptotal - swapusage;
+                                       swapfree = swapusage < swaptotal ? 
swaptotal - swapusage : 0;
                        snprintf(lbuf, 100, "SwapFree:       %8lu kB\n", 
swapfree);
                        printme = lbuf;
                } else if (startswith(line, "SwapFree:") && opts && 
opts->swap_off == true) {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to