From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.20544.1684424267572420766 for ; Thu, 18 May 2023 08:37:48 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=THKuMBZp; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: michael.d.kinney@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684424267; x=1715960267; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=whbkVAgk4SH4mnClelfu1O2d14W2BIjDAPMM4QT0Alk=; b=THKuMBZpMFPTkoushMx/rlBDXTr5/rRCYRaUWsSK+msVGgNzIkgEBCqV r3Xw9vQxXUgqST+M6bfNrvYgoPGnKx6/CF4040f0oL3+OEwToEOT3u7Qf QbLMkRlV7Rh7jV9+GFXSPk81LDCIDiCvnMyKPfrabU2QEMLdRdMhwUw9V oO9dzYNQVfoDSziDM2C917bowBkWO/xLM3LhK4qstSh1CXXInjO4fFZ6K V6Yw2aCTXCoYVJ+WbrHHUzCna5IIAdPy1l0UtwtL8tciTdRta88slP1h4 tLkGie3eoMLHCw6dJdJMDWa1tj9ORBbPEWyzSl2Rq9ygDVtt0euBfNPiy w==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="341528694" X-IronPort-AV: E=Sophos;i="5.99,285,1677571200"; d="scan'208";a="341528694" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 08:37:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="705236333" X-IronPort-AV: E=Sophos;i="5.99,285,1677571200"; d="scan'208";a="705236333" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga007.fm.intel.com with ESMTP; 18 May 2023 08:37:46 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 18 May 2023 08:37:46 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 18 May 2023 08:37:45 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 18 May 2023 08:37:45 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.102) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Thu, 18 May 2023 08:37:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BkngKjw+4tGTLwV/QWveJg4ZHmuHRpDoBTJXZm9fdDVNRN8TXgenuqjEWjzdl9q4UFVPQzuxtVWR9p8r/qGHhcpsAMGM4VIeKYo0NTZ1E+x//YnMlxZtfs4YHhhbHKmMJLdbGTvBO4yzfFDMl67I4IZthgWGFsfm0/AVydEDxRvSq9iW9ce+DTM6PWQpzg5RJzTYivPhejZVchFf4bM/VJOfir2466qXT3wm9M5ln0//FYx2EcO65UuzDCNm2SueqNinNyOReiZ7eEUOR0yoj9llmPJvkpUugplbIS/JEFEwbtX8c/iBz11WObCQDhIm3g2xQuLj1xTh5NCTmK4SGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=48m4hQBX/V3+MOv/Tfuy/+MjKWTCAGu9FmfKfJS1VoE=; b=bMkjDjs7VLc4eYsLkyZndrJfek6hc3DFylIhjl+pTmiswzShoopsV2zVKpcNdr1BZukPUUda4eLxaiwJ6KS+4T8BEIAr7cqgBTXbZV2TsmpSDzZbvUv9f5zhr8PVs+uw3sPBrsK1WnEexNmaVPoFUR74EGralzW748NxnxmgHSV03X1R7iEWZiX4JYjO2NcU1AmuWD/+XZtAevOk4d+ryj7zehAnxiGDK2UAIKLfeXXKcOY2fE8bWPYv+nHZwlREm86OHtY2zXpBTwSD8SGkkM3OfMgvBNAgPAkOEQdHuhALrjcQ9nQQsYDnIWdaN1wbD1OXdQjKb0fjwNuKAo83+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from CO1PR11MB4929.namprd11.prod.outlook.com (2603:10b6:303:6d::19) by CO6PR11MB5586.namprd11.prod.outlook.com (2603:10b6:5:35d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19; Thu, 18 May 2023 15:37:43 +0000 Received: from CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::4752:67f2:9956:b277]) by CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::4752:67f2:9956:b277%4]) with mapi id 15.20.6411.017; Thu, 18 May 2023 15:37:41 +0000 From: "Michael D Kinney" To: "Ni, Ray" , "Tan, Dun" , "devel@edk2.groups.io" CC: "Gao, Liming" , "Liu, Zhiguang" , "Kinney, Michael D" Subject: Re: [Patch V2] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Topic: [Patch V2] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Index: AQHZiVq88nHMQfObGUm3U9hP+NUKUa9fujKAgABwOOA= Date: Thu, 18 May 2023 15:37:41 +0000 Message-ID: References: <20230518073101.1838-1-dun.tan@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CO1PR11MB4929:EE_|CO6PR11MB5586:EE_ x-ms-office365-filtering-correlation-id: 1d77f865-0695-443d-2f31-08db57b5d175 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qW9GfchYl42tnYRn8AV4gHYRQ9QEQmfzQNLDRVVbLGoK5A83nwJ/y5EATBZbL/CZvuv86lUoMfpFdZg5M/F5rq/wHloavwWJehKOx/xM7jIMrjFJ2+GzQway6x1d7ljiROb3BPllwUFwDoPiRsZO/f+BTAhVMa0PtA05zbuVqpToOIrHm7Gk1QkZrWqTz1pP4vCANinO4UUWHVCvO5kJf7n9Hj9Kj29iGp+KQ3iH25A+UPNFf+u/P6BO+Yz5Q7GZeIZnP4W1IGzSvgPy6spGNUdLVM4EQraGSTzhhjopUIlc/yvdACiJQcoIk7NqxyuI3c3LTdO7xiBaK9j0Mxk/AN6yMd88h2m0i9r4hMBsR7PJgZfKikzRlvhGgn4jhXhUTUT9E/xpVs6x9b5sp9E9pqRyYKgBIv1x+BPcGDNEclEC092sEoHmHgIUjqg8ZgShjPrj59eRGCbmB2+eAz3pr1SZJCdBAi4oSXjU1PSVxl5gkDZ8q0pNJHP56N0Viy+NfMsrtwZZcB3e0AXgpjBqJ8+ps1IcTVg3vn9BLsnvwYOtRPo+oZbXVTNaz02gIG+491VpUPykxf6iDfV+ATVlmA9Uzp0Mveoijmza3wTkB/562U6FVL2/YiM6Lp6ksJfz x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4929.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(376002)(136003)(396003)(39860400002)(346002)(451199021)(26005)(9686003)(6506007)(107886003)(7696005)(53546011)(83380400001)(33656002)(86362001)(38070700005)(38100700002)(82960400001)(55016003)(122000001)(186003)(54906003)(110136005)(478600001)(2906002)(316002)(8936002)(4326008)(8676002)(41300700001)(52536014)(5660300002)(64756008)(66476007)(66446008)(66556008)(76116006)(66946007)(71200400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?DCyJHpBUVV/NNMKgIw5IfiPqg5KTQW1Q2xNOAwQeipACCRuNE+7Hn/M7trR7?= =?us-ascii?Q?oUFB9ZgBVIzHqdeBMi4XEu8FbhrzzW1bRgD64kCF6MPaM1tEs3yRGMOo0utZ?= =?us-ascii?Q?lCdYCxbPsUOQ0KTbcqMUrO+BlrCz4o+20G7ORhdkAoo/9c1hnzFxIlJLA1dx?= =?us-ascii?Q?cZyW1AN56xRhmZHB8mne6yoYlrWGJ0TOdpbd9H4H0biRbXcIVhpfJOi88Fln?= =?us-ascii?Q?vJbSPz6TXyaLkw1Gzd684ysh3hpuskdUe09eYJ4/mOpnWVHyN/4WY0Bqo1LG?= =?us-ascii?Q?t+MH3y8mwtLEeuz3C0QBdWetPRGh6KgDd9Vtgqkr+C7/hCMs7jjSZA97X59J?= =?us-ascii?Q?N7HWd31Zw34D05q5EbgQsWIhfDfVT4iJveewGvh+hwUIjVv8sDyijycRdOyy?= =?us-ascii?Q?ZRmOArRYfm4TGKhmZrzzC7Dvia3Gp8HdtHG6sm80FY30Jb14eZNnvtTtv5sn?= =?us-ascii?Q?e0X2iMd+PgtSaG3Ai/dzss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7m?= =?us-ascii?Q?4DoA9b05HnQfaCOHBzsFiic0s+m+krOpCCOzDcHrXIkZAm7xEdU31SpI7fEW?= =?us-ascii?Q?iP+sX5V8aykGycKhBEoNb3sLx+LuhptAYX05v2XnQBWSGrjjlibRP0QneiF/?= =?us-ascii?Q?B6bGn9EZ26RUsBasKU70CIEikh14itZmQ4gl3XZ2A4cu5jJYSzEgU0GDHi6m?= =?us-ascii?Q?CoIQ/V1DZuQqw2Gnz2v7YaGq18yWxWp7198qGl5ptHOHQkK9GZ8/p/LHRHD0?= =?us-ascii?Q?7Q=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4929.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d77f865-0695-443d-2f31-08db57b5d175 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 May 2023 15:37:41.7756 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: mOxnd+UmZ/z6dQrVPjFqKV8O+zD649Sy54qR6LdcO/1I+lXNyvw4eFFfxxTdJxYugCWh3s5brjP8GskX00NIu9pe6m7TL2Pi4LIvwY6L+B8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR11MB5586 Return-Path: michael.d.kinney@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Is this considered a critical bug for stable tag release? Is there are HSD and if it is critical, all memory allocation lobs should b= e fixed. Right? Mike > -----Original Message----- > From: Ni, Ray > Sent: Thursday, May 18, 2023 1:55 AM > To: Tan, Dun ; devel@edk2.groups.io > Cc: Kinney, Michael D ; Gao, Liming > ; Liu, Zhiguang > Subject: RE: [Patch V2] MdePkg: Code optimization to SMM > InternalAllocateAlignedPages >=20 > Reviewed-by: Ray Ni >=20 > > -----Original Message----- > > From: Tan, Dun > > Sent: Thursday, May 18, 2023 3:31 PM > > To: devel@edk2.groups.io > > Cc: Ni, Ray ; Kinney, Michael D > > ; Gao, Liming ; > Liu, > > Zhiguang > > Subject: [Patch V2] MdePkg: Code optimization to SMM > > InternalAllocateAlignedPages > > > > This commit is code optimization to InternalAllocateAlignedPages of > > SmmMemoryAllocationLib which can reduce free memory fragments. Also > > it can reduce one pre-allocation page. > > > > Let's take a simple example: > > The expected pages size is 8KB, Alignment value is 8KB. > > > > In original InternalAllocateAlignedPages(), the first step is to > > allocate 4 pages and then find the first 8KB-aligned address in > > allocated 4 pages. If the upper limit address of allocated 4 pages > > is already 8KB aligned, then the allocated 4 pages contains two > > 8KB-aligned 8KB ranges. The lower 2 pages will be selected and > > removed from free pages. Then the higher 2 pages will be free. > > Since the whole memory allocation is from high address to low > > address, then the higher 2 pages cann't be merged with other free > > pages, causing the free memory fragments. > > > > However, when only allocate 3(2+2-1) pages, we can avoid the free > > memory fragments in specific case. Also 3 pages must contain a > > 8KB-aligned 8KB range, which meets the requirement. If the upper > > limit address of allocated 3 pages is 8KB-aligned, then the higher > > 2 pages range of allocated 3 pages is 8KB-aligned and will be > > selected and removed from free pages. The remaining lower one page > > of allocated 3 pages will be free and merged with left lower free > > memory. This can reduce free memory fragments in smm. > > > > Signed-off-by: Dun Tan > > Cc: Ray Ni > > Cc: Michael D Kinney > > Cc: Liming Gao > > Cc: Zhiguang Liu > > --- > > MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git > a/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c > > b/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c > > index 3ab2c1ebfd..99a8259325 100644 > > --- a/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c > > +++ b/MdePkg/Library/SmmMemoryAllocationLib/MemoryAllocationLib.c > > @@ -322,7 +322,7 @@ InternalAllocateAlignedPages ( > > // Calculate the total number of pages since alignment is larger t= han > page size. > > // > > AlignmentMask =3D Alignment - 1; > > - RealPages =3D Pages + EFI_SIZE_TO_PAGES (Alignment); > > + RealPages =3D Pages + EFI_SIZE_TO_PAGES (Alignment) - 1; > > // > > // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does no= t > > overflow. > > // > > -- > > 2.31.1.windows.1