[PATCH 0/6] kexec: enable kexec_crash_size to support two crash kernel regions

From: Zhen Lei
Date: Sat May 27 2023 - 08:36:14 EST


When crashkernel=X fails to reserve region under 4G, it will fall back to
reserve region above 4G and a region of the default size will also be reserved
under 4G. Unfortunately, /sys/kernel/kexec_crash_size only supports one crash
kernel region now, the user cannot sense the low memory reserved by reading
/sys/kernel/kexec_crash_size. Also, low memory cannot be freed by writing this
file.

For example:
resource_size(crashk_res) = 512M
resource_size(crashk_low_res) = 256M

The result of 'cat /sys/kernel/kexec_crash_size' is 512M, but it should be 768M.
When we execute 'echo 0 > /sys/kernel/kexec_crash_size', the size of crashk_res
becomes 0 and resource_size(crashk_low_res) is still 256 MB, which is incorrect.

Since crashk_res manages the memory with high address and crashk_low_res manages
the memory with low address, crashk_low_res is shrunken only when all crashk_res
is shrunken. And because when there is only one crash kernel region, crashk_res
is always used. Therefore, if all crashk_res is shrunken and crashk_low_res still
exists, swap them.


Zhen Lei (6):
kexec: fix a memory leak in crash_shrink_memory()
kexec: delete a useless check in crash_shrink_memory()
kexec: clear crashk_res if all its memory has been released
kexec: improve the readability of crash_shrink_memory()
kexec: add helper __crash_shrink_memory()
kexec: enable kexec_crash_size to support two crash kernel regions

kernel/kexec_core.c | 92 +++++++++++++++++++++++++++++++--------------
1 file changed, 64 insertions(+), 28 deletions(-)

--
2.25.1