Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions MdeModulePkg/Core/Pei/Memory/MemoryServices.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,20 @@ PeiAllocatePages (
}
}

if (!PrivateData->PeiMemoryInstalled && (PrivateData->FreeMemorySearchHintCount != 0)) {
// Reuse temporary-memory pages before consuming the limited free-memory top.
Status = FindFreeMemoryFromMemoryAllocationHob (
(CONST EFI_PEI_SERVICES **)PeiServices,
MemoryType,
ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity)),
Granularity,
Memory
);
if (!EFI_ERROR (Status)) {
return Status;
}
}

//
// We will attempt up to two times here.
// If we don't have memory bins, we will only attempt to allocate from the PHIT.
Expand Down Expand Up @@ -849,6 +863,9 @@ PeiAllocatePages (
Padding & ~(UINTN)EFI_PAGE_MASK,
EfiConventionalMemory
);
if (!PrivateData->PeiMemoryInstalled && (PrivateData->FreeMemorySearchHintCount < MAX_UINTN)) {
PrivateData->FreeMemorySearchHintCount++;
}
}

//
Expand Down Expand Up @@ -1051,6 +1068,10 @@ PeiFreePages (
if (MemoryAllocationHob != NULL) {
UpdateOrSplitMemoryAllocationHob (PeiServices, MemoryAllocationHob, Memory, Bytes, EfiConventionalMemory);
FreeMemoryAllocationHob (PrivateData, MemoryAllocationHob);
if (!PrivateData->PeiMemoryInstalled && (PrivateData->FreeMemorySearchHintCount < MAX_UINTN)) {
PrivateData->FreeMemorySearchHintCount++;
}

return EFI_SUCCESS;
} else {
return EFI_NOT_FOUND;
Expand Down
5 changes: 5 additions & 0 deletions MdeModulePkg/Core/Pei/PeiMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ struct _PEI_CORE_INSTANCE {
// This is used for the memory bin feature, if enabled, to track bin locations.
//
EFI_MEMORY_TYPE_STATISTICS *MemoryTypeStatistics;

///
/// Count pre-memory events that may produce reusable conventional-memory ranges.
///
UINTN FreeMemorySearchHintCount;
};

///
Expand Down
Loading
Loading