#1250: the pages that are really free (MemFree), not the reclaimable cache MemAvailable counts; false when unknown.
| 591 | |
| 592 | /// #1250: the pages that are really free (MemFree), not the reclaimable cache MemAvailable counts; false when unknown. |
| 593 | bool 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 | |
| 622 | void log_complement_memory(const char* stage, uint64_t requested) { |
| 623 | #if defined(_WIN32) |
no test coverage detected