[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 07/15] efi: mm: Always request a fixed number of pages on init
From: |
Daniel Axtens |
Subject: |
[PATCH v3 07/15] efi: mm: Always request a fixed number of pages on init |
Date: |
Thu, 21 Apr 2022 15:24:19 +1000 |
From: Patrick Steinhardt <ps@pks.im>
When initializing the EFI memory subsytem, 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>
---
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 d8e4114541a4..0bccd24f304f 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;
@@ -478,23 +477,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,
@@ -583,8 +565,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;
/* Prepare a memory region to store two memory maps. */
@@ -624,22 +604,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. */
--
2.32.0
- [PATCH v3 00/15] Dynamic allocation of memory regions and IBM vTPM v2, Daniel Axtens, 2022/04/21
- [PATCH v3 01/15] grub-shell: only pass SeaBIOS fw_opt in for x86 BIOS platforms, Daniel Axtens, 2022/04/21
- [PATCH v3 02/15] mm: assert that we preserve header vs region alignment, Daniel Axtens, 2022/04/21
- [PATCH v3 03/15] mm: when adding a region, merge with region after as well as before, Daniel Axtens, 2022/04/21
- [PATCH v3 04/15] mm: debug support for region operations, Daniel Axtens, 2022/04/21
- [PATCH v3 05/15] mm: Drop unused unloading of modules on OOM, Daniel Axtens, 2022/04/21
- [PATCH v3 06/15] mm: Allow dynamically requesting additional memory regions, Daniel Axtens, 2022/04/21
- [PATCH v3 07/15] efi: mm: Always request a fixed number of pages on init,
Daniel Axtens <=
- [PATCH v3 08/15] efi: mm: Extract function to add memory regions, Daniel Axtens, 2022/04/21
- [PATCH v3 09/15] efi: mm: Pass up errors from `add_memory_regions ()`, Daniel Axtens, 2022/04/21
- [PATCH v3 10/15] efi: mm: Implement runtime addition of pages, Daniel Axtens, 2022/04/21
- [PATCH v3 11/15] ieee1275: request memory with ibm, client-architecture-support, Daniel Axtens, 2022/04/21
- [PATCH v3 12/15] ieee1275: drop len -= 1 quirk in heap_init, Daniel Axtens, 2022/04/21
- [PATCH v3 13/15] ieee1275: support runtime memory claiming, Daniel Axtens, 2022/04/21
- [PATCH v3 15/15] ibmvtpm: Add support for trusted boot using a vTPM 2.0, Daniel Axtens, 2022/04/21
- [PATCH v3 14/15] [RFC] Add memtool module with memory allocation stress-test, Daniel Axtens, 2022/04/21