diff --git a/receiver/JFJochReceiverRugnux.cpp b/receiver/JFJochReceiverRugnux.cpp index 49670eee1..6fd35f40b 100644 --- a/receiver/JFJochReceiverRugnux.cpp +++ b/receiver/JFJochReceiverRugnux.cpp @@ -3,6 +3,7 @@ #include "JFJochReceiverRugnux.h" +#include #include #include "spdlog/fmt/fmt.h" @@ -24,14 +25,17 @@ namespace { // rugnux plans against is decided. constexpr size_t RUGNUX_HOST_MEMORY_MARGIN = 16ULL * 1024 * 1024 * 1024; - // The host memory rugnux plans against (HostMemory.h) is the machine's budget less what the broker + // The host memory rugnux plans against (HostMemory.h) is what the machine has beside what the broker // already holds: the image buffer, which has to keep the whole collection and so is most of the - // machine, and a margin. Never 0, which would take the whole machine's budget: at worst what could - // run side by side runs one part after the other. + // machine, and a margin - at most the machine's budget. Both come off the machine's total, not off the + // budget: the budget's own fraction is the reserve for the rest of the machine, which the margin already + // keeps for the broker, and taken off twice it left nothing (1 byte) with a buffer sized to most of the + // machine. Never 0, which would take the whole machine's budget: at worst what could run side by side + // runs one part after the other. size_t RugnuxHostBudget(const ImageBuffer &buffer) { - const size_t budget = DefaultHostMemoryBudget(); + const size_t total = get_host_total_memory(); const size_t taken = buffer.GetBufferSize() + RUGNUX_HOST_MEMORY_MARGIN; - return budget > taken ? budget - taken : 1; + return total > taken ? std::min(DefaultHostMemoryBudget(), total - taken) : 1; } double SecondsSince(std::chrono::steady_clock::time_point t) {