July 4, 2021


Allocating Memory Above 2GB

Some UEFI implementations, notably those based on IP from AMI, have a limitation on the amount of memory available for allocation via the gBS->AllocatePool and gBS->AllocatePages(AllocateAnyAddress, ...) APIs. Specifically they won't allow allocation of any memory above about 2GB, regardless of allocation size. Furthermore, some implementations (such as on the ASUS Z170) appear to have a catastrophic failure whereby if a module causes the system to run out of memory under 2GB the system subsequently becomes unbootable and must be recovered using the ASUS Flashback feature, or RMA'd. On other AMI-based systems, the system just locks up and can be successfully rebooted (ASUS Z97), while some others fail the request and return NULL.

The 2GB restriction comes about because memory in the range 2-4GB is used for MMIO and so cannot be used for general allocations. I don't know why they won't allocate above 4GB once they run out of memory below that though.

A way to workaround this is to use gBS->GetMemoryMap and look for entries of type EfiConventionalMemory of the required size: these can be allocated using gBS->AllocatePages(AllocateAddress, ...).

© Rebecca Cran 2022