MCPcopy Create free account
hub / github.com/catboost/catboost / TotalMemorySize

Method TotalMemorySize

util/system/info.cpp:272–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270}
271
272size_t NSystemInfo::TotalMemorySize() {
273#if defined(_linux_) && defined(_64_)
274 try {
275 auto q = FromString<size_t>(StripString(TFileInput("/sys/fs/cgroup/memory/memory.limit_in_bytes").ReadAll()));
276
277 if (q < (((size_t)1) << 60)) {
278 return q;
279 }
280 } catch (...) {
281 }
282#endif
283
284#if defined(_linux_) || defined(_cygwin_)
285 struct sysinfo info;
286 sysinfo(&info);
287 return info.totalram;
288#elif defined(_darwin_)
289 int mib[2];
290 int64_t memSize;
291 size_t length;
292
293 // Get the Physical memory size
294 mib[0] = CTL_HW;
295 mib[1] = HW_MEMSIZE;
296 length = sizeof(int64_t);
297 if (sysctl(mib, 2, &memSize, &length, NULL, 0) != 0) {
298 ythrow yexception() << "sysctl failed: " << LastSystemErrorText();
299 }
300 return (size_t)memSize;
301#elif defined(_win_)
302 MEMORYSTATUSEX memoryStatusEx;
303 memoryStatusEx.dwLength = sizeof(memoryStatusEx);
304 if (!GlobalMemoryStatusEx(&memoryStatusEx)) {
305 ythrow yexception() << "GlobalMemoryStatusEx failed: " << LastSystemErrorText();
306 }
307 return (size_t)memoryStatusEx.ullTotalPhys;
308#else
309 return 0;
310#endif
311}
312
313size_t NSystemInfo::MaxOpenFiles() {
314#if defined(ANDROID) || defined(__ANDROID__)

Callers

nothing calls this directly

Calls 5

StripStringFunction · 0.85
ReadAllMethod · 0.80
sysinfoClass · 0.70
LastSystemErrorTextFunction · 0.70
TFileInputClass · 0.50

Tested by

no test coverage detected