kdump-load: Parse the biggest RAM buffer for pstore
The way kdump-load parses /proc/iomem currently expects it has only a single RAM buffer - but what if we have more, how to choose? This commit enables multi RAM buffers parsing, and the tool now copes with various available buffers, selecting the biggest one. Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
This commit is contained in:
@ -74,6 +74,27 @@ clear_all_initrds() {
|
|||||||
rm -f "${MOUNT_FOLDER}"/kdump-initrd-*
|
rm -f "${MOUNT_FOLDER}"/kdump-initrd-*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Next routine parses /proc/iomem to obtain the biggest RAM buffer
|
||||||
|
# available. Saves the results in 2 global variables: MEM_{SIZE,START}.
|
||||||
|
parse_ram_buffers() {
|
||||||
|
BUFFERS="$(grep "RAM buffer" /proc/iomem)"
|
||||||
|
while read -r line
|
||||||
|
do
|
||||||
|
RANGE=$(echo "$line" | cut -f1 -d\ )
|
||||||
|
|
||||||
|
MEM_END=$(echo "$RANGE" | cut -f2 -d-)
|
||||||
|
MSTART=$(echo "$RANGE" | cut -f1 -d-)
|
||||||
|
MSIZE=$(( 16#${MEM_END} - 16#${MSTART} ))
|
||||||
|
|
||||||
|
if [ ${MSIZE} -gt "${MEM_SIZE}" ]; then
|
||||||
|
MEM_SIZE="${MSIZE}"
|
||||||
|
MEM_START="${MSTART}"
|
||||||
|
fi
|
||||||
|
done <<< "${BUFFERS}"
|
||||||
|
# Trick to preserve global variables modifications inside loops
|
||||||
|
# using here-strings got from https://stackoverflow.com/a/16854326 .
|
||||||
|
}
|
||||||
|
|
||||||
# Function to display basic help about how to use this tool.
|
# Function to display basic help about how to use this tool.
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@ -132,13 +153,11 @@ preamble
|
|||||||
if [ "${USE_PSTORE_RAM}" -eq 1 ]; then
|
if [ "${USE_PSTORE_RAM}" -eq 1 ]; then
|
||||||
MEM_REQUIRED="${PSTORE_MEM_AMOUNT}"
|
MEM_REQUIRED="${PSTORE_MEM_AMOUNT}"
|
||||||
RECORD_SIZE="${PSTORE_RECORD_SZ}"
|
RECORD_SIZE="${PSTORE_RECORD_SZ}"
|
||||||
RANGE=$(grep "RAM buffer" /proc/iomem | head -n1 | cut -f1 -d\ )
|
MEM_SIZE=0
|
||||||
|
|
||||||
MEM_END=$(echo "$RANGE" | cut -f2 -d-)
|
parse_ram_buffers
|
||||||
MEM_START=$(echo "$RANGE" | cut -f1 -d-)
|
|
||||||
MEM_SIZE=$(( 16#${MEM_END} - 16#${MEM_START} ))
|
|
||||||
|
|
||||||
if [ ${MEM_SIZE} -ge "${MEM_REQUIRED}" ]; then
|
if [ "${MEM_SIZE}" -gt 0 ]; then
|
||||||
if modprobe ramoops mem_address=0x"${MEM_START}" mem_size="${MEM_REQUIRED}" record_size="${RECORD_SIZE}"; then
|
if modprobe ramoops mem_address=0x"${MEM_START}" mem_size="${MEM_REQUIRED}" record_size="${RECORD_SIZE}"; then
|
||||||
# If Pstore is set, update grub.cfg to avoid reserving crashkernel memory.
|
# If Pstore is set, update grub.cfg to avoid reserving crashkernel memory.
|
||||||
logger "kdump: pstore-RAM was loaded successfully"
|
logger "kdump: pstore-RAM was loaded successfully"
|
||||||
|
|||||||
Reference in New Issue
Block a user