[PATCH 2/2] Shrink segments to fit alignment instead of throwing them away
Hongyan Xia
hx242 at xen.org
Tue Apr 6 15:11:53 BST 2021
From: Hongyan Xia <hongyxia at amazon.com>
We risk throwing an entire large chunk away if it is just slightly
unaligned which then causes the crash kernel to run out of RAM. Keep
them and shrink them to alignment.
Signed-off-by: Hongyan Xia <hongyxia at amazon.com>
---
kexec/arch/i386/crashdump-x86.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index c79791f2b3e0..3fcb19ad76d6 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -475,9 +475,18 @@ static int add_memmap(struct memory_range *memmap_p, int *nr_memmap,
int i, j, nr_entries = 0, tidx = 0, align = 1024;
unsigned long long mstart, mend;
- /* Do alignment check if it's RANGE_RAM */
- if ((type == RANGE_RAM) && ((addr%align) || (size%align)))
- return -1;
+ /* Shrink to 1KiB alignment if needed. */
+ if (type == RANGE_RAM && ((addr%align) || (size%align))) {
+ unsigned long long end = addr + size;
+
+ printf("%s: RAM chunk %#llx - %#llx unaligned\n", __func__, addr, end);
+ addr = _ALIGN_UP(addr, align);
+ end = _ALIGN_DOWN(end, align);
+ if (addr >= end)
+ return -1;
+ size = end - addr;
+ printf("%s: RAM chunk shrunk to %#llx - %#llx\n", __func__, addr, end);
+ }
/* Make sure at least one entry in list is free. */
for (i = 0; i < CRASH_MAX_MEMMAP_NR; i++) {
--
2.23.3
More information about the kexec
mailing list