Merge pull request #14440 from JosJuice/optimize-remove-page

Core: Optimize RemoveHostPageTableMappings
This commit is contained in:
Dentomologist 2026-03-12 12:31:53 -07:00 committed by GitHub
commit e26b61dcee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 21 deletions

View File

@ -438,7 +438,9 @@ void MemoryManager::RemovePageTableMappings(const std::set<u32>& mappings)
switch (m_host_page_type)
{
case HostPageType::SmallPages:
return RemoveHostPageTableMappings(mappings);
for (u32 logical_address : mappings)
RemoveHostPageTableMapping(logical_address);
return;
case HostPageType::LargePages:
for (u32 logical_address : mappings)
RemoveLargePageTableMapping(logical_address);
@ -453,15 +455,7 @@ void MemoryManager::RemoveLargePageTableMapping(u32 logical_address)
RemoveLargePageTableMapping(logical_address, m_large_readable_pages);
RemoveLargePageTableMapping(logical_address, m_large_writeable_pages);
const u32 aligned_logical_address = logical_address & ~(m_page_size - 1);
const auto it = m_page_table_mapped_entries.find(aligned_logical_address);
if (it != m_page_table_mapped_entries.end())
{
const LogicalMemoryView& entry = it->second;
m_arena.UnmapFromMemoryRegion(entry.mapped_pointer, entry.mapped_size);
m_page_table_mapped_entries.erase(it);
}
RemoveHostPageTableMapping(logical_address & ~(m_page_size - 1));
}
void MemoryManager::RemoveLargePageTableMapping(u32 logical_address,
@ -472,18 +466,16 @@ void MemoryManager::RemoveLargePageTableMapping(u32 logical_address,
it->second[(logical_address & (m_page_size - 1)) / PowerPC::HW_PAGE_SIZE] = INVALID_MAPPING;
}
void MemoryManager::RemoveHostPageTableMappings(const std::set<u32>& mappings)
void MemoryManager::RemoveHostPageTableMapping(u32 logical_address)
{
if (mappings.empty())
return;
const auto it = m_page_table_mapped_entries.find(logical_address);
if (it != m_page_table_mapped_entries.end())
{
const LogicalMemoryView& entry = it->second;
m_arena.UnmapFromMemoryRegion(entry.mapped_pointer, entry.mapped_size);
std::erase_if(m_page_table_mapped_entries, [this, &mappings](const auto& pair) {
const auto& [logical_address, entry] = pair;
const bool remove = mappings.contains(logical_address);
if (remove)
m_arena.UnmapFromMemoryRegion(entry.mapped_pointer, entry.mapped_size);
return remove;
});
m_page_table_mapped_entries.erase(it);
}
}
void MemoryManager::RemoveAllPageTableMappings()

View File

@ -294,6 +294,6 @@ private:
u32 logical_size);
void RemoveLargePageTableMapping(u32 logical_address);
void RemoveLargePageTableMapping(u32 logical_address, std::map<u32, std::vector<u32>>& map);
void RemoveHostPageTableMappings(const std::set<u32>& mappings);
void RemoveHostPageTableMapping(u32 logical_address);
};
} // namespace Memory