mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-15 08:53:51 +00:00
world loading memory pressure detector
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
This commit is contained in:
parent
4b9b3026f4
commit
312994be83
4 changed files with 42 additions and 1 deletions
|
|
@ -126,5 +126,12 @@ bool MemoryMonitor::isMemoryPressure() const {
|
|||
return available < (totalRAM_ * 10 / 100);
|
||||
}
|
||||
|
||||
bool MemoryMonitor::isSevereMemoryPressure() const {
|
||||
size_t available = getAvailableRAM();
|
||||
// Severe pressure if < 15% RAM available — background workers should
|
||||
// pause entirely to avoid OOM-killing other applications.
|
||||
return available < (totalRAM_ * 15 / 100);
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace wowee
|
||||
|
|
|
|||
|
|
@ -1212,6 +1212,28 @@ void TerrainManager::workerLoop() {
|
|||
break;
|
||||
}
|
||||
|
||||
// --- Memory-aware throttling ---
|
||||
// Back-pressure: if the ready queue is deep (finalization can't
|
||||
// keep up), or the system is running low on RAM, sleep instead
|
||||
// of pulling more tiles. Each prepared tile can hold hundreds
|
||||
// of MB of decoded textures; limiting concurrency here prevents
|
||||
// WoWee from consuming all system memory during world load.
|
||||
const auto& memMon = core::MemoryMonitor::getInstance();
|
||||
if (memMon.isSevereMemoryPressure()) {
|
||||
// Severe pressure — don't pull ANY work until main thread
|
||||
// finalizes tiles and frees decoded texture data.
|
||||
lock.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
continue;
|
||||
}
|
||||
if (readyQueue.size() >= maxReadyQueueSize_ || memMon.isMemoryPressure()) {
|
||||
// Moderate pressure or ready queue is backing up — sleep briefly
|
||||
// to let the main thread catch up with finalization.
|
||||
lock.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!loadQueue.empty()) {
|
||||
coord = loadQueue.front();
|
||||
loadQueue.pop_front();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue