Browse Source

Align all physical pages to page size

remotes/1785372757367212240/tmp_refs/heads/variable-page-size
Exverge 2 months ago
parent
commit
5858998e35
No known key found for this signature in database GPG Key ID: DAD399BCC5FB77E4
  1. 17
      src/core/hle/kernel/k_memory_manager.cpp
  2. 2
      src/core/hle/kernel/k_page_table_base.cpp

17
src/core/hle/kernel/k_memory_manager.cpp

@ -212,10 +212,8 @@ KPhysicalAddress KMemoryManager::AllocateAndOpenContinuous(size_t num_pages, siz
return 0;
}
// todo: find a better way to do this
if (align_pages % Common::GuestHostAlignment != 0) {
align_pages = Common::AlignUp(align_pages, Common::GuestHostAlignment);
}
// todo: does this waste too much space?
align_pages = Common::AlignUp(align_pages, Common::GuestHostAlignment);
// Lock the pool that we're allocating from.
const auto [pool, dir] = DecodeOption(option);
@ -253,6 +251,9 @@ KPhysicalAddress KMemoryManager::AllocateAndOpenContinuous(size_t num_pages, siz
Result KMemoryManager::AllocatePageGroupImpl(KPageGroup* out, size_t num_pages, Pool pool,
Direction dir, bool unoptimized, bool random) {
// todo: does this waste too much space?
num_pages = Common::AlignUp(num_pages, Common::GuestHostAlignment);
// Choose a heap based on our page size request.
const s32 heap_index = KPageHeap::GetBlockIndex(num_pages);
R_UNLESS(0 <= heap_index, ResultOutOfMemory);
@ -275,7 +276,13 @@ Result KMemoryManager::AllocatePageGroupImpl(KPageGroup* out, size_t num_pages,
cur_manager = this->GetNextManager(cur_manager, dir)) {
while (num_pages >= pages_per_alloc) {
// Allocate a block.
KPhysicalAddress allocated_block = cur_manager->AllocateBlock(index, random);
KPhysicalAddress allocated_block = 0;
if (random) {
allocated_block = cur_manager->AllocateAligned(index, pages_per_alloc, Common::GuestHostAlignment);
} else {
// TODO: linear search support for Aligned?
allocated_block = cur_manager->AllocateBlock(index, random);
}
if (allocated_block == 0) {
break;
}

2
src/core/hle/kernel/k_page_table_base.cpp

@ -5755,7 +5755,7 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
ASSERT(this->IsLockedByCurrentThread());
ASSERT(Common::IsAligned(GetInteger(virt_addr), PageSize));
ASSERT(num_pages > 0);
ASSERT(num_pages == page_group.GetNumPages());
ASSERT(Common::AlignUp(num_pages, Common::GuestHostAlignment) == page_group.GetNumPages());
// As we don't allocate page entries in guest memory, we don't need to allocate them from
// the page list, and so it goes unused (along with page properties).

Loading…
Cancel
Save