From 22f4db4b0e304c37326577da610abee9e5539ebb Mon Sep 17 00:00:00 2001 From: John Weismiller Date: Thu, 18 Jan 2018 13:15:18 -0600 Subject: [PATCH] Updated used memory calculation. Changed used memory calculation to account for shared memory in accordance with this: https://github.com/KittyKatt/screenFetch/issues/386#issuecomment-249312716 --- linux/memory.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/linux/memory.cc b/linux/memory.cc index f6ac406..4bcc295 100644 --- a/linux/memory.cc +++ b/linux/memory.cc @@ -40,7 +40,7 @@ void mem_status( MemoryStatus & status ) * application requests memory. * In order to calculate the ram that's actually used we need to use the * following formula: - * total_ram - free_ram - buffered_ram - cached_ram + * total_ram + shmem - free_ram - buffered_ram - cached_ram - srclaimable * * example data, junk removed, with comments added: * @@ -72,8 +72,13 @@ void mem_status( MemoryStatus & status ) { used_mem = total_mem - stoi( line.substr( substr_start, substr_len ) ); } + else if( substr.compare( "Shmem" ) == 0 ) + { + used_mem += stoi( line.substr( substr_start, substr_len ) ); + } else if( substr.compare( "Buffers" ) == 0 || - substr.compare( "Cached" ) == 0 ) + substr.compare( "Cached" ) == 0 || + substr.compare( "SReclaimable" ) == 0 ) { used_mem -= stoi( line.substr( substr_start, substr_len ) ); }