From: qhuang8 Date: Fri, 22 Dec 2006 08:11:47 +0000 (+0000) Subject: Optimize to preallocate big bigs to avoid latter allocations. X-Git-Tag: edk2-stable201903~23746 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=e2d56e0a59f2788df11d02c96433e908d9f414b4 Optimize to preallocate big bigs to avoid latter allocations. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2131 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c b/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c index 78134564e5..609fea2eca 100644 --- a/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c +++ b/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c @@ -69,12 +69,8 @@ Returns: PAGE_MAP_AND_DIRECTORY_POINTER *PageMap; PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry; PAGE_TABLE_ENTRY *PageDirectoryEntry; - - // - // By architecture only one PageMapLevel4 exists - so lets allocate storage for it. - // - PageMap = AllocatePages (1); - ASSERT (PageMap != NULL); + UINTN TotalPagesNum; + UINTN BigPageAddress; // // Get physical address bits supported. @@ -98,6 +94,19 @@ Returns: NumberOfPdpEntriesNeeded = 512; } + // + // Pre-allocate big pages to avoid later allocations. + // + TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1; + BigPageAddress = (UINTN) AllocatePages (TotalPagesNum); + ASSERT (BigPageAddress != 0); + + // + // By architecture only one PageMapLevel4 exists - so lets allocate storage for it. + // + PageMap = (VOID *) BigPageAddress; + BigPageAddress += EFI_PAGE_SIZE; + PageMapLevel4Entry = PageMap; PageAddress = 0; for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) { @@ -105,8 +114,8 @@ Returns: // Each PML4 entry points to a page of Page Directory Pointer entires. // So lets allocate space for them and fill them in in the IndexOfPdpEntries loop. // - PageDirectoryPointerEntry = AllocatePages (1); - ASSERT (PageDirectoryPointerEntry != NULL); + PageDirectoryPointerEntry = (VOID *) BigPageAddress; + BigPageAddress += EFI_PAGE_SIZE; // // Make a PML4 Entry @@ -120,8 +129,8 @@ Returns: // Each Directory Pointer entries points to a page of Page Directory entires. // So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop. // - PageDirectoryEntry = AllocatePages (1); - ASSERT (PageDirectoryEntry != NULL); + PageDirectoryEntry = (VOID *) BigPageAddress; + BigPageAddress += EFI_PAGE_SIZE; // // Fill in a Page Directory Pointer Entries