]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
pbx.c: Include filesystem cache in free memory calculation
authorSean Bright <sean.bright@gmail.com>
Thu, 16 Jan 2020 13:32:34 +0000 (08:32 -0500)
committerSean Bright <sean.bright@gmail.com>
Thu, 16 Jan 2020 18:38:09 +0000 (12:38 -0600)
ASTERISK-28695 #close
Reported by: Kevin Flyn

Change-Id: Ief098bb6eb77378daeace8f97ba30701c8de55b8

doc/CHANGES-staging/minmemfree.txt [new file with mode: 0644]
main/pbx.c

diff --git a/doc/CHANGES-staging/minmemfree.txt b/doc/CHANGES-staging/minmemfree.txt
new file mode 100644 (file)
index 0000000..5762c15
--- /dev/null
@@ -0,0 +1,5 @@
+Subject: minmemfree
+
+The 'minmemfree' configuration option now counts memory allocated to
+the filesystem cache as "free" because it is memory that is available
+to the process.
index 872d67413de768fc3c7ab2caff930c824b0f52a6..f7b813b66a8831e3c49c62dfaaf9b0201a863f7a 100644 (file)
@@ -4614,7 +4614,6 @@ static int increase_call_count(const struct ast_channel *c)
        int failed = 0;
        double curloadavg;
 #if defined(HAVE_SYSINFO)
-       long curfreemem;
        struct sysinfo sys_info;
 #endif
 
@@ -4634,13 +4633,16 @@ static int increase_call_count(const struct ast_channel *c)
        }
 #if defined(HAVE_SYSINFO)
        if (option_minmemfree) {
+               /* Make sure that the free system memory is above the configured low watermark */
                if (!sysinfo(&sys_info)) {
-                       /* make sure that the free system memory is above the configured low watermark
-                        * convert the amount of freeram from mem_units to MB */
-                       curfreemem = sys_info.freeram * sys_info.mem_unit;
+                       /* Convert the amount of available RAM from mem_units to MB. The calculation
+                        * was done this way to avoid overflow problems */
+                       uint64_t curfreemem = sys_info.freeram + sys_info.bufferram;
+                       curfreemem *= sys_info.mem_unit;
                        curfreemem /= 1024 * 1024;
                        if (curfreemem < option_minmemfree) {
-                               ast_log(LOG_WARNING, "Available system memory (~%ldMB) is below the configured low watermark (%ldMB)\n", curfreemem, option_minmemfree);
+                               ast_log(LOG_WARNING, "Available system memory (~%" PRIu64 "MB) is below the configured low watermark (%ldMB)\n",
+                                       curfreemem, option_minmemfree);
                                failed = -1;
                        }
                }