From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.12596.1684400116012874499 for ; Thu, 18 May 2023 01:55:16 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=XQqpqhRq; spf=pass (domain: intel.com, ip: 192.55.52.136, 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=1684400116; x=1715936116; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=cNesGw2TbM8QiXCIIN+rZ4NM7zOZq0lQt3sm65DFxT8=; b=XQqpqhRqZ27shGU37HXdptgf7lk9nE8q5P9h3kgZ/kROxe1hSqJ6x58b QGXz1LmA0MPwProCleheco7OY0Axr7iioepExkrmL5cR+ymPCepDcK1FR gOWJieqU5sygDRiqcxqooYVk7/mjn+LaHHp/OKad0OFsC9Hf6O0BMCWmF grSsNvviqtSFnAVzBf4eNFGuXhplYTYOp3oqSKkL8IqRGJpPbI90eQloe R0QRwhO95sQhnuwzHFSP7UZmMRkpw/bVla2X9EwWfCew/CpM+OSKwDlGF 0g+SIM2IrJmNdHSH1s1M/80AiWixIoEOBfo1ZRxfN1Na16hTbsWrIWZ3f Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="331630394" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="331630394" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 01:55:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="652556527" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="652556527" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga003.jf.intel.com with ESMTP; 18 May 2023 01:55:15 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) 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 01:55:14 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) 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 01:55:14 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (192.55.55.71) 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 01:55:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aMdeAl6bpIyvDRRv2SY2oLBvPKyv2K/9jK9L8HWbcKwaTmg/YbREtb1WJBymL9RGCCnRwK6RFqhAscbmpuBt8yrUzwgj0rW9Jwyn6f//IvDWghkCzQ/NcJt0oUnGl1dY0HxZHPhuB8z3ZZQWY/0F0EnCTJkUAYG4u5fa/6rCyTW8iXHlqhHsGoAjUpz5XHH7UiTTpSAjv8OaBMEK4LKqzTfUgs0Dg1bshCS0XQP0KqYziOF51fG3mEa2il1Wd8uDOhjQe45VNETxhbcPiEBLXpOA1GCLZpD5P3Dr7r2JlVzpUwckq5TYELZHxJxyaYcpRq3oh/qkPgOakCg5WZlaAg== 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=dzQ8lwjq91AK3KoulwooP1GtM+7BQD/C3f85ok4Lrrc=; b=jWqdAWIPgXDSvQ5vb1qKAJQPZ04RnPPMdhisZzK6Ef9MtSG3QF0Px9eyzSkM5aCrhfFN2jlyRqYLWMTP5bP2CZ0MVWCl/QicsDvB75zxIz3C7vT+6BlidQNF1ZbpPSyOfVZ3MAscQ3j5FZNvzzI8YSfb/dCW9WtCex9lVAreIFuLxit+dkmEmpgsmaLY7sQd3aL0+C7qbq25pFODeI8wykRjeHI2QUeBtJ2u6tGBYdPHwqzPprYOjpoFwcRYPVfxf8DDA2pm2G9Pu/swnDduPDGHuQzLqpQgartIfwq9qbXUZ22z8crzIo+IDypbNlt3/7zpI5zy1rv3X60cwsUacw== 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 PH7PR11MB6378.namprd11.prod.outlook.com (2603:10b6:510:1fa::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6387.30; Thu, 18 May 2023 08:55:11 +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 08:55:11 +0000 From: "Ni, Ray" 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 Thread-Topic: [Patch V2] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Index: AQHZiVq8+owiorYnOkCxcHyQKGT4zq9fuizQ Date: Thu, 18 May 2023 08:55:11 +0000 Message-ID: References: <20230518073101.1838-1-dun.tan@intel.com> In-Reply-To: <20230518073101.1838-1-dun.tan@intel.com> 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_|PH7PR11MB6378:EE_ x-ms-office365-filtering-correlation-id: 707dbbd2-330e-4904-9ff4-08db577d96b6 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: hYApb9Up0Ph+L7F2bo4Oe+BEpJVYL+5SGFZ40OiMagYIZ2z6um1C76b4ANsKnIov/7XwYi/8GnO2ZwITo5d4qQx1hHamXvovOCelhZT13pv37OHLcmwgaFPcjDB7DO9/IdeedhsZUw9FneIEdeTG15SwAvJjAKuk8I4OA3lniRTR/gGsPgQWnLhYFCI0gL1/H0P2JHSzTosUksN2tKdMtIgbq5+bbdEXpv/H5qv4BMkng/jeuERELeaJDGCbakEM98onf+mi0EsILbzpzsb9Fqlid3XoyGjheQpSMfXU9Cmi7vMSxEXXewhig84gnWwRtSL9ogiWVq+06b90xwlrhPS0ryAVY/6BrYD7crWGzF3bjXNm2ybMM9NtE1Rm7d8Nct2FvFMZzXdJQhGy3J8NJkZqwoE7kX1I9Ajv6uWSuu8QbDIRS5eK5AHwyWYyBimAevXw81u7TIdz9bt/xV4TIXvTTFfWIW3dHWSHHzW1dJQawZy0EdgujISe45m8dZUcvyV63oKq3uI9Vm9beyVYUSq3hOAs7+2kbGyHlrYDfgL4cO8FlV3fddr+7xe/ZFhx8OByua3YvFwqpSW858pH7Z7KTv0M40/yg/CFyko0r91Qw64cOAmKdgqONdRi9tDb 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)(346002)(396003)(366004)(136003)(39860400002)(451199021)(83380400001)(52536014)(8676002)(8936002)(33656002)(5660300002)(316002)(122000001)(2906002)(86362001)(38070700005)(54906003)(186003)(110136005)(107886003)(6506007)(9686003)(26005)(478600001)(53546011)(66946007)(55016003)(38100700002)(64756008)(82960400001)(66476007)(66446008)(66556008)(76116006)(41300700001)(4326008)(7696005)(71200400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?wFvu4ytr6CzjLA7MgBvTra0jT0SQGcm9ofg+BReJzILC7P+N9NWpnI/Io6Dy?= =?us-ascii?Q?ahU636/AAldagQBYIYKLGOv5qQXlJS+qmiAoVpn5a0NLR4wxGhHbCJPEfMOI?= =?us-ascii?Q?F8dz1csGuO6BY9JkoIJgrEzmN9gRozThZ04dRfVO4W8v/4iK/3r+433HUhbq?= =?us-ascii?Q?yeU6ecyARW7sFJ5k7wNl7bAdL1FSEJsJRnFKd1lKog5QvxrowUXvm8/ZzxUN?= =?us-ascii?Q?SJAdGw4XUTL1Vw3kmFhe+igTgAd01WY9Rv6N2cjqTMBr6O0uYk6WHM7qKP16?= =?us-ascii?Q?Npu16+JPJ/EYjANJt81VQ4/p1uQOn9LoRQRlmIHxikfbXNjwqwYZVFgptz+q?= =?us-ascii?Q?rOJRX7wYe9RDRch5MryQ4wyKnhCa30pkgRkz292faU1eVWVQAJz26boh6Xrk?= =?us-ascii?Q?kHQSGMQOdeWG9bBik9U7y1khRtFtwL5hT5B6IzfRKvzMZ23E4xUo5aRcy5+s?= =?us-ascii?Q?5rJ52SyJ6aM7z4ApWwR8sg/5Xe/abTmFDW7I74PcYw2gavmoybUJPNJ/Xi6S?= =?us-ascii?Q?sA+E6o5CqYz1rP5LQ5OzkmTEkxeqjETO+r3AAeLo1UJALAN0Nmm767EKnwYE?= =?us-ascii?Q?/qS3inYwe69ROjfOLkeGpOHAnyJfqm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SScUbvciCUaMfnNtk1kzBmVKRY4QU+TyiMwTFHYhisJc3HbygE1tnfGnd+?= =?us-ascii?Q?5ZmMSJveaG+cEyykMq4=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: 707dbbd2-330e-4904-9ff4-08db577d96b6 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 May 2023 08:55:11.3760 (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: pC1KtdIR+29gLH3nEp/Y5WXNtDUTGveMFv45QrRjJPpu72eBMrDuYMKOHUTl0ASCKgo/pP4iWSDDBUVhJNh/dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6378 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 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 >=20 > This commit is code optimization to InternalAllocateAlignedPages of > SmmMemoryAllocationLib which can reduce free memory fragments. Also > it can reduce one pre-allocation page. >=20 > Let's take a simple example: > The expected pages size is 8KB, Alignment value is 8KB. >=20 > 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. >=20 > 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. >=20 > 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(-) >=20 > 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 tha= n 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