[buffer_cache] Add batching support for memory tracker updates (#3288)

I added a batching/ coalescing of ranges in WordManager to reduce calls per pages in UpdatePagesCachedCount, also a test to verify if FlushCachedWrites coalesced (reduces callings to UpdatePagesCachedCount) callings and register each of them to inspect them.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3288
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Reviewed-by: DraVee <dravee@eden-emu.dev>
Co-authored-by: CamilleLaVey <camillelavey99@gmail.com>
Co-committed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
CamilleLaVey
2026-01-18 03:48:09 +01:00
committed by crueter
parent 51cc1bc6be
commit 1a9b4b37e1
4 changed files with 155 additions and 6 deletions
+13 -1
View File
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -9,6 +12,7 @@
#include <deque>
#include <memory>
#include <mutex>
#include <vector>
#include "common/common_types.h"
#include "common/range_mutex.h"
@@ -44,6 +48,7 @@ public:
~DeviceMemoryManager();
static constexpr bool HAS_FLUSH_INVALIDATION = true;
static constexpr size_t AS_BITS = Traits::device_virtual_bits;
void BindInterface(DeviceInterface* device_inter);
@@ -117,7 +122,12 @@ public:
void UpdatePagesCachedCount(DAddr addr, size_t size, s32 delta);
static constexpr size_t AS_BITS = Traits::device_virtual_bits;
// New batch API to update multiple ranges with a single lock acquisition.
void UpdatePagesCachedBatch(const std::vector<std::pair<DAddr, size_t>>& ranges, s32 delta);
private:
// Internal helper that performs the update assuming the caller already holds the necessary lock.
void UpdatePagesCachedCountNoLock(DAddr addr, size_t size, s32 delta);
private:
static constexpr size_t device_virtual_bits = Traits::device_virtual_bits;
@@ -214,6 +224,8 @@ private:
std::unique_ptr<CachedPages> cached_pages;
Common::RangeMutex counter_guard;
std::mutex mapping_guard;
};
} // namespace Core