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