Blame SOURCES/0303-kern-efi-mm-Always-request-a-fixed-number-of-pages-o.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Patrick Steinhardt <ps@pks.im>
fd0330
Date: Thu, 21 Apr 2022 15:24:19 +1000
fd0330
Subject: [PATCH] kern/efi/mm: Always request a fixed number of pages on init
fd0330
fd0330
When initializing the EFI memory subsystem, we will by default request
fd0330
a quarter of the available memory, bounded by a minimum/maximum value.
fd0330
Given that we're about to extend the EFI memory system to dynamically
fd0330
request additional pages from the firmware as required, this scaling of
fd0330
requested memory based on available memory will not make a lot of sense
fd0330
anymore.
fd0330
fd0330
Remove this logic as a preparatory patch such that we'll instead defer
fd0330
to the runtime memory allocator. Note that ideally, we'd want to change
fd0330
this after dynamic requesting of pages has been implemented for the EFI
fd0330
platform. But because we'll need to split up initialization of the
fd0330
memory subsystem and the request of pages from the firmware, we'd have
fd0330
to duplicate quite some logic at first only to remove it afterwards
fd0330
again. This seems quite pointless, so we instead have patches slightly
fd0330
out of order.
fd0330
fd0330
Signed-off-by: Patrick Steinhardt <ps@pks.im>
fd0330
Signed-off-by: Daniel Axtens <dja@axtens.net>
fd0330
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
fd0330
Tested-by: Patrick Steinhardt <ps@pks.im>
fd0330
(cherry picked from commit 938c3760b8c0fca759140be48307179b50107ff6)
fd0330
---
fd0330
 grub-core/kern/efi/mm.c | 35 +++--------------------------------
fd0330
 1 file changed, 3 insertions(+), 32 deletions(-)
fd0330
fd0330
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
fd0330
index e460b072e6..782a1365a1 100644
fd0330
--- a/grub-core/kern/efi/mm.c
fd0330
+++ b/grub-core/kern/efi/mm.c
fd0330
@@ -38,9 +38,8 @@
fd0330
    a multiplier of 4KB.  */
fd0330
 #define MEMORY_MAP_SIZE	0x3000
fd0330
 
fd0330
-/* The minimum and maximum heap size for GRUB itself.  */
fd0330
-#define MIN_HEAP_SIZE	0x100000
fd0330
-#define MAX_HEAP_SIZE	(1600 * 0x100000)
fd0330
+/* The default heap size for GRUB itself in bytes.  */
fd0330
+#define DEFAULT_HEAP_SIZE	0x100000
fd0330
 
fd0330
 static void *finish_mmap_buf = 0;
fd0330
 static grub_efi_uintn_t finish_mmap_size = 0;
fd0330
@@ -514,23 +513,6 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
fd0330
   return filtered_desc;
fd0330
 }
fd0330
 
fd0330
-/* Return the total number of pages.  */
fd0330
-static grub_efi_uint64_t
fd0330
-get_total_pages (grub_efi_memory_descriptor_t *memory_map,
fd0330
-		 grub_efi_uintn_t desc_size,
fd0330
-		 grub_efi_memory_descriptor_t *memory_map_end)
fd0330
-{
fd0330
-  grub_efi_memory_descriptor_t *desc;
fd0330
-  grub_efi_uint64_t total = 0;
fd0330
-
fd0330
-  for (desc = memory_map;
fd0330
-       desc < memory_map_end;
fd0330
-       desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
fd0330
-    total += desc->num_pages;
fd0330
-
fd0330
-  return total;
fd0330
-}
fd0330
-
fd0330
 /* Add memory regions.  */
fd0330
 static void
fd0330
 add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
fd0330
@@ -694,8 +676,6 @@ grub_efi_mm_init (void)
fd0330
   grub_efi_memory_descriptor_t *filtered_memory_map_end;
fd0330
   grub_efi_uintn_t map_size;
fd0330
   grub_efi_uintn_t desc_size;
fd0330
-  grub_efi_uint64_t total_pages;
fd0330
-  grub_efi_uint64_t required_pages;
fd0330
   int mm_status;
fd0330
 
fd0330
   grub_nx_init ();
fd0330
@@ -737,22 +717,13 @@ grub_efi_mm_init (void)
fd0330
   filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map,
fd0330
 					       desc_size, memory_map_end);
fd0330
 
fd0330
-  /* By default, request a quarter of the available memory.  */
fd0330
-  total_pages = get_total_pages (filtered_memory_map, desc_size,
fd0330
-				 filtered_memory_map_end);
fd0330
-  required_pages = (total_pages >> 2);
fd0330
-  if (required_pages < BYTES_TO_PAGES (MIN_HEAP_SIZE))
fd0330
-    required_pages = BYTES_TO_PAGES (MIN_HEAP_SIZE);
fd0330
-  else if (required_pages > BYTES_TO_PAGES (MAX_HEAP_SIZE))
fd0330
-    required_pages = BYTES_TO_PAGES (MAX_HEAP_SIZE);
fd0330
-
fd0330
   /* Sort the filtered descriptors, so that GRUB can allocate pages
fd0330
      from smaller regions.  */
fd0330
   sort_memory_map (filtered_memory_map, desc_size, filtered_memory_map_end);
fd0330
 
fd0330
   /* Allocate memory regions for GRUB's memory management.  */
fd0330
   add_memory_regions (filtered_memory_map, desc_size,
fd0330
-		      filtered_memory_map_end, required_pages);
fd0330
+		      filtered_memory_map_end, BYTES_TO_PAGES (DEFAULT_HEAP_SIZE));
fd0330
 
fd0330
 #if 0
fd0330
   /* For debug.  */