]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/HiiDB: Minimize memory allocation times after ReadyToBoot
authorDandan Bi <dandan.bi@intel.com>
Thu, 25 Apr 2019 01:00:26 +0000 (09:00 +0800)
committerLiming Gao <liming.gao@intel.com>
Sun, 28 Apr 2019 01:32:42 +0000 (09:32 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1597

Currently RTData are allocated at/after ReadyToBoot to store the
contents in HiiDatabase and the HII configurations for OS runtime
utilization.
Some platforms may meet S4 resume issue since the allocation after
ReadyToBoot cause memory map change.
Now this patch is to do some overallocation to minimize the number
of memory allocations after ReadyToBoot and also add warning
message when do allocation after ReadyToBoot.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
MdeModulePkg/Universal/HiiDatabaseDxe/Database.c

index 6da0e30c989fbc6c882900984ed298f9db293a35..d3791ca68be17a9898af0aaeb20f4e4cd64deac6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation for EFI_HII_DATABASE_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -3363,14 +3363,19 @@ HiiGetConfigRespInfo(
   if (!EFI_ERROR (Status)){\r
     ConfigSize = StrSize(ConfigAltResp);\r
     if (ConfigSize > gConfigRespSize){\r
-      gConfigRespSize = ConfigSize;\r
+      //\r
+      // Do 25% overallocation to minimize the number of memory allocations after ReadyToBoot.\r
+      // Since lots of allocation after ReadyToBoot may change memory map and cause S4 resume issue.\r
+      //\r
+      gConfigRespSize = ConfigSize + (ConfigSize >> 2);\r
       if (gRTConfigRespBuffer != NULL){\r
         FreePool(gRTConfigRespBuffer);\r
+        DEBUG ((DEBUG_WARN, "[HiiDatabase]: Memory allocation is required after ReadyToBoot, which may change memory map and cause S4 resume issue.\n"));\r
       }\r
-      gRTConfigRespBuffer = (EFI_STRING)AllocateRuntimeZeroPool(ConfigSize);\r
+      gRTConfigRespBuffer = (EFI_STRING) AllocateRuntimeZeroPool (gConfigRespSize);\r
       if (gRTConfigRespBuffer == NULL){\r
         FreePool(ConfigAltResp);\r
-        DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the ConfigResp string.\n"));\r
+        DEBUG ((DEBUG_ERROR, "[HiiDatabase]: No enough memory resource to store the ConfigResp string.\n"));\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
     } else {\r
@@ -3414,13 +3419,18 @@ HiiGetDatabaseInfo(
   ASSERT(Status == EFI_BUFFER_TOO_SMALL);\r
 \r
   if(DatabaseInfoSize > gDatabaseInfoSize ) {\r
-    gDatabaseInfoSize = DatabaseInfoSize;\r
+    //\r
+    // Do 25% overallocation to minimize the number of memory allocations after ReadyToBoot.\r
+    // Since lots of allocation after ReadyToBoot may change memory map and cause S4 resume issue.\r
+    //\r
+    gDatabaseInfoSize = DatabaseInfoSize + (DatabaseInfoSize >> 2);\r
     if (gRTDatabaseInfoBuffer != NULL){\r
       FreePool(gRTDatabaseInfoBuffer);\r
+      DEBUG ((DEBUG_WARN, "[HiiDatabase]: Memory allocation is required after ReadyToBoot, which may change memory map and cause S4 resume issue.\n"));\r
     }\r
-    gRTDatabaseInfoBuffer = AllocateRuntimeZeroPool(DatabaseInfoSize);\r
+    gRTDatabaseInfoBuffer = AllocateRuntimeZeroPool (gDatabaseInfoSize);\r
     if (gRTDatabaseInfoBuffer == NULL){\r
-      DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the HiiDatabase info.\n"));\r
+      DEBUG ((DEBUG_ERROR, "[HiiDatabase]: No enough memory resource to store the HiiDatabase info.\n"));\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
   } else {\r