From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.7220.1684452635943797335 for ; Thu, 18 May 2023 16:30:36 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=i84qmlJO; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684452636; x=1715988636; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=oUMdiR0UtuwXPgXQCLT9fIBL/mZk3iHpocUC6kubq74=; b=i84qmlJObsMzS2bI8uHjqTIgCv3SlrqVsHoRZSlm82BecUTSgE/B/ltJ la+hbpocnoYWckjjKCowBNmOL89emFQ3YGuuQzB0HumtoqcG1UZNlNQIA 1Z4KihlvkeJ3V5mGGbFBJE/o/Rm/TEcjg1qHJN0rWb7UB0EJ48ksdsMya mOdoP7yk8fPkszK8aCDBpIxw5iLfUvo39bdfhtlZisEfWgAiBEOkznSSH C9SEMQimITK5Ogd0rW9IusxrSLHTQcCS5/6m9MlLELWoNC6sXyzIPkJ7K JqrBd5gjaTWl9K+2GfAKKXC6D88JHNeTJcjj2XjqRGjiktZuwkhg6memh A==; X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="417908464" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="417908464" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 16:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10714"; a="696502220" X-IronPort-AV: E=Sophos;i="6.00,175,1681196400"; d="scan'208";a="696502220" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga007.jf.intel.com with ESMTP; 18 May 2023 16:30:34 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) 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 16:30:34 -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 16:30:34 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.171) 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 16:30:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JIlxApyPMxYxl4tmSminYR64We+PNrAPvwfKGBO9kk6xRVgE2tZHkwBb6Fmamjl5JAAmqX3fklCTilu3O87xOY6PwBTqJdiLBH/ijk4z9na/uSM/ywhn9BHXeBB8eVlRmtiZ76A5buQ9s/zh3Np7TLyfC7NHCY/Uh4cjhlS2qxjFaneHoOJIMR8d5bPUIaVtuJuALABw2gp6VZ0QhMszAAiSsAc35rFgazAz4joR6Pm6V1jd7Jc0ZiDpdLult9FVzcdTNIKwYgLIRmjKnqM73SL23Y3kZQOXYwuufXXnHpnAJBJ1xM6cUmtnp8K5VdhqoB3/zUQ5D8tnLXZ7xk6lZQ== 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=eTaxUiSHDQW/3kDN3iAKXWxW0253EeUCW0XIRbYvV4M=; b=gn6bva8NvvVVqdqppdQvJnYJP5zpnBBzveOQviDbjeckAXt5lkCOebGTDzt5vs7r0iBLRTVI7MV1KV53mBKZZCiXzMljGspG075JmWi/MecWV6+pqNXRb0zoVDzzHRKpv8DgovFNem6tQ8qycKDkFLI+LOkjH0pxBZrqyJ+8J5uv1Die8y0r8twWwOHdOf7RWovrOgiVxrGidSRKtbUsaba4drXqkFccHlABSsypP9MPk27UMjlD49QD7J5S07ZhxwQcCi2yVuJMMrORFp2z0lizKjLlSXMRahhZKzBcvb/Su73MrCGnRKgyRqe7pnQh8ftzKq46mqB7B7zYhBnP8A== 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 MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by SA0PR11MB4653.namprd11.prod.outlook.com (2603:10b6:806:94::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Thu, 18 May 2023 23:30:30 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%5]) with mapi id 15.20.6387.032; Thu, 18 May 2023 23:30:30 +0000 From: "Ni, Ray" To: "Kinney, Michael D" , "Tan, Dun" , "devel@edk2.groups.io" CC: "Gao, Liming" , "Liu, Zhiguang" Subject: Re: [Patch V2] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Topic: [Patch V2] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Index: AQHZiVq8+owiorYnOkCxcHyQKGT4zq9fuizQgABwe4CAAINhEA== Date: Thu, 18 May 2023 23:30:30 +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: MN6PR11MB8244:EE_|SA0PR11MB4653:EE_ x-ms-office365-filtering-correlation-id: b839a6c3-07ef-4276-e6bc-08db57f7de7a 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: 1eCAiaHxYfm/BST9/82+iWAGTBq+AghPcskV1a4ssNEhqWxB3X+cMU8Go7ALpWHiC8Hy2NoXNdgOip2F9iJYXtR5UD2UV5FpT9gN0/B2pASrTcgvmXwWK9FDMfQbKPwVVAx+EKU1LVausJP4GF5EehgtcUbu+JzRdLCC2GmVwuh+ugPHm2cXw7+ngTzO37oC4MIxtP1gmV+MUKyN7zi5eZouzRAEyB7MZ6egb4xG4F3JF14lK8GhVa2zk2Xukd82c9vpN6MFkDdhAPCvqfnAT4YvDVbWmQA+2Sy7LiMLubRz9IwkEOwW1ZPU4Flf9Vkbfd6lur4sORAGukXC0FTHxghi0zYSt+19gbKztrG5xWx4JE5xHI8NedVvx8YtzCBk7lmJPt7DBa5NrUX5Kxe6I/Ma7dujdfRwhq1IGGQ2PLJY371bhYxX/xaWNlepCGViHQZ1kWZXxuXaZ8MbOBpC/6SkKxDuS4A5D0BtZDN35nor2Ha8XSrPueOxbiIhlVlCuobj2QpB41KZSpk3WE1xlmjrRdfV0EDmTuI+LwxEJneYdQJ9xwnEeS8bP+Fz+iusX/1t1E8OwegGaIpwRHnzExEgHyTiwrqdPjhcl3YtRkQZA8UKdW9DYk8n1Kxh1uRw x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(39860400002)(136003)(346002)(366004)(396003)(451199021)(66446008)(66476007)(64756008)(66556008)(66946007)(110136005)(54906003)(7696005)(76116006)(53546011)(107886003)(316002)(4326008)(478600001)(71200400001)(41300700001)(5660300002)(186003)(9686003)(33656002)(8936002)(26005)(52536014)(6506007)(8676002)(55016003)(38100700002)(83380400001)(2906002)(82960400001)(38070700005)(122000001)(86362001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?SOsz5u4W7pSs5e7XRyQF7bGpHL/1WYNCcgOUOCs8cJKgTMnvm7z2g30ZMgqX?= =?us-ascii?Q?EI21EMEPglaePwhTRfP4rcdwk3v80h1HziA6Lyuf2RcxLHEpRzwg5wHJo7n0?= =?us-ascii?Q?3BoBIl0SeleiDbAwmmLVyq632hcf2ex4Duq9SPWBrZQ6QRytY64wnI/c/vHC?= =?us-ascii?Q?JxAe/sLMOAw2zLlvFcKA8zkgEUq59N640d7pftMNTWVtqGrk8kIC15JB8kLj?= =?us-ascii?Q?9YfCimmB9o9fTcpwLdF2W7q202zbvShZFW6J7iwpxr2rKwkcbUPOwf7wzNcg?= =?us-ascii?Q?JzSBVrl7NoLtaXtZesGVh5Ek94h2VbjOdvVGDjxBcLtcFwdm7vTakU8qnmn/?= =?us-ascii?Q?4G4PjaR7hpSRcpKqzBT0zig9KS0JGIDAzu/qLv09+h6sqilukGMEwfLDCjQA?= =?us-ascii?Q?9Xpu1CtqkWBqBNtf2iPRwb+tKRbQWWvVaUAT+EaNGQGT+1fCX+zKvXz4UjbY?= =?us-ascii?Q?4+4FPYiQr1hNL9tB+YHNo7L955miwH/SftIIvsxmdX61aJSWWvobLdtc9Q4l?= =?us-ascii?Q?LRl1W8s8GdZuRWIqZwnpTZU63ickL6ItPGpGtAiJ8lxAHRSa2fQSDmSoZGTW?= =?us-ascii?Q?41IodyRhRc7O/jQ5bCkrMCA1YpXHQLS8KGSCh+3oUnm/XbBj4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QQKu//EkPTJ7Sj+a+HRpcDbboi5vjF2M+AZEkAMl6?= =?us-ascii?Q?WOLBZfznpMG1edTCTKw=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b839a6c3-07ef-4276-e6bc-08db57f7de7a X-MS-Exchange-CrossTenant-originalarrivaltime: 18 May 2023 23:30:30.3682 (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: MZoFiZN8GfKHZw+NKeLfQ5cy9ldWMWtzeUpTTSLXecnYcWSiM1BQlGtDRimH21kipiUiHDfZykcWTyhWonCzbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR11MB4653 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Mike, No. The code is there for couple years. With that fact, I don't think it's = a critical bug. Yes. all memory allocation libs should be fixed. We start with the SMM one = first to see feedbacks. Thanks, Ray > -----Original Message----- > From: Kinney, Michael D > Sent: Thursday, May 18, 2023 11:38 PM > 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 >=20 > Is this considered a critical bug for stable tag release? >=20 > Is there are HSD and if it is critical, all memory allocation lobs should= be fixed. > Right? >=20 > Mike >=20 > > -----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 > > > > Reviewed-by: Ray Ni > > > > > -----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= than > > 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 = not > > > overflow. > > > // > > > -- > > > 2.31.1.windows.1