]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: serve allocations from higher-up bins if current bin is empty
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 6 Mar 2015 02:57:11 +0000 (02:57 +0000)
committerlgao4 <lgao4@Edk2>
Fri, 6 Mar 2015 02:57:11 +0000 (02:57 +0000)
This patch changes the allocation logic for the pool allocator to only
allocate additional pages if the requested allocation cannot be fulfilled
from the current bin or any of the larger ones. If there are larger blocks
available, they will be used to serve the allocation, and the remainder will
be carved up into smaller blocks using the existing carving up logic.
Note that all pool sizes are a multiple of the smallest pool size, so it is
guaranteed that the remainder will be carved up without spilling. Due to the
exponential nature of the pool sizes, the amount of work is logarithmic in
the size of the available block.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17015 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Mem/Pool.c

index 23409d35c4284e92e7ffab5d2451ae949e924a57..fd9f065dafa2a6beae417423e6fd20cfeabd4e76 100644 (file)
@@ -292,7 +292,7 @@ CoreAllocatePoolI (
   VOID        *Buffer;\r
   UINTN       Index;\r
   UINTN       FSize;\r
-  UINTN       Offset;\r
+  UINTN       Offset, MaxOffset;\r
   UINTN       NoPages;\r
   UINTN       Granularity;\r
 \r
@@ -343,6 +343,22 @@ CoreAllocatePoolI (
   //\r
   if (IsListEmpty (&Pool->FreeList[Index])) {\r
 \r
+    Offset = LIST_TO_SIZE (Index);\r
+    MaxOffset = Granularity;\r
+\r
+    //\r
+    // Check the bins holding larger blocks, and carve one up if needed\r
+    //\r
+    while (++Index < SIZE_TO_LIST (Granularity)) {\r
+      if (!IsListEmpty (&Pool->FreeList[Index])) {\r
+        Free = CR (Pool->FreeList[Index].ForwardLink, POOL_FREE, Link, POOL_FREE_SIGNATURE);\r
+        RemoveEntryList (&Free->Link);\r
+        NewPage = (VOID *) Free;\r
+        MaxOffset = LIST_TO_SIZE (Index);\r
+        goto Carve;\r
+      }\r
+    }\r
+\r
     //\r
     // Get another page\r
     //\r
@@ -354,29 +370,28 @@ CoreAllocatePoolI (
     //\r
     // Serve the allocation request from the head of the allocated block\r
     //\r
+Carve:\r
     Head = (POOL_HEAD *) NewPage;\r
-    Offset = LIST_TO_SIZE (Index);\r
 \r
     //\r
     // Carve up remaining space into free pool blocks\r
     //\r
-    Index = SIZE_TO_LIST (Granularity) - 1;\r
-    while (Offset < Granularity) {\r
+    Index--;\r
+    while (Offset < MaxOffset) {\r
       ASSERT (Index < MAX_POOL_LIST);\r
       FSize = LIST_TO_SIZE(Index);\r
 \r
-      while (Offset + FSize <= Granularity) {\r
+      while (Offset + FSize <= MaxOffset) {\r
         Free = (POOL_FREE *) &NewPage[Offset];\r
         Free->Signature = POOL_FREE_SIGNATURE;\r
         Free->Index     = (UINT32)Index;\r
         InsertHeadList (&Pool->FreeList[Index], &Free->Link);\r
         Offset += FSize;\r
       }\r
-\r
       Index -= 1;\r
     }\r
 \r
-    ASSERT (Offset == Granularity);\r
+    ASSERT (Offset == MaxOffset);\r
     goto Done;\r
   }\r
 \r