]> git.ipfire.org Git - thirdparty/grub.git/commit
mm: Allow dynamically requesting additional memory regions
authorPatrick Steinhardt <ps@pks.im>
Thu, 21 Apr 2022 05:24:18 +0000 (15:24 +1000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Mon, 4 Jul 2022 12:25:41 +0000 (14:25 +0200)
commit887f98f0db43e33fba4ec1f85e42fae1185700bc
tree89fdfcea7073dd1bf596c5abfbc248ab0ac71c62
parent139fd9b134a01e0b5fe0ebefafa7f48d1ffb6d60
mm: Allow dynamically requesting additional memory regions

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.

If this fails, we try asking for "n" bytes, possibly spread across
multiple regions, in hopes that region merging means that we end up
with enough memory for things to work out.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Patrick Steinhardt <ps@pks.im>
grub-core/kern/mm.c
include/grub/mm.h