// Verify that there is sufficient memory to satisfy the allocation\r
//\r
RemainingPages = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));\r
- if ((INTN) (RemainingPages - EFI_SIZE_TO_PAGES (sizeof (EFI_HOB_MEMORY_ALLOCATION))) < Pages) {\r
+ //\r
+ // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page.\r
+ // So the number of remaining pages needs to be greater than that of the request pages.\r
+ //\r
+ if (RemainingPages <= Pages) {\r
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));\r
DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));\r
return EFI_OUT_OF_RESOURCES;\r