From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: eric.dong@intel.com) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by groups.io with SMTP; Thu, 25 Apr 2019 17:07:21 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Apr 2019 17:07:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,395,1549958400"; d="scan'208";a="138900187" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga006.jf.intel.com with ESMTP; 25 Apr 2019 17:07:20 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 25 Apr 2019 17:07:20 -0700 Received: from shsmsx105.ccr.corp.intel.com (10.239.4.158) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 25 Apr 2019 17:07:19 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.206]) by SHSMSX105.ccr.corp.intel.com ([169.254.11.25]) with mapi id 14.03.0415.000; Fri, 26 Apr 2019 08:07:17 +0800 From: "Dong, Eric" To: "Bi, Dandan" , "devel@edk2.groups.io" CC: "Kinney, Michael D" , "Gao, Liming" Subject: Re: [patch] MdeModulePkg/HiiDB: Minimize memory allocation times after ReadyToBoot Thread-Topic: [patch] MdeModulePkg/HiiDB: Minimize memory allocation times after ReadyToBoot Thread-Index: AQHU+xg8uM1qiv9pP06/OPoSFevsIKZNkbqg Date: Fri, 26 Apr 2019 00:07:16 +0000 Message-ID: References: <20190425033728.32212-1-dandan.bi@intel.com> In-Reply-To: <20190425033728.32212-1-dandan.bi@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: eric.dong@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Eric Dong > -----Original Message----- > From: Bi, Dandan > Sent: Thursday, April 25, 2019 11:37 AM > To: devel@edk2.groups.io > Cc: Kinney, Michael D ; Gao, Liming > ; Dong, Eric > Subject: [patch] MdeModulePkg/HiiDB: Minimize memory allocation times > after ReadyToBoot >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1597 >=20 > 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 to do some overallocation to minimize the number > of memory allocations after ReadyToBoot and also add warning > message when do allocation after ReadyToBoot. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Eric Dong > Signed-off-by: Dandan Bi > --- > .../Universal/HiiDatabaseDxe/Database.c | 24 +++++++++++++------ > 1 file changed, 17 insertions(+), 7 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c > b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c > index 6da0e30c98..d3791ca68b 100644 > --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c > +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c > @@ -1,9 +1,9 @@ > /** @file > Implementation for EFI_HII_DATABASE_PROTOCOL. >=20 > -Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
> +Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ >=20 >=20 > @@ -3361,18 +3361,23 @@ HiiGetConfigRespInfo( > Status =3D HiiConfigRoutingExportConfig(&Private- > >ConfigRouting,&ConfigAltResp); >=20 > if (!EFI_ERROR (Status)){ > ConfigSize =3D StrSize(ConfigAltResp); > if (ConfigSize > gConfigRespSize){ > - gConfigRespSize =3D ConfigSize; > + // > + // Do 25% overallocation to minimize the number of memory allocati= ons > after ReadyToBoot. > + // Since lots of allocation after ReadyToBoot may change memory ma= p > and cause S4 resume issue. > + // > + gConfigRespSize =3D ConfigSize + (ConfigSize >> 2); > if (gRTConfigRespBuffer !=3D NULL){ > FreePool(gRTConfigRespBuffer); > + DEBUG ((DEBUG_WARN, "[HiiDatabase]: Memory allocation is require= d > after ReadyToBoot, which may change memory map and cause S4 resume > issue.\n")); > } > - gRTConfigRespBuffer =3D > (EFI_STRING)AllocateRuntimeZeroPool(ConfigSize); > + gRTConfigRespBuffer =3D (EFI_STRING) AllocateRuntimeZeroPool > (gConfigRespSize); > if (gRTConfigRespBuffer =3D=3D NULL){ > FreePool(ConfigAltResp); > - DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the > ConfigResp string.\n")); > + DEBUG ((DEBUG_ERROR, "[HiiDatabase]: No enough memory resource > to store the ConfigResp string.\n")); > return EFI_OUT_OF_RESOURCES; > } > } else { > ZeroMem(gRTConfigRespBuffer,gConfigRespSize); > } > @@ -3412,17 +3417,22 @@ HiiGetDatabaseInfo( > Status =3D HiiExportPackageLists(This, NULL, &DatabaseInfoSize, > DatabaseInfo); >=20 > ASSERT(Status =3D=3D EFI_BUFFER_TOO_SMALL); >=20 > if(DatabaseInfoSize > gDatabaseInfoSize ) { > - gDatabaseInfoSize =3D DatabaseInfoSize; > + // > + // Do 25% overallocation to minimize the number of memory allocation= s > after ReadyToBoot. > + // Since lots of allocation after ReadyToBoot may change memory map > and cause S4 resume issue. > + // > + gDatabaseInfoSize =3D DatabaseInfoSize + (DatabaseInfoSize >> 2); > if (gRTDatabaseInfoBuffer !=3D NULL){ > FreePool(gRTDatabaseInfoBuffer); > + DEBUG ((DEBUG_WARN, "[HiiDatabase]: Memory allocation is required > after ReadyToBoot, which may change memory map and cause S4 resume > issue.\n")); > } > - gRTDatabaseInfoBuffer =3D AllocateRuntimeZeroPool(DatabaseInfoSize); > + gRTDatabaseInfoBuffer =3D AllocateRuntimeZeroPool (gDatabaseInfoSize= ); > if (gRTDatabaseInfoBuffer =3D=3D NULL){ > - DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the > HiiDatabase info.\n")); > + DEBUG ((DEBUG_ERROR, "[HiiDatabase]: No enough memory resource > to store the HiiDatabase info.\n")); > return EFI_OUT_OF_RESOURCES; > } > } else { > ZeroMem(gRTDatabaseInfoBuffer,gDatabaseInfoSize); > } > -- > 2.18.0.windows.1