Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1l1Gmo-0000wa-5b for mharc-grub-devel@gnu.org; Sun, 17 Jan 2021 17:44:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Gmm-0000wT-VF for grub-devel@gnu.org; Sun, 17 Jan 2021 17:44:40 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:15513) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Gmk-0006H2-Rs for grub-devel@gnu.org; Sun, 17 Jan 2021 17:44:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1610923479; x=1642459479; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gCMQiryynfYfwlRJB2i2/TB4XASVfAjKZo3RV7Af2EM=; b=SnUhdkzMuK4gJG0wXTKsn8W33mQPFYAk5rAuAORceAT7mHwAWNlad9L5 OdN/Zquf5bf/X5Rg/ymy5/13jM1DfLHdLxnia/+eo2A5Z1PSzF6KeiX9Q VK8wVLpUm82d8GDuBI/zKipuu/8RbjvLo9dIzYLAs6klCrLYt5Cdc0kaJ s=; X-IronPort-AV: E=Sophos;i="5.79,355,1602547200"; d="scan'208";a="112776607" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2b-a7fdc47a.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 17 Jan 2021 22:44:36 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2b-a7fdc47a.us-west-2.amazon.com (Postfix) with ESMTPS id 5CB54C05A5; Sun, 17 Jan 2021 22:44:35 +0000 (UTC) Received: from EX13D07UWB002.ant.amazon.com (10.43.161.131) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 17 Jan 2021 22:44:34 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D07UWB002.ant.amazon.com (10.43.161.131) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 17 Jan 2021 22:44:34 +0000 Received: from 3c22fb124a25.ant.amazon.com (10.187.171.36) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 17 Jan 2021 22:44:34 +0000 From: Hanson Char To: , CC: Hanson Char Subject: [PATCH] Relax memory constraints on required_pages for EFI boot Date: Sun, 17 Jan 2021 14:43:50 -0800 Message-ID: <20210117224349.70436-1-hchar@amazon.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Received-SPF: pass client-ip=207.171.184.29; envelope-from=prvs=644bf40df=hchar@amazon.com; helo=smtp-fw-9102.amazon.com X-Spam_score_int: -147 X-Spam_score: -14.8 X-Spam_bar: -------------- X-Spam_report: (-14.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.189, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jan 2021 22:44:41 -0000 (Finally figured out how to git send-email on this patch properly.) As reported earlier, when booted in UEFI mode, Grub would fail to load a ramdisk of size larger than "(total_pages >> 2)" with "error: out of memory" (https://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/kern/efi/mm.c#n616) Further investigation into the EFI memory map indicates the current limit of MAX_HEAP_MEMORY and the use of a quarter of the total_pages returned from EFI available memory (type 7) as the default seems arbitrary and unnecessary. Therefore this proposed patch removes the aribrary limit, and lets Grub make full use of the EFI available memory reported by the BIOS. The patch has been successfully tested to load large ramdisk with size that would otherwise fail. Regards, Hanson Signed-off-by: Hanson Char --- grub-core/kern/efi/mm.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 457772d57..9cf6a4d34 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -38,9 +38,8 @@ a multiplier of 4KB. */ #define MEMORY_MAP_SIZE 0x3000 -/* The minimum and maximum heap size for GRUB itself. */ +/* The minimum heap size for GRUB itself. */ #define MIN_HEAP_SIZE 0x100000 -#define MAX_HEAP_SIZE (1600 * 0x100000) static void *finish_mmap_buf = 0; static grub_efi_uintn_t finish_mmap_size = 0; @@ -569,7 +568,6 @@ grub_efi_mm_init (void) grub_efi_memory_descriptor_t *filtered_memory_map_end; grub_efi_uintn_t map_size; grub_efi_uintn_t desc_size; - grub_efi_uint64_t total_pages; grub_efi_uint64_t required_pages; int mm_status; @@ -610,14 +608,10 @@ grub_efi_mm_init (void) filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map, desc_size, memory_map_end); - /* By default, request a quarter of the available memory. */ - total_pages = get_total_pages (filtered_memory_map, desc_size, - filtered_memory_map_end); - required_pages = (total_pages >> 2); + required_pages = get_total_pages (filtered_memory_map, desc_size, + filtered_memory_map_end); if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE)) required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE); - else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE)) - required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE); /* Sort the filtered descriptors, so that GRUB can allocate pages from smaller regions. */ -- 2.30.0