From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.11291.1684393124399510312 for ; Wed, 17 May 2023 23:58:44 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=AdgRN2fL; spf=pass (domain: intel.com, ip: 192.55.52.93, 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=1684393124; x=1715929124; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=IS2MrPZ8954T/XqBc3muqie1NMCNgokiky5O0yn1edc=; b=AdgRN2fLRlw462eYx+c6hlabYjfFCOZrDzZljAixSYwBbNkwpEaWeawt WhPT5oonPo+EY4om4yPWbXVdM6lzgZzqTJIsKfkXDID9GlcVSVYVEuo0V F5ZZSHF/1kaQ/YN3UU5bU9EZPmWUYTgbIspiZs2KVLHJJZUzYs+62sPex ug4obDES4w1+yRFUKNeUKkHRvObGIKWzxz+YrJL3yeie7lqLO7WkV8uQi vphTk7F8cVKQTS6iCS57RcQBIuyi5YfRZ3BfHfE/0vd/9SE9vSujjjI9j 2blGDkQW6eLpb5tYXPGsohxm+cGb6tPSAtK9L9RL69WLGo/v5tv9M8XFU w==; X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="349498049" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="349498049" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2023 23:58:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10713"; a="652525498" X-IronPort-AV: E=Sophos;i="5.99,284,1677571200"; d="scan'208";a="652525498" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga003.jf.intel.com with ESMTP; 17 May 2023 23:58:43 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 17 May 2023 23:58:43 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) 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; Wed, 17 May 2023 23:58:42 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Wed, 17 May 2023 23:58:42 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.109) 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; Wed, 17 May 2023 23:58:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G/tK/QLFFuDpyGpHl1YS2C0UzxxX7UKa2nGA3UyZWLYRmU/XT3PhsRb37daNeZd211DMN5lXXYVP2LBgrT1WX1ND+jbZUHG0CHA35vzgQZhO2K9AjqWiDD8rXinJqL22wSfeP8JHIaDQVQaCBZ3xseCSsInLgN2tgfJCWAobORlBiP56Ly0GrbWOVXVR5Laag/NQK+rbun/DDR/Y7DFvoY5BG/YExqkG3Ni1nP0csTE4XQfzCrrLYNscyo1hoAO+gXKcOk8E9aUakQNUzkw5di8NaWcA2DX9cBRzVi8+WdX3jhChKl6vymiomPdG+4YFOfrZIksqTzqsFRZ2BcK1EA== 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=IS2MrPZ8954T/XqBc3muqie1NMCNgokiky5O0yn1edc=; b=gqYaa+VwbGjB+0wLLrzNMmUQhH9b2sz8OQqgcw8eV/JpPF0yqsCX7pWE5e0jvUgsIMVQe4X7TNueP5TX5dtNoO4PY8zLzqWWcFh5xO5x0tTTzw2HBPbGCCsS/LRamzF+goaJI9YETMxUPMQ0TVdSqHOgCv1ZshAgAH0wNwWvFU5783IkcLZjxkHdeoiDFGpRblc9xGt0xanxMQ6Ezeqym1KjcdGjM8Ek9L4mteXBOBzzot4cVh0HxL95SgrleNQpoP2T0Ov6iVwq/fnFXszzEGPGtXnNvpPOnIuuVQITAuHBT/DrZaD00tWSy63305xFB0YohrG0eN2Xah5sGwf8dQ== 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 SA1PR11MB6965.namprd11.prod.outlook.com (2603:10b6:806:2bf::10) 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 06:58:40 +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 06:58:39 +0000 From: "Ni, Ray" To: "Tan, Dun" , "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+AgFG69fl4hQ Date: Thu, 18 May 2023 06:58:39 +0000 Message-ID: References: <20230518063715.1703-1-dun.tan@intel.com> In-Reply-To: <20230518063715.1703-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_|SA1PR11MB6965:EE_ x-ms-office365-filtering-correlation-id: 57956101-2463-4581-cc17-08db576d4f70 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: m3swt2kWt9xpk6lk7A4lJOzgnf8yiERWA86kzzpZXnGO2hjwzTPvtMpE6bPYHZUmn5Ms0mNjSEI3ILNQau7OOfQgKjGAhnJT4o1j2ZiI7VplHnsu51vYvITp9PWDKkX5Z/blqDyifnLmfgLXGTe0YoIyvNo6k+gqk1vwKOxR8RQqyTUcpcVaDDB5X8p9e4GNcjc1lnqnkFo7WwMoJQ9Q+kYBd/5cLW3LEpxgQOpKl8WVo7alrT4AAdYWd77ZeFYTD8hyQBn8XcWXsce1y5jZWoBHgvWC3l7EhKz3EWWZGOROAVLxtx/WcXtyeN9zgNF1tnTgzloX86P3FK2rlcH8B4L1kqqdmgnFskgKq5cUfWujYUxlpIG3TZQsId2EeZ0tTO6NrQ0tyuPHUjkJRE9N+l56Bjg3j5XnUOnohSElVE2WrIcKZPD7B45VjfLYqaNDGvwBhVsy0tq1Yz8Cq+7Vhte1oxvLvnzR9fcZml3H662HKHpwScvRc253qdWufo/KEgoOEAnjh0V6e1webNv6HTyZYjp+z+eP8DqS1HxBeibY9R7KagrviqZ9IQAy0sX6+EDZl9xl/xIZJiCrr7PPQii+DHWR/ByBTtxjToc+CYkD9YT63rd5y40aUxvWqdla 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)(39860400002)(366004)(376002)(396003)(346002)(136003)(451199021)(86362001)(83380400001)(7696005)(82960400001)(41300700001)(33656002)(122000001)(5660300002)(52536014)(8676002)(38100700002)(316002)(38070700005)(66476007)(4326008)(66556008)(66446008)(55016003)(2906002)(66946007)(76116006)(64756008)(186003)(6506007)(107886003)(9686003)(26005)(8936002)(53546011)(71200400001)(110136005)(478600001)(54906003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?+kGSNYsrK3QyBuhz4J5ASAl+FXh9nXuoNnvJAOcdh+rddTBOEZeMTmrL/LUm?= =?us-ascii?Q?nwEJJLxWylWr5nWjlk9dQDmoV4wURcQmviodof6m9uxsZ+uT56EWnsIRZL0+?= =?us-ascii?Q?E9oufDr0YjIC+9QGRjbIElZaRNe/faSBs9hf7+kjMK8u/hUWQhhBJXew8RMW?= =?us-ascii?Q?JINNaAywn7Y0cydnGTUgVbAppz+qZRtHqdEs+ntfFPhXzywdZumwl3MITXBf?= =?us-ascii?Q?WPEpTC8rv6Cp+74tkRgC2NIuXvFdJhExQqCQRAcpxrmUC+09P9b1TyCubqCU?= =?us-ascii?Q?ps0gZL5uJsK/bt+Z93ue5w8Qv51DUQW10fazq0y6LD3zT7qkspRg1jbCktLp?= =?us-ascii?Q?2V15HGdFjibYIGBhYsPBp9uQ+X8Qvi+Qi225dr73X85Ej2ZiPmkpPH9/G0yP?= =?us-ascii?Q?H/SlNd37mZpjwQ06AhgYEad8zHfZpu59CNnbrVMYQhg36ZDwpvGq2jtUgssu?= =?us-ascii?Q?mMaiCzd87Ii1O2z6cJcpYUzOuKpcPSwJ3CB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J22egvsiuSJ0YnAeWU2Qff28MicVqlnMl+tIBorhbmrizWSFG?= =?us-ascii?Q?i5Zgri9xjfLwpOWSZxmo116rc48KtgwqD0xyb8ky3Qk3sF9bE6NNFh2Xb0xF?= =?us-ascii?Q?+prFTuYn/K6TYqrGKnv91/PtSbIFtAIlDomD95zRe+f60SEg6mVTLbXISXrl?= =?us-ascii?Q?G2Ctv7ZrFybVJOi4zVU=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: 57956101-2463-4581-cc17-08db576d4f70 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 May 2023 06:58:39.8385 (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: pLYU3YzS74dRlGsDy3728+67ve9ez0VPQwCd3HP4zTSTN1CEsq0wVOml3Ve0FPK/RO24QrTW64poM8AMuMhNLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB6965 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 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 > ; Gao, Liming ; Liu= , > Zhiguang > Subject: [PATCH] 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 the > 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 > address to lower address, then the higher 2 pages cann't be merged > 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 limit > of allocated 3 pages is 8KB-aligned, then the last 8K range will 2. What's "last 8k"?