summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/hle/kernel/k_memory_manager.cpp12
-rw-r--r--src/core/hle/kernel/k_memory_manager.h14
2 files changed, 26 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_memory_manager.cpp b/src/core/hle/kernel/k_memory_manager.cpp
index 9027602bf..aa71697b2 100644
--- a/src/core/hle/kernel/k_memory_manager.cpp
+++ b/src/core/hle/kernel/k_memory_manager.cpp
@@ -173,4 +173,16 @@ ResultCode KMemoryManager::Free(KPageLinkedList& page_list, std::size_t num_page
return RESULT_SUCCESS;
}
+std::size_t KMemoryManager::Impl::CalculateManagementOverheadSize(std::size_t region_size) {
+ const std::size_t ref_count_size = (region_size / PageSize) * sizeof(u16);
+ const std::size_t optimize_map_size =
+ (Common::AlignUp((region_size / PageSize), Common::BitSize<u64>()) /
+ Common::BitSize<u64>()) *
+ sizeof(u64);
+ const std::size_t manager_meta_size =
+ Common::AlignUp(optimize_map_size + ref_count_size, PageSize);
+ const std::size_t page_heap_size = KPageHeap::CalculateManagementOverheadSize(region_size);
+ return manager_meta_size + page_heap_size;
+}
+
} // namespace Kernel
diff --git a/src/core/hle/kernel/k_memory_manager.h b/src/core/hle/kernel/k_memory_manager.h
index 587dad178..ac840b3d0 100644
--- a/src/core/hle/kernel/k_memory_manager.h
+++ b/src/core/hle/kernel/k_memory_manager.h
@@ -60,6 +60,10 @@ public:
static constexpr std::size_t MaxManagerCount = 10;
public:
+ static std::size_t CalculateManagementOverheadSize(std::size_t region_size) {
+ return Impl::CalculateManagementOverheadSize(region_size);
+ }
+
static constexpr u32 EncodeOption(Pool pool, Direction dir) {
return (static_cast<u32>(pool) << static_cast<u32>(Pool::Shift)) |
(static_cast<u32>(dir) << static_cast<u32>(Direction::Shift));
@@ -90,6 +94,16 @@ private:
Pool pool{};
public:
+ static std::size_t CalculateManagementOverheadSize(std::size_t region_size);
+
+ static constexpr std::size_t CalculateOptimizedProcessOverheadSize(
+ std::size_t region_size) {
+ return (Common::AlignUp((region_size / PageSize), Common::BitSize<u64>()) /
+ Common::BitSize<u64>()) *
+ sizeof(u64);
+ }
+
+ public:
Impl() = default;
std::size_t Initialize(Pool new_pool, u64 start_address, u64 end_address);