Hi Experts,

We are using the 'AllocateAlignedPages' function (inside 
'MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c')
to allocate 512MB aligned memory chunk in a DXE driver.

However the memory chunk which gets allocated by this API is around 1GB.

I understand that this might be  because of the memory fragmentation, as a 
result of which allocating
the 512MB aligned buffer might result in memory chunk being allocated be 
greater in size than 512MB.

Are we using the right API for the purpose - is there another API available 
which allows alignment to specified
more granularly? 

Here is the 'AllocateAlignedPages' function which calls 
'InternalAllocateAlignedPages' internally.

/**
  Allocates one or more 4KB pages of type EfiBootServicesData at a specified 
alignment.

  Allocates the number of 4KB pages specified by Pages of type 
EfiBootServicesData with an
  alignment specified by Alignment.  The allocated buffer is returned.  If 
Pages is 0, then NULL is
  returned.  If there is not enough memory at the specified alignment remaining 
to satisfy the
  request, then NULL is returned.
  
  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
  If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().

  @param  Pages                 The number of 4 KB pages to allocate.
  @param  Alignment             The requested alignment of the allocation.  
Must be a power of two.
                                If Alignment is zero, then byte alignment is 
used.

  @return A pointer to the allocated buffer or NULL if allocation fails.

**/
VOID *
EFIAPI
AllocateAlignedPages (
  IN UINTN  Pages,
  IN UINTN  Alignment
  )
{
  return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);
}

...

/**
  Allocates one or more 4KB pages of a certain memory type at a specified 
alignment.

  Allocates the number of 4KB pages specified by Pages of a certain memory type 
with an alignment
  specified by Alignment.  The allocated buffer is returned.  If Pages is 0, 
then NULL is returned.
  If there is not enough memory at the specified alignment remaining to satisfy 
the request, then
  NULL is returned.
  If Alignment is not a power of two and Alignment is not zero, then ASSERT().
  If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().

  @param  MemoryType            The type of memory to allocate.
  @param  Pages                 The number of 4 KB pages to allocate.
  @param  Alignment             The requested alignment of the allocation.  
Must be a power of two.
                                If Alignment is zero, then byte alignment is 
used.

  @return A pointer to the allocated buffer or NULL if allocation fails.

**/
VOID *
InternalAllocateAlignedPages (
  IN EFI_MEMORY_TYPE  MemoryType,  
  IN UINTN            Pages,
  IN UINTN            Alignment
  )

...

Thanks for the help.

Regards,
Bhupesh
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to