Skip to content

Commit

Permalink
Updated used memory calculation.
Browse files Browse the repository at this point in the history
Changed used memory calculation to account for shared memory in accordance with this:
KittyKatt/screenFetch#386 (comment)
  • Loading branch information
jmmweismiller committed Jan 18, 2018
1 parent 75b9ea7 commit 22f4db4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions linux/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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 ) );
}
Expand Down

0 comments on commit 22f4db4

Please sign in to comment.