From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.11632.1684394916189978989 for ; Thu, 18 May 2023 00:28:36 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=LN/2P/uZ; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: dun.tan@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684394916; x=1715930916; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=4bnaOMtDfd/dBbn7s8x5yrg8CuLZ47d2H0igy8hqbjs=; b=LN/2P/uZaEdJYWIuDY4xqx5u0iTOGXl9/aTGrMdmm1/ezdH/SF53K0xb EgIOXoV4tFGLvUJ5fwzXnvFbbc7KU9mEjvCnX/n66N1YWAcxoZKMtEeeN sZUSL5EZB6rZEygxs+73SmDj+LYWwVg37VuHLiAARZvjqGW2zuanY2xl+ h3NZXMYB6CslPxd6E9mRgqgvATIADeMys1Odak2w48J0f82ROzJWlyxX5 bKXD7YyWIHEfx4PmvNmK28JXTinW2kChwhyMerrFE8PxdWSU2LuZgpbQb kn46ZaIzxG01yQGnO2eeQowpHymIczzY5bmSx3gu5Ofs8p2NdpJL+wkuK Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="438336281" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="438336281" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2023 00:28:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="948586261" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="948586261" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga006.fm.intel.com with ESMTP; 18 May 2023 00:28:22 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) 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 00:28:20 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx612.amr.corp.intel.com (10.18.126.92) 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 00:28:19 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx612.amr.corp.intel.com (10.18.126.92) 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 00:28:19 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.170) by edgegateway.intel.com (192.55.55.68) 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 00:28:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yfq5KPA6kf32thUM02S7weTfVWnT2ZDOuFF30bs/WG4f0at1NUCoAT2qOyCNsPRUMoRRpGUKY1f5PPK019D6kduJJvGdeA9DFWcud2xJDS/LuUC4ULLsSe1x0oS9sG6RaYuWx8WAr1umw63bXZS1Ke8yHYZD+7d+xurZklKeHlQe+BwiAgdLm/vECubSgsPLyOs0aBmuBl1sKBMqx0E6k5HTxSNL/LvuNcKMT0Sywfi2ABFum7lijtSM/VV5Pif2s1/UxSRWReUCg5idg/3ZrfQ+1Q1VgwhNrUOmjGLfM5jqVMvBwq8zG5uYAh21cDqcALobhgxTiulU/HD2/lw4/Q== 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=4bnaOMtDfd/dBbn7s8x5yrg8CuLZ47d2H0igy8hqbjs=; b=C8hQNYbOAM4cxaAT9gGaF1ltb2bagpmIRtJwE82ys5qV28J73iGkgEIBxCRB5sqYp+XoLLLaQNAPbg6bA1WLOwTITpSCnrgrAIlMY+xDO4IcSit+yKiRq9+6u9bIcM9ZaUiYWq/Q+AHB3O+H46cwRg4jkgCKa2JsNehz9cx1m5CRC0lE1fpI19f5oh6ioR+ByooZZDrOPGQmodruoJwr/ua4MKe+LKzDCAFwSSSozI6Lt/ENY669MU/GQiRoULGueH+vHnA+QbFMd5Arbb9Q8KvzmGDNcOHzbzt0MdtUJnw0JSiE0I3nhHDepE96q9FxR/BQdAx+YddLTpsFasTU3Q== 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 BN9PR11MB5483.namprd11.prod.outlook.com (2603:10b6:408:104::10) by PH8PR11MB7968.namprd11.prod.outlook.com (2603:10b6:510:25f::14) 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 07:28:17 +0000 Received: from BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::1eb1:2222:1823:8e7a]) by BN9PR11MB5483.namprd11.prod.outlook.com ([fe80::1eb1:2222:1823:8e7a%5]) with mapi id 15.20.6411.019; Thu, 18 May 2023 07:28:16 +0000 From: "duntan" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Kinney, Michael D" , "Gao, Liming" , "Liu, Zhiguang" Subject: Re: [PATCH] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Topic: [PATCH] MdePkg: Code optimization to SMM InternalAllocateAlignedPages Thread-Index: AQHZiVNYHjQ+hIU23k24+GqW+AgFG69fl4hQgAACzSA= Date: Thu, 18 May 2023 07:28:16 +0000 Message-ID: References: <20230518063715.1703-1-dun.tan@intel.com> In-Reply-To: Accept-Language: zh-CN, 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: BN9PR11MB5483:EE_|PH8PR11MB7968:EE_ x-ms-office365-filtering-correlation-id: 13e4bcc1-c448-404c-dc3d-08db57717280 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: r3515ApEa5y48IVsfQjNyqtCwX4jtRkw64p3imnkiRZJqMS32VVJps30kiZGWNs/u7PDNymYaqpGPQHvjrtHoab7DFVy3JDA4FmNxBxdQjU5hq5K+FiV1KfPcwmtBp4IiC5M3oXEMgfsB1RxBzFiUhvs7uNIK41/Bcnbq3eXcB41YcdBKizyeyaZ0GDYeL8mx+1jz/pWVbM9GTfxDubPMJCBPLjH7MZ4XKNUx9LzGsSFLKNIdO6WFDZ3GsBkdtfreM9RqEv56IBOojSadki66OYazx236UI+7afNcbCD9rx/6mm339AQnotMwxhSiublGmN5nvPf9ZoGPKeTHdCILhJlZRxAcSlOwfnM0A8+YysFHXMPQJVm5Ywkxbwge2qZVu+jdAyNQDzBnZ30+eqCrdgiJkYD85eCRuDC4jG8x6U8/F0LW+cVuLEwAb+3ERteIHdjm2GUloXTXZRY8VvpmOvTjeEJfO0lyxH5p7VnnrDleAZ7m+0cTnCmtK+Cuq6sFzC1cXNg+osRNVqQzNM1VUNg+F8dghU1IkFZK9LfSxxztGP75fzLPsiNKHti0EKeA9a38MpMq0WWaLa+k97Zd+DLG7pPIs3JHUNTiavU4q0DqlPWJ4/rPWa4gLTlfNUk x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5483.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(136003)(39860400002)(396003)(366004)(451199021)(64756008)(107886003)(9686003)(53546011)(76116006)(66556008)(66446008)(66476007)(66946007)(54906003)(4326008)(316002)(110136005)(7696005)(478600001)(41300700001)(71200400001)(5660300002)(186003)(8676002)(6506007)(55016003)(52536014)(8936002)(83380400001)(2906002)(38070700005)(82960400001)(38100700002)(33656002)(122000001)(86362001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?xZD38U5ByuVJOvrec94oL9Crq2ZLcuhdMXCyx13tUnsvsuLSpd8YpG9RDs6Q?= =?us-ascii?Q?0Fg27xr2hQngqGQS209u0RfEDB3ge5PkP/3zDuxDnJJTD9iau3u6N5bMfl29?= =?us-ascii?Q?KNmFhcb7onP0yJMstWAwuuo35t4lPO7M5dw4bk7OXkrKWLer9b6ak4fTYNrc?= =?us-ascii?Q?P2Xc5Fm8VtfKSPjET+zSQMrMJB71XvpQdh3I6tqL6w+jRfEEuztmRzQBN4hO?= =?us-ascii?Q?2Kgln9Nqy8ic0ct3FMFcAv6db+zlQK7Gt+zMKGw4/6zcDvTpndjoFsIVYD3R?= =?us-ascii?Q?aeYGbeiDTU/Jm6m9ofndItIUjrZIOjR80uTASTRoiG+v2J0Y2qBUypeRlfHb?= =?us-ascii?Q?1KHo7aXUeZ4Is+aQVZ64EkFcVKGnFMcIt+aFnBqEvl4R5vjXu/Ay6dSTAEEq?= =?us-ascii?Q?NmoeieDdP8IsbQ0XBjj3qZsFvkKp+EdJYJ4cZ7TwPfH/6+jKaLqxVi8kCB1a?= =?us-ascii?Q?kvJ6LtH8Aj+IIEkHb7vLK+4Wx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-ascii?Q?bsedbhW1C8oAg44C5Y4eU8/XE7+dXSQYm62tSGrfI7V04N8Dw6rrdmVvuINx?= =?us-ascii?Q?KQkRifewwlldvswRvI0FRRonGKE13bFh8i7wqd/+9fv5kXcFi7o89Qj5v6hH?= =?us-ascii?Q?okaviXzMtjzwsieUx+zdpfKHW8KYQsE3YbRog8BJIdpJyhXzPLFSx0XNrw?= =?us-ascii?Q?=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5483.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13e4bcc1-c448-404c-dc3d-08db57717280 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 May 2023 07:28:16.6618 (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: 93RR+pl7H+Ia/meRDxUZ/aRpCfl90uxMGtA1ysQkAmQnAfvZNNi58kWRFIhgwfJSDjE0ftByrEdK9u/jwoLudg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB7968 Return-Path: dun.tan@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ray, Thanks for the comments. I'll refine the commit message according to your s= uggestions in V2 version patch. Thanks, Dun -----Original Message----- From: Ni, Ray =20 Sent: Thursday, May 18, 2023 2:59 PM To: Tan, Dun ; devel@edk2.groups.io Cc: Kinney, Michael D ; Gao, Liming ; Liu, Zhiguang Subject: RE: [PATCH] MdePkg: Code optimization to SMM InternalAllocateAlign= edPages Dun, I can understand what you are trying to describe in the commit message. I have some suggestions/questions that might help you refine the commit mes= sage a bit better. Code changes look good to me. Thanks, Ray > -----Original Message----- > From: Tan, Dun > Sent: Thursday, May 18, 2023 2:37 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Kinney, Michael D=20 > ; Gao, Liming ;=20 > Liu, Zhiguang > Subject: [PATCH] MdePkg: Code optimization to SMM=20 > InternalAllocateAlignedPages >=20 > This commit is code optimization to InternalAllocateAlignedPages of=20 > SmmMemoryAllocationLib which can reduce free memory fragments. Also it=20 > 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=20 > allocate 4 pages and then find the first 8KB-aligned address in the=20 > allocated 4 pages. If the limit address is already 8KB aligned, then 1. What's "limit address"? > 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=20 > address to lower address, then the higher 2 pages cann't be merged=20 > other free pages, causing the free memory fragments. >=20 > However, when only allocate 3(2+2-1) pages, we can avoid the free=20 > memory fragments in specific case. Also 3 pages must contain a=20 > 8kb-aligned 8kb range, which meets the requirement. If the limit of=20 > allocated 3 pages is 8KB-aligned, then the last 8K range will 2. What's "last 8k"?