Commit 3e1b7395 authored by Chuck Atkins's avatar Chuck Atkins Committed by Brad King

SystemInformation: Ignore buffers and cache when reporting host memory use

Change-Id: I694df81c1c62bd538ef02cb2846b6932870dbefe
parent 9fe15333
......@@ -3569,33 +3569,44 @@ SystemInformationImplementation::GetHostMemoryUsed()
return (statex.ullTotalPhys - statex.ullAvailPhys)/1024;
# endif
#elif defined(__linux)
const char *names[3]={"MemTotal:","MemFree:",NULL};
SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)};
int ierr=GetFieldsFromFile("/proc/meminfo",names,values);
// First try to use MemAvailable, but it only works on newer kernels
const char *names2[3]={"MemTotal:","MemAvailable:",NULL};
SystemInformation::LongLong values2[2]={SystemInformation::LongLong(0)};
int ierr=GetFieldsFromFile("/proc/meminfo",names2,values2);
if (ierr)
{
return ierr;
}
SystemInformation::LongLong &memTotal=values[0];
SystemInformation::LongLong &memFree=values[1];
return memTotal - memFree;
const char *names4[5]={"MemTotal:","MemFree:","Buffers:","Cached:",NULL};
SystemInformation::LongLong values4[4]={SystemInformation::LongLong(0)};
ierr=GetFieldsFromFile("/proc/meminfo",names4,values4);
if(ierr)
{
return ierr;
}
SystemInformation::LongLong &memTotal=values4[0];
SystemInformation::LongLong &memFree=values4[1];
SystemInformation::LongLong &memBuffers=values4[2];
SystemInformation::LongLong &memCached=values4[3];
return memTotal - memFree - memBuffers - memCached;
}
SystemInformation::LongLong &memTotal=values2[0];
SystemInformation::LongLong &memAvail=values2[1];
return memTotal - memAvail;
#elif defined(__APPLE__)
SystemInformation::LongLong psz=getpagesize();
if (psz<1)
{
return -1;
}
const char *names[4]={"Pages active:","Pages inactive:","Pages wired down:",NULL};
SystemInformation::LongLong values[3]={SystemInformation::LongLong(0)};
const char *names[3]={"Pages wired down:","Pages active:",NULL};
SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)};
int ierr=GetFieldsFromCommand("vm_stat", names, values);
if (ierr)
{
return -1;
}
SystemInformation::LongLong &vmActive=values[0];
SystemInformation::LongLong &vmInactive=values[1];
SystemInformation::LongLong &vmWired=values[2];
return ((vmActive+vmInactive+vmWired)*psz)/1024;
SystemInformation::LongLong &vmWired=values[0];
SystemInformation::LongLong &vmActive=values[1];
return ((vmActive+vmWired)*psz)/1024;
#else
return 0;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment