[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 09/19] mm: Allow dynamically requesting additional memory reg
From: |
Daniel Kiper |
Subject: |
Re: [PATCH 09/19] mm: Allow dynamically requesting additional memory regions |
Date: |
Tue, 9 Nov 2021 14:25:15 +0100 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Tue, Oct 12, 2021 at 06:29:58PM +1100, Daniel Axtens wrote:
> From: Patrick Steinhardt <ps@pks.im>
>
> Currently, all platforms will set up their heap on initialization of the
> platform code. While this works mostly fine, it poses some limitations
> on memory management on us. Most notably, allocating big chunks of
> memory in the gigabyte range would require us to pre-request this many
> bytes from the firmware and add it to the heap from the beginning on
> some platforms like EFI. As this isn't needed for most configurations,
> it is inefficient and may even negatively impact some usecases when,
> e.g., chainloading. Nonetheless, allocating big chunks of memory is
> required sometimes, where one example is the upcoming support for the
> Argon2 key derival function in LUKS2.
>
> In order to avoid pre-allocating big chunks of memory, this commit
> implements a runtime mechanism to add more pages to the system. When a
> given allocation cannot be currently satisfied, we'll call a given
> callback set up by the platform's own memory management subsystem,
> asking it to add a memory area with at least `n` bytes. If this
> succeeds, we retry searching for a valid memory region, which should now
> succeed.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> [dja: add this to the documentation at the top of mm.c]
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
> grub-core/kern/mm.c | 13 +++++++++++++
> include/grub/mm.h | 16 ++++++++++++++++
> 2 files changed, 29 insertions(+)
>
> diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c
> index 6038c0d0cbb2..58d5b89e8860 100644
> --- a/grub-core/kern/mm.c
> +++ b/grub-core/kern/mm.c
> @@ -28,6 +28,9 @@
> - multiple regions may be used as free space. They may not be
> contiguous.
>
> + - if existing regions are insufficient to satisfy an allocation, a new
> + region can be requested from firmware.
> +
> Regions are managed by a singly linked list, and the meta information is
> stored in the beginning of each region. Space after the meta information
> is used to allocate memory.
> @@ -81,6 +84,7 @@
>
>
> grub_mm_region_t grub_mm_base;
> +grub_mm_add_region_func_t grub_mm_add_region_fn;
>
> /* Get a header from the pointer PTR, and set *P and *R to a pointer
> to the header and a pointer to its region, respectively. PTR must
> @@ -377,6 +381,15 @@ grub_memalign (grub_size_t align, grub_size_t size)
> count++;
> goto again;
>
> + case 1:
> + /* Request additional pages. */
> + count++;
> +
> + if (grub_mm_add_region_fn && grub_mm_add_region_fn (size,
> GRUB_MM_ADD_REGION_CONSECUTIVE) == GRUB_ERR_NONE)
if (grub_mm_add_region_fn != NULL && ...
If you fix this you can add Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
> + goto again;
> +
> + /* fallthrough */
> +
> default:
> break;
> }
Daniel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH 09/19] mm: Allow dynamically requesting additional memory regions,
Daniel Kiper <=