1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-379 - changed to make the check for mem available for dynamic

This commit is contained in:
david hill
2017-05-30 15:12:50 -05:00
parent 9c7434ba52
commit 2cc5fc7195

View File

@ -173,6 +173,9 @@ uint64_t CGroupConfigurator::getTotalMemory()
{ {
uint64_t ret; uint64_t ret;
if (totalMemory != 0)
return totalMemory;
if (!cGroupDefined) if (!cGroupDefined)
ret = getTotalMemoryFromProc(); ret = getTotalMemoryFromProc();
else { else {
@ -180,11 +183,7 @@ uint64_t CGroupConfigurator::getTotalMemory()
if (ret == 0) if (ret == 0)
ret = getTotalMemoryFromProc(); ret = getTotalMemoryFromProc();
} }
//ostringstream os; //cout << "Total mem available is " << ret << endl;
//os << "Total mem available is " << ret;
//cerr << os.str() << endl;
//log(logging::LOG_TYPE_WARNING, os.str());
totalMemory = ret; totalMemory = ret;
return totalMemory; return totalMemory;
} }
@ -217,31 +216,17 @@ uint64_t CGroupConfigurator::getTotalMemoryFromProc()
input[79] = '\0'; input[79] = '\0';
pclose(cmdPipe); pclose(cmdPipe);
memTot = atoi(input); memTot = atoi(input);
//ostringstream os;
//os << "FreeBSD Total mem available is " << memTot;
//cerr << os.str() << endl;
//log(logging::LOG_TYPE_WARNING, os.str());
#else #else
ifstream in("/proc/meminfo"); ifstream in("/proc/meminfo");
string x; string x;
in >> x; in >> x;
in >> memTot; in >> memTot;
//ostringstream os;
//os << "meminfo Total mem available is " << memTot;
//cerr << os.str() << endl;
//log(logging::LOG_TYPE_WARNING, os.str());
#endif #endif
//memTot is now in KB, convert to bytes //memTot is now in KB, convert to bytes
memTot *= 1024; memTot *= 1024;
//os << "meminfo Total bytes mem available is " << memTot;
//cerr << os.str() << endl;
//log(logging::LOG_TYPE_WARNING, os.str());
return memTot; return memTot;
} }
@ -322,24 +307,26 @@ uint64_t CGroupConfigurator::getMemUsageFromCGroup()
uint64_t CGroupConfigurator::getFreeMemoryFromProc() uint64_t CGroupConfigurator::getFreeMemoryFromProc()
{ {
uint64_t memFree = 0; uint64_t memFree = 0;
uint64_t memAvailable = 0; uint64_t buffers = 0;
uint64_t cached = 0;
uint64_t memTotal = 0; uint64_t memTotal = 0;
uint64_t memAvailable = 0;
#if defined(_MSC_VER) #if defined(_MSC_VER)
MEMORYSTATUSEX memStat; MEMORYSTATUSEX memStat;
memStat.dwLength = sizeof(memStat); memStat.dwLength = sizeof(memStat);
if (GlobalMemoryStatusEx(&memStat)) if (GlobalMemoryStatusEx(&memStat))
{ {
memFree = memStat.ullAvailPhys; memAvailable = memStat.ullAvailPhys;
#ifndef _WIN64 #ifndef _WIN64
uint64_t tmp = getTotalMemoryFromProc(); uint64_t tmp = getTotalMemoryFromProc();
if (memFree > tmp) if (memFree > tmp)
memFree = tmp; memAvailable = tmp;
#endif #endif
} }
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
// FreeBSD is not supported, no optimization. // FreeBSD is not supported, no optimization.
memFree = 0; memAvailable = 0;
#else #else
ifstream in("/proc/meminfo"); ifstream in("/proc/meminfo");
string x; string x;
@ -352,10 +339,22 @@ uint64_t CGroupConfigurator::getFreeMemoryFromProc()
in >> memFree; in >> memFree;
in >> x; // kB in >> x; // kB
in >> x; // MemAvailable: //check if available or buffers is passed
in >> memAvailable; in >> x;
in >> x; // kB if ( x == "MemAvailable:")
{
in >> memAvailable; // MemAvailable
}
else
{ // centos 6 and older OSs
in >> buffers;
in >> x; // kB
in >> x; // Cached:
in >> cached;
memAvailable = memFree + buffers + cached;
}
#endif #endif
// amount available for application // amount available for application