We will output memstrack analysis report in kexec-tools side during kdump.
Becasue kdump will use 'reboot -f' to reboot 2nd kernel by default,
which leaves no stable hook target to terminate memstrack and output its
analysis report in dracut side. However it is easy to implement in
kexec-tools side.
In this patch, we will place the memstrack report before do_kdump_pre()
for now, that is right before kdump starts, so kdump will not share memory
with memstrack. However if later we want memstrack to record memory status
during kdump as well, we can easily place it after do_kdump_post().
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
dracut-kdump.sh | 22 ++++++++++++++++++++++
dracut-module-setup.sh | 2 ++
2 files changed, 24 insertions(+)
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index 4eec70b..8096da4 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -574,6 +574,26 @@ fence_kdump_notify()
fi
}
+handle_memstrack_report()
+{
+ MEMSTRACK_LOG="/.memstrack"
+
+ if ! [ "$DEBUG_MEM_LEVEL" -ge 4 ]; then
+ return
+ fi
+
+ if pgrep -c '[m]emstrack' > /dev/null; then
+ pkill --signal INT '[m]emstrack'
+ while pgrep -c '[m]emstrack' > /dev/null; do
+ sleep 1
+ done
+ fi
+
+ if [ -e "$MEMSTRACK_LOG" ]; then
+ IFS= dinfo < "$MEMSTRACK_LOG"
+ fi
+}
+
if [ "$1" = "--error-handler" ]; then
get_kdump_confs
do_failure_action
@@ -599,6 +619,8 @@ if [ -z "$DUMP_INSTRUCTION" ]; then
DUMP_INSTRUCTION="dump_fs $NEWROOT"
fi
+handle_memstrack_report
+
if ! do_kdump_pre; then
derror "kdump_pre script exited with non-zero status!"
do_final_action
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index a8ac16c..37845e3 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -1033,6 +1033,8 @@ install() {
inst "/usr/bin/printf" "/sbin/printf"
inst "/usr/bin/logger" "/sbin/logger"
inst "/usr/bin/chmod" "/sbin/chmod"
+ inst "/usr/bin/pkill" "/usr/bin/pkill"
+ inst "/usr/bin/pgrep" "/usr/bin/pgrep"
inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh"
inst "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh"
inst "$moddir/kdump.sh" "/usr/bin/kdump.sh"
--
2.33.1