Skip to contentSkip to conversation

Remove unnecessary constraints on required_pages for EFI boot

PATCH In review Char, Hanson 2 participants 2 messages Jan 10, 2021 – Jan 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove unnecessary constraints on required_pages for EFI boot

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

From ceb27404eb281a74aa82799885cd74b530e9237e Mon Sep 17 00:00:00 2001
From: Hanson Char <[email protected]>
Date: Sun, 10 Jan 2021 10:57:06 -0800
Subject: [PATCH] Remove unnecessary constraints on required_pages for EFI boot

---
 grub-core/kern/efi/mm.c | 12 +++---------

 1 file changed, 3 insertions(+), 9 deletions(-)
grub-core/kern/efi/mm.c +0 -0
index 457772d57..9cf6a4d34 100644
@@ -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.29.2

#1 lore raw
Quoted 12 lines · Hanson via Grub-devel

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.

Quoted 6 lines

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.

Something is off with your patch. That text above should have been in the patch as a comment. And also your SoB in it. Could you kindly repost?

Quoted 3 lines

Regards,
Hanson

From ceb27404eb281a74aa82799885cd74b530e9237e Mon Sep 17 00:00:00 2001

Quoted 57 lines

From: Hanson Char <[email protected]>
Date: Sun, 10 Jan 2021 10:57:06 -0800
Subject: [PATCH] Remove unnecessary constraints on required_pages for EFI boot

---
 grub-core/kern/efi/mm.c | 12 +++---------

 1 file changed, 3 insertions(+), 9 deletions(-)
grub-core/kern/efi/mm.c +0 -0
index 457772d57..9cf6a4d34 100644
@@ -38,9 +38,8 @@

    a multiplier of 4KB.  */
 #define MEMORY_MAP_SIZE    0x3000

grub-core/kern/efi/mm.c +1 -1
-/* 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;

grub-core/kern/efi/mm.c +2 -7
@@ -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.29.2

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel