]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: improve scalability of memory pools
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 6 Mar 2015 02:54:50 +0000 (02:54 +0000)
committerlgao4 <lgao4@Edk2>
Fri, 6 Mar 2015 02:54:50 +0000 (02:54 +0000)
The existing linear mapping between allocation size and pool index
does not scale when moving to a 64 KB granularity or beyond. With
a granularity of 64 KB, 2048 (!) bins will be created for each
memory type, each differing 32 bytes in size with the next one.

Instead, introduce an exponential scheme where each bin size is
the sum of the two previous ones.

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@17012 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Mem/Pool.c

index f99293da5c51a2eb7dd04b565102f02e548658af..c7998e80cce695412064cd8971dadd96bb16e45c 100644 (file)
@@ -41,19 +41,24 @@ typedef struct {
   UINTN       Size;\r
 } POOL_TAIL;\r
 \r
-\r
-#define POOL_SHIFT  7\r
-\r
 #define POOL_OVERHEAD (SIZE_OF_POOL_HEAD + sizeof(POOL_TAIL))\r
 \r
 #define HEAD_TO_TAIL(a)   \\r
   ((POOL_TAIL *) (((CHAR8 *) (a)) + (a)->Size - sizeof(POOL_TAIL)));\r
 \r
+//\r
+// Each element is the sum of the 2 previous ones: this allows us to migrate\r
+// blocks between bins by splitting them up, while not wasting too much memory\r
+// as we would in a strict power-of-2 sequence\r
+//\r
+STATIC CONST UINT16 mPoolSizeTable[] = {\r
+  64, 128, 192, 320, 512, 832, 1344, 2176, 3520, 5696, 9216, 14912, 24128\r
+};\r
 \r
-#define SIZE_TO_LIST(a)   ((a) >> POOL_SHIFT)\r
-#define LIST_TO_SIZE(a)   ((a+1) << POOL_SHIFT)\r
+#define SIZE_TO_LIST(a)   (GetPoolIndexFromSize (a))\r
+#define LIST_TO_SIZE(a)   (mPoolSizeTable [a])\r
 \r
-#define MAX_POOL_LIST       SIZE_TO_LIST(DEFAULT_PAGE_ALLOCATION)\r
+#define MAX_POOL_LIST     (sizeof (mPoolSizeTable) / sizeof (mPoolSizeTable[0]))\r
 \r
 #define MAX_POOL_SIZE     (MAX_ADDRESS - POOL_OVERHEAD)\r
 \r
@@ -80,6 +85,21 @@ POOL            mPoolHead[EfiMaxMemoryType];
 //\r
 LIST_ENTRY      mPoolHeadList = INITIALIZE_LIST_HEAD_VARIABLE (mPoolHeadList);\r
 \r
+STATIC\r
+UINTN\r
+GetPoolIndexFromSize (\r
+  UINTN   Size\r
+  )\r
+{\r
+  UINTN   Index;\r
+\r
+  for (Index = 0; Index < MAX_POOL_LIST; Index++) {\r
+    if (mPoolSizeTable [Index] >= Size) {\r
+      return Index;\r
+    }\r
+  }\r
+  return MAX_POOL_LIST;\r
+}\r
 \r
 /**\r
   Called to initialize the pool.\r
@@ -311,7 +331,7 @@ CoreAllocatePoolI (
   // If allocation is over max size, just allocate pages for the request\r
   // (slow)\r
   //\r
-  if (Index >= MAX_POOL_LIST) {\r
+  if (Index >= SIZE_TO_LIST (Granularity)) {\r
     NoPages = EFI_SIZE_TO_PAGES(Size) + EFI_SIZE_TO_PAGES (Granularity) - 1;\r
     NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1);\r
     Head = CoreAllocatePoolPages (PoolType, NoPages, Granularity);\r
@@ -539,7 +559,7 @@ CoreFreePoolI (
   //\r
   // If it's not on the list, it must be pool pages\r
   //\r
-  if (Index >= MAX_POOL_LIST) {\r
+  if (Index >= SIZE_TO_LIST (Granularity)) {\r
 \r
     //\r
     // Return the memory pages back to free memory\r