mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-29 09:58:05 +00:00
[TEST] Adjustment memory reclamation 2
This commit is contained in:
@@ -80,13 +80,16 @@ u64 BufferCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
||||
const u64 cold_tick =
|
||||
frame_tick > RECLAIM_GUARD_FRAMES ? frame_tick - RECLAIM_GUARD_FRAMES : 0;
|
||||
lru_cache.ForEachItemBelow(cold_tick, clean_up);
|
||||
if (freed < target_bytes) {
|
||||
if (freed == 0) {
|
||||
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, clean_up);
|
||||
}
|
||||
sentenced_buffers.Reclaim(runtime.CompletedSyncPoint());
|
||||
in_reclaim = false;
|
||||
usage_refresh_countdown = 0;
|
||||
reclaim_stalled = freed == 0;
|
||||
if (freed > 0) {
|
||||
reclaim_wait_sync_point = runtime.CurrentSyncPoint();
|
||||
}
|
||||
return freed;
|
||||
}
|
||||
|
||||
@@ -95,13 +98,19 @@ void BufferCache<P>::EnsureHeadroom(bool allow_download) {
|
||||
if (reclaim_stalled) {
|
||||
return;
|
||||
}
|
||||
if (runtime.CompletedSyncPoint() < reclaim_wait_sync_point) {
|
||||
return;
|
||||
}
|
||||
const u64 limit = memory_budget > RECLAIM_HEADROOM ? memory_budget - RECLAIM_HEADROOM : 0;
|
||||
const u64 usage = DeviceUsage(false);
|
||||
if (usage <= limit) {
|
||||
return;
|
||||
}
|
||||
const u64 target = (limit / 100) * RECLAIM_TARGET_PERCENT;
|
||||
ReclaimMemory((std::min)(usage - target, total_used_memory), allow_download);
|
||||
const u64 excess = usage - target;
|
||||
const u64 usage_mib = (std::max)(usage >> 20, u64{1});
|
||||
const u64 share = (((excess >> 20) * (total_used_memory >> 20)) / usage_mib) << 20;
|
||||
ReclaimMemory((std::min)(share, total_used_memory), allow_download);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
|
||||
@@ -191,7 +191,7 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<BufferCacheChannelInf
|
||||
static constexpr u64 FALLBACK_MEMORY_BUDGET = 2_GiB;
|
||||
static constexpr u32 USAGE_REFRESH_INTERVAL = 16;
|
||||
static constexpr u64 RECLAIM_GUARD_FRAMES = 8;
|
||||
static constexpr u64 RECLAIM_TARGET_PERCENT = 88;
|
||||
static constexpr u64 RECLAIM_TARGET_PERCENT = 95;
|
||||
|
||||
// Debug Flags.
|
||||
|
||||
@@ -519,6 +519,9 @@ private:
|
||||
u64 total_used_memory = 0;
|
||||
u64 memory_budget = 0;
|
||||
u64 cached_device_usage = 0;
|
||||
/// Sync point the last reclaim's evictions were queued at. Their memory is not back with the
|
||||
/// device until this completes, so reclaiming again before then measures stale usage.
|
||||
u64 reclaim_wait_sync_point = 0;
|
||||
u32 usage_refresh_countdown = 0;
|
||||
bool in_reclaim = false;
|
||||
bool reclaim_stalled = false;
|
||||
|
||||
@@ -211,7 +211,7 @@ u64 TextureCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
||||
const u64 cold_tick =
|
||||
frame_tick > RECLAIM_GUARD_FRAMES ? frame_tick - RECLAIM_GUARD_FRAMES : 0;
|
||||
lru_cache.ForEachItemBelow(cold_tick, evict);
|
||||
if (freed < target_bytes) {
|
||||
if (freed == 0) {
|
||||
lru_cache.ForEachItemBelow(frame_tick > 0 ? frame_tick - 1 : 0, evict);
|
||||
}
|
||||
const u64 exit_point = runtime.CompletedSyncPoint();
|
||||
@@ -221,6 +221,9 @@ u64 TextureCache<P>::ReclaimMemory(u64 target_bytes, bool allow_download) {
|
||||
in_reclaim = false;
|
||||
usage_refresh_countdown = 0;
|
||||
reclaim_stalled = freed == 0;
|
||||
if (freed > 0) {
|
||||
reclaim_wait_sync_point = runtime.CurrentSyncPoint();
|
||||
}
|
||||
return freed;
|
||||
}
|
||||
|
||||
@@ -229,13 +232,19 @@ void TextureCache<P>::EnsureHeadroom(bool allow_download) {
|
||||
if (reclaim_stalled) {
|
||||
return;
|
||||
}
|
||||
if (runtime.CompletedSyncPoint() < reclaim_wait_sync_point) {
|
||||
return;
|
||||
}
|
||||
const u64 limit = memory_budget > RECLAIM_HEADROOM ? memory_budget - RECLAIM_HEADROOM : 0;
|
||||
const u64 usage = DeviceUsage(false);
|
||||
if (usage <= limit) {
|
||||
return;
|
||||
}
|
||||
const u64 target = (limit / 100) * RECLAIM_TARGET_PERCENT;
|
||||
ReclaimMemory((std::min)(usage - target, total_used_memory), allow_download);
|
||||
const u64 excess = usage - target;
|
||||
const u64 usage_mib = (std::max)(usage >> 20, u64{1});
|
||||
const u64 share = (((excess >> 20) * (total_used_memory >> 20)) / usage_mib) << 20;
|
||||
ReclaimMemory((std::min)(share, total_used_memory), allow_download);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
|
||||
@@ -121,7 +121,7 @@ class TextureCache : public VideoCommon::ChannelSetupCaches<TextureCacheChannelI
|
||||
static constexpr u64 FALLBACK_MEMORY_BUDGET = 2_GiB;
|
||||
static constexpr u32 USAGE_REFRESH_INTERVAL = 16;
|
||||
static constexpr u64 RECLAIM_GUARD_FRAMES = 8;
|
||||
static constexpr u64 RECLAIM_TARGET_PERCENT = 88;
|
||||
static constexpr u64 RECLAIM_TARGET_PERCENT = 95;
|
||||
|
||||
using Runtime = typename P::Runtime;
|
||||
using Image = typename P::Image;
|
||||
@@ -466,6 +466,7 @@ private:
|
||||
u64 total_used_memory = 0;
|
||||
u64 memory_budget = 0;
|
||||
u64 cached_device_usage = 0;
|
||||
u64 reclaim_wait_sync_point = 0;
|
||||
u32 usage_refresh_countdown = 0;
|
||||
bool in_reclaim = false;
|
||||
bool reclaim_stalled = false;
|
||||
|
||||
@@ -1544,9 +1544,16 @@ void Device::CollectPhysicalMemoryInfo() {
|
||||
device_access_memory += mem_properties.memoryHeaps[element].size;
|
||||
}
|
||||
if (is_integrated) {
|
||||
const s64 available_memory = static_cast<s64>(device_access_memory - device_initial_usage);
|
||||
const u64 memory_size = Settings::values.vram_usage_mode.GetValue() == Settings::VramUsageMode::Aggressive ? 6_GiB : 4_GiB;
|
||||
device_access_memory = static_cast<u64>(std::max<s64>(std::min<s64>(available_memory - 8_GiB, memory_size), std::min<s64>(local_memory, memory_size)));
|
||||
const bool aggressive =
|
||||
Settings::values.vram_usage_mode.GetValue() == Settings::VramUsageMode::Aggressive;
|
||||
const s64 available_memory =
|
||||
static_cast<s64>(device_access_memory) - static_cast<s64>(device_initial_usage);
|
||||
const u64 reserve = std::min<u64>(local_memory / 8, 1_GiB);
|
||||
const u64 usable = available_memory > static_cast<s64>(reserve)
|
||||
? static_cast<u64>(available_memory) - reserve
|
||||
: 0;
|
||||
const u64 cap = (local_memory / 8) * (aggressive ? 6 : 5);
|
||||
device_access_memory = std::max<u64>(std::min<u64>(usable, cap), 1_GiB);
|
||||
} else {
|
||||
const u64 reserve_memory = std::min<u64>(device_access_memory / 8, 1_GiB);
|
||||
device_access_memory -= reserve_memory;
|
||||
|
||||
Reference in New Issue
Block a user