MCPcopy Create free account
hub / github.com/Niko1221/Strata / free_memory_bytes

Function free_memory_bytes

engine/src/core/expert_source.cpp:593–620  ·  view source on GitHub ↗

#1250: the pages that are really free (MemFree), not the reclaimable cache MemAvailable counts; false when unknown.

Source from the content-addressed store, hash-verified

591
592/// #1250: the pages that are really free (MemFree), not the reclaimable cache MemAvailable counts; false when unknown.
593bool free_memory_bytes(uint64_t& bytes) {
594#if defined(__linux__)
595 std::ifstream info("/proc/meminfo");
596 if (!info) return false;
597 std::stringstream text;
598 text << info.rdbuf();
599 bytes = detail::meminfo_bytes(text.str(), "MemFree");
600 if (bytes == 0) return false;
601 // 0.1.42: a multi-socket host's nodes each have their own free pages; judge by the emptiest one too
602 std::vector<uint64_t> nodes;
603 for (int n = 0; n < 64; ++n) {
604 std::ifstream node("/sys/devices/system/node/node" + std::to_string(n) + "/meminfo");
605 if (!node) break;
606 std::string line;
607 while (std::getline(node, line)) {
608 std::istringstream f(line);
609 std::string a, id, key;
610 uint64_t kb = 0;
611 if (f >> a >> id >> key >> kb && key == "MemFree:") { nodes.push_back(kb * 1024); break; }
612 }
613 }
614 bytes = detail::numa_pin_free(bytes, nodes);
615 return bytes > 0;
616#else
617 bytes = 0;
618 return false;
619#endif
620}
621
622void log_complement_memory(const char* stage, uint64_t requested) {
623#if defined(_WIN32)

Callers 1

pin_cache_complementMethod · 0.85

Calls 5

numa_pin_freeFunction · 0.85
push_backMethod · 0.80
meminfo_bytesFunction · 0.70
to_stringFunction · 0.50
strMethod · 0.45

Tested by

no test coverage detected