From affff43008c8105350fb7c8e27ef7cd847ec577e Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 8 Feb 2017 10:09:20 +0100 Subject: [PATCH] merge: Limit memswlimit by TotalSwap --- .../0001-Limit-memswlimit-by-TotalSwap.patch | 51 +++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 52 insertions(+) create mode 100644 debian/patches/0001-Limit-memswlimit-by-TotalSwap.patch diff --git a/debian/patches/0001-Limit-memswlimit-by-TotalSwap.patch b/debian/patches/0001-Limit-memswlimit-by-TotalSwap.patch new file mode 100644 index 0000000..b0d292f --- /dev/null +++ b/debian/patches/0001-Limit-memswlimit-by-TotalSwap.patch @@ -0,0 +1,51 @@ +From f4f2e7852fab28ec01b0634f6f2063a6e321e5e6 Mon Sep 17 00:00:00 2001 +From: Wolfgang Bumiller +Date: Thu, 2 Feb 2017 09:36:46 +0100 +Subject: [PATCH lxcfs] Limit memswlimit by TotalSwap + +We do this for the memlimit when hitting MemTotal which +means if neither is limited we end up subtracting the +hosts's total memory from the 'unlimited' swap value in the +SwapTotal and SwapFree lines. + +Signed-off-by: Wolfgang Bumiller +--- + bindings.c | 8 ++++++-- + 1 file changed, 6 insertions(+), 2 deletions(-) + +diff --git a/bindings.c b/bindings.c +index 2d4c36a..e116ff6 100644 +--- a/bindings.c ++++ b/bindings.c +@@ -3086,7 +3086,8 @@ 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, ++ hostswtotal = 0; + char *line = NULL; + size_t linelen = 0, total_len = 0, rv = 0; + char *cache = d->buf; +@@ -3148,7 +3149,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, + + memset(lbuf, 0, 100); + if (startswith(line, "MemTotal:")) { +- sscanf(line+14, "%lu", &hosttotal); ++ sscanf(line+sizeof("MemTotal:")-1, "%lu", &hosttotal); + if (hosttotal < memlimit) + memlimit = hosttotal; + snprintf(lbuf, 100, "MemTotal: %8lu kB\n", memlimit); +@@ -3160,6 +3161,9 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, + snprintf(lbuf, 100, "MemAvailable: %8lu kB\n", memlimit - memusage); + 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); + printme = lbuf; + } else if (startswith(line, "SwapFree:") && memswlimit > 0 && memswusage > 0) { +-- +2.1.4 + diff --git a/debian/patches/series b/debian/patches/series index bf650b4..bb28889 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1 +1,2 @@ do-not-start-without-lxcfs.patch +0001-Limit-memswlimit-by-TotalSwap.patch -- 2.39.2