From 3acaf2653e56a95d97523f7e553b3987b1ebfe96 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Tue, 13 Jun 2017 13:34:17 +0200 Subject: [PATCH 1/3] src/driver/pictureviewer/pictureviewer.cpp add bufferram and cached to calc freemem Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/1f0a1bfdf25ba4f489d5e738940fab66ec1a5d61 Author: Jacek Jendrzej Date: 2017-06-13 (Tue, 13 Jun 2017) Origin message was: ------------------ src/driver/pictureviewer/pictureviewer.cpp add bufferram and cached to calc freemem --- src/driver/pictureviewer/pictureviewer.cpp | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index f93779996..6c4ed8f42 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -854,12 +854,38 @@ unsigned char * CPictureViewer::ResizeA(unsigned char *orgin, int ox, int oy, in return int_Resize(orgin, ox, oy, dx, dy, COLOR, NULL, true); } +static size_t getCachedMemSize(void) +{ + FILE *procmeminfo = fopen("/proc/meminfo", "r"); + size_t cached = 0; + if (procmeminfo) { + char buf[80] = {0}, a[80] = {0}; + size_t v = 0; + while (fgets(buf, sizeof(buf), procmeminfo)) { + char unit[10]; + *unit = 0; + if ((3 == sscanf(buf, "%[^:]: %llu %s", a, &v, unit)) + || (2 == sscanf(buf, "%[^:]: %llu", a, &v))) { + if (*unit == 'k') + v <<= 10; + if (!strcasecmp(a, "Cached")){ + cached = v; + break; + } + } + } + fclose(procmeminfo); + } + return cached; +} + bool CPictureViewer::checkfreemem(size_t bufsize) { struct sysinfo info; sysinfo( &info ); - if(bufsize + 4096 > (size_t)info.freeram + (size_t)info.freeswap){ - dprintf(DEBUG_NORMAL, "[CPictureViewer] [%s - %d] Error: Out of memory: need %zu > free %zu\n", __func__, __LINE__,bufsize,(size_t)info.freeram + (size_t)info.freeswap); + size_t cached = getCachedMemSize(); + if(bufsize + sysconf(_SC_PAGESIZE) > (size_t)info.freeram + (size_t)info.freeswap + (size_t)info.bufferram + cached){ + dprintf(DEBUG_NORMAL, "[CPictureViewer] [%s - %d] Error: Out of memory: need %zu > free %zu\n", __func__, __LINE__,bufsize,(size_t)info.freeram + (size_t)info.freeswap + (size_t)info.bufferram + cached); return false; } return true; From 336aa4f1faaf1aac512397c0680bf5a66a867ca9 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Tue, 13 Jun 2017 14:23:56 +0200 Subject: [PATCH 2/3] supplement to 3acaf2653e56a95d97523f7e553b3987b1ebfe96 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/30b1c3f286e7b634f6f17b79838285ca24a94b31 Author: Jacek Jendrzej Date: 2017-06-13 (Tue, 13 Jun 2017) --- src/driver/pictureviewer/pictureviewer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index 6c4ed8f42..f3a1a03a0 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -860,7 +860,7 @@ static size_t getCachedMemSize(void) size_t cached = 0; if (procmeminfo) { char buf[80] = {0}, a[80] = {0}; - size_t v = 0; + long long unsigned int v = 0; while (fgets(buf, sizeof(buf), procmeminfo)) { char unit[10]; *unit = 0; From ee3c3bb2681f23c84f722021d678aa2f106200fd Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Tue, 13 Jun 2017 14:30:37 +0200 Subject: [PATCH 3/3] 2 supplement to 3acaf2653e56a95d97523f7e553b3987b1ebfe96 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/85cff28f07a7e7e36db210f80b3b63a585577ca6 Author: Jacek Jendrzej Date: 2017-06-13 (Tue, 13 Jun 2017) --- src/driver/pictureviewer/pictureviewer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index f3a1a03a0..90947fe39 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -860,12 +860,12 @@ static size_t getCachedMemSize(void) size_t cached = 0; if (procmeminfo) { char buf[80] = {0}, a[80] = {0}; - long long unsigned int v = 0; + size_t v = 0; while (fgets(buf, sizeof(buf), procmeminfo)) { char unit[10]; *unit = 0; - if ((3 == sscanf(buf, "%[^:]: %llu %s", a, &v, unit)) - || (2 == sscanf(buf, "%[^:]: %llu", a, &v))) { + if ((3 == sscanf(buf, "%[^:]: %zu %s", a, &v, unit)) + || (2 == sscanf(buf, "%[^:]: %zu", a, &v))) { if (*unit == 'k') v <<= 10; if (!strcasecmp(a, "Cached")){