mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 03:18:55 +02:00
[buffer_cache] Removal of LRU inside buffer cache and replaced with tick operations inside frames.
This commit is contained in:
parent
febddbd00c
commit
ba1e137bb6
3 changed files with 17 additions and 19 deletions
|
|
@ -109,12 +109,12 @@ public:
|
||||||
return static_cast<u32>(other_cpu_addr - cpu_addr);
|
return static_cast<u32>(other_cpu_addr - cpu_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getLRUID() const noexcept {
|
u64 GetFrameTick() const noexcept {
|
||||||
return lru_id;
|
return frame_tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLRUID(size_t lru_id_) {
|
void SetFrameTick(u64 tick) noexcept {
|
||||||
lru_id = lru_id_;
|
frame_tick = tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SizeBytes() const {
|
size_t SizeBytes() const {
|
||||||
|
|
@ -125,7 +125,7 @@ private:
|
||||||
VAddr cpu_addr = 0;
|
VAddr cpu_addr = 0;
|
||||||
BufferFlagBits flags{};
|
BufferFlagBits flags{};
|
||||||
int stream_score = 0;
|
int stream_score = 0;
|
||||||
size_t lru_id = SIZE_MAX;
|
u64 frame_tick = 0;
|
||||||
size_t size_bytes = 0;
|
size_t size_bytes = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,17 +58,22 @@ void BufferCache<P>::RunGarbageCollector() {
|
||||||
const bool aggressive_gc = total_used_memory >= critical_memory;
|
const bool aggressive_gc = total_used_memory >= critical_memory;
|
||||||
const u64 ticks_to_destroy = aggressive_gc ? 60 : 120;
|
const u64 ticks_to_destroy = aggressive_gc ? 60 : 120;
|
||||||
int num_iterations = aggressive_gc ? 64 : 32;
|
int num_iterations = aggressive_gc ? 64 : 32;
|
||||||
const auto clean_up = [this, &num_iterations](BufferId buffer_id) {
|
const u64 threshold = frame_tick - ticks_to_destroy;
|
||||||
|
boost::container::small_vector<BufferId, 64> expired;
|
||||||
|
for (auto [id, buffer] : slot_buffers) {
|
||||||
|
if (buffer.GetFrameTick() < threshold) {
|
||||||
|
expired.push_back(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto buffer_id : expired) {
|
||||||
if (num_iterations == 0) {
|
if (num_iterations == 0) {
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
--num_iterations;
|
--num_iterations;
|
||||||
auto& buffer = slot_buffers[buffer_id];
|
auto& buffer = slot_buffers[buffer_id];
|
||||||
DownloadBufferMemory(buffer);
|
DownloadBufferMemory(buffer);
|
||||||
DeleteBuffer(buffer_id);
|
DeleteBuffer(buffer_id);
|
||||||
return false;
|
}
|
||||||
};
|
|
||||||
lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
|
|
@ -1595,10 +1600,9 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
||||||
const auto size = buffer.SizeBytes();
|
const auto size = buffer.SizeBytes();
|
||||||
if (insert) {
|
if (insert) {
|
||||||
total_used_memory += Common::AlignUp(size, 1024);
|
total_used_memory += Common::AlignUp(size, 1024);
|
||||||
buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick));
|
buffer.SetFrameTick(frame_tick);
|
||||||
} else {
|
} else {
|
||||||
total_used_memory -= Common::AlignUp(size, 1024);
|
total_used_memory -= Common::AlignUp(size, 1024);
|
||||||
lru_cache.Free(buffer.getLRUID());
|
|
||||||
}
|
}
|
||||||
const DAddr device_addr_begin = buffer.CpuAddr();
|
const DAddr device_addr_begin = buffer.CpuAddr();
|
||||||
const DAddr device_addr_end = device_addr_begin + size;
|
const DAddr device_addr_end = device_addr_begin + size;
|
||||||
|
|
@ -1616,7 +1620,7 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
||||||
template <class P>
|
template <class P>
|
||||||
void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept {
|
void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept {
|
||||||
if (buffer_id != NULL_BUFFER_ID) {
|
if (buffer_id != NULL_BUFFER_ID) {
|
||||||
lru_cache.Touch(buffer.getLRUID(), frame_tick);
|
buffer.SetFrameTick(frame_tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/div_ceil.h"
|
#include "common/div_ceil.h"
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
#include "common/lru_cache.h"
|
|
||||||
#include "common/range_sets.h"
|
#include "common/range_sets.h"
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
|
@ -506,11 +505,6 @@ private:
|
||||||
size_t immediate_buffer_capacity = 0;
|
size_t immediate_buffer_capacity = 0;
|
||||||
Common::ScratchBuffer<u8> immediate_buffer_alloc;
|
Common::ScratchBuffer<u8> immediate_buffer_alloc;
|
||||||
|
|
||||||
struct LRUItemParams {
|
|
||||||
using ObjectType = BufferId;
|
|
||||||
using TickType = u64;
|
|
||||||
};
|
|
||||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
|
||||||
u64 frame_tick = 0;
|
u64 frame_tick = 0;
|
||||||
u64 total_used_memory = 0;
|
u64 total_used_memory = 0;
|
||||||
u64 minimum_memory = 0;
|
u64 minimum_memory = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue