[kexec-tools/f16] Add debug_mem_level debugging option, resolve Bug 731395

Cong Wang wangcong at fedoraproject.org
Wed Aug 31 10:54:25 UTC 2011


commit d208970dc85964aaba159be67acc73318c5d50b8
Author: Amerigo Wang <amwang at redhat.com>
Date:   Wed Aug 31 18:53:34 2011 +0800

    Add debug_mem_level debugging option, resolve Bug 731395

 kdump.conf       |   10 +++++
 kdump.conf.5     |   15 +++++++
 kexec-tools.spec |    6 ++-
 mkdumprd         |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 1 deletions(-)
---
diff --git a/kdump.conf b/kdump.conf
index 2d05493..66797b8 100644
--- a/kdump.conf
+++ b/kdump.conf
@@ -95,6 +95,15 @@
 #				  Exiting this shell reboots the system.
 #			  NOTE: If no default action is specified, the initramfs
 #				will mount the root file system and run init.
+#
+# debug_mem_level <0-3>
+#                       - Turns on debug/verbose output of kdump scripts
+#                         regarding free/used memory at various points of
+#                         execution. Higher level means more debugging output.
+#                         0 - no output
+#                         1 - partial /proc/meminfo
+#                         2 - /proc/meminfo
+#                         3 - /proc/meminfo + /proc/slabinfo
 
 #raw /dev/sda5
 #ext4 /dev/sda3
@@ -110,4 +119,5 @@
 #disk_timeout 30
 #extra_modules gfs2
 #default shell
+#debug_mem_level 0
 
diff --git a/kdump.conf.5 b/kdump.conf.5
index 2949f89..5f62a3d 100644
--- a/kdump.conf.5
+++ b/kdump.conf.5
@@ -155,6 +155,21 @@ on service start if this invalid configuration is specified.  Also note that if
 no default action is specified, reboot is implied.
 .RE
 
+.B debug_mem_level <0-3>
+.RS
+Turns on debug/verbose output of kdump scripts regarding free/used memory at
+various points of execution. Higher level means more debugging output.
+.PP
+0 - no output
+.PP
+1 - partial /proc/meminfo
+.PP
+2 - /proc/meminfo
+.PP
+3 - /proc/meminfo + /proc/slabinfo
+.RE
+
+
 .SH EXAMPLES
 
 see 
diff --git a/kexec-tools.spec b/kexec-tools.spec
index 0afb0b3..a3dc59e 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -1,6 +1,6 @@
 Name: kexec-tools
 Version: 2.0.2
-Release: 26%{?dist}
+Release: 27%{?dist}
 License: GPLv2
 Group: Applications/System
 Summary: The kexec/kdump userspace component.
@@ -282,6 +282,10 @@ done
 
 
 %changelog
+* Wed Aug 31 2011 Cong Wang <xiyou.wangcong at gmail.com> - 2.0.2-27
+- Add debug_mem_level debugging option, from Jan Stancek.
+  Resolve Bug 731395.
+
 * Mon Aug 15 2011 Cong Wang <xiyou.wangcong at gmail.com> - 2.0.2-26
 - Fix several issues caused by the previous revert.
 
diff --git a/mkdumprd b/mkdumprd
index 0abe921..befe603 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -75,6 +75,8 @@ extra_kdump_mods=""
 
 TMPDISKLIST=`mktemp /tmp/disklist.XXXXXX`
 
+DEBUG_MEM_LEVEL="0"
+
 vecho()
 {
     NONL=""
@@ -116,6 +118,71 @@ usage () {
     fi
 }
 
+function make_trace_mem()
+{
+    # parameters: msg [trace_level:trace]...
+    msg=$1
+    shift
+    if [ "$DEBUG_MEM_LEVEL" -gt 0 ]; then
+        make_trace show_memstats $DEBUG_MEM_LEVEL "[debug_mem]" "$msg" "$@"
+    fi
+}
+
+function make_trace()
+{
+    # parameters: func log_level prefix msg [trace_level:trace]...
+    func=$1
+    shift
+
+    log_level=`echo "$1" | grep -o '^[0-9]\+'`
+    shift
+
+    prefix=$1
+    shift
+
+    msg=$1
+    shift
+
+    if [ -z "$log_level" ]; then
+        return
+    fi
+
+    # deal with indentation
+    space_at_front=`echo "$msg" | grep -o "^[[:space:]]\+"`
+    msg=`echo "$msg" | sed 's/^\s\+//'`
+
+    msg_printed=0
+    while [ $# -gt 0 ]; do
+        trace_level=`echo "$1" | grep -o '^[0-9]\+'`
+        trace_in_higher_levels=`echo "$1" | grep -o '+'`
+        trace=`echo $1 | sed "s/^.*://"`
+
+        if [ -z "$trace_level" ]; then
+            trace_level=0
+        fi
+
+        insert_trace=0
+        if [ -n "$trace_in_higher_levels" ]; then
+            if [ "$log_level" -ge "$trace_level" ]; then
+                insert_trace=1
+            fi
+        else
+            if [ "$log_level" -eq "$trace_level" ]; then
+                insert_trace=1
+            fi
+        fi
+
+        if [ $insert_trace -eq 1 ]; then
+            if [ $msg_printed -eq 0 ]; then
+                emit "${space_at_front}echo \"$prefix $msg\""
+                msg_printed=1
+            fi
+            emit "${space_at_front}$func $trace"
+        fi
+        shift
+    done
+}
+
 moduledep() {
     if [ ! -f "/lib/modules/$kernel/modules.dep" ]; then
 	error "No dep file found for kernel $kernel"
@@ -1115,6 +1182,15 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
         disk_timeout)
             DISK_TIMEOUT=$config_val
             ;;
+        debug_mem_level)
+            DEBUG_MEM_LEVEL=$config_val
+            echo "$DEBUG_MEM_LEVEL" | grep "^[0-3]$" &> /dev/null
+            if [ $? -ne 0 ]
+            then
+                echo "debug_mem_level is valid only for range 0-3"
+                exit 1
+            fi
+            ;;
         *)
             IS_COMMENT=`echo $config_opt | grep "^#.*$"`
             if [ -n "$IS_COMMENT" -o -z "$config_opt" ]
@@ -1377,6 +1453,28 @@ chmod 755 $MNTIMAGE/usr/share/udhcpc/default.script
 SCRIPTDIR=$MNTIMAGE/scriptfns
 mkdir -p $SCRIPTDIR
 
+cat >> $SCRIPTDIR/show_memstats << EOF
+#!/bin/msh
+while [ \$# -gt 0 ]; do
+    case \$1 in
+        shortmem)
+            cat /proc/meminfo  | grep -e "^MemFree" -e "^Cached" -e "^Slab"
+            ;;
+        mem)
+            cat /proc/meminfo
+            ;;
+        slab)
+            cat /proc/slabinfo
+            ;;
+        iomem)
+            cat /proc/iomem
+            ;;
+    esac
+    shift
+done
+echo
+EOF
+
 cat >> $SCRIPTDIR/map_interface << EOF
 #!/bin/msh
 if [ -e /tmp/tmpcnt ]
@@ -1710,6 +1808,7 @@ for i in 0 1 2 3 ; do
     emit "mknod /dev/ttyS$i c 4 $(($i + 64))"
 done
 emit "mknod /dev/mem c 1 1"
+make_trace_mem "At init start" 1+:mem 2+:iomem 3+:slab
 for MODULE in $MODULES; do
     text=""
     module=`echo $MODULE | sed "s|.*/||" | sed "s/.k\?o$//"`
@@ -1731,6 +1830,7 @@ for MODULE in $MODULES; do
     fi
     emit "echo \"Loading $fullmodule module\""
     emit "insmod /lib/$fullmodule $options"
+    make_trace_mem "After module $fullmodule has been loaded" 1:shortmem 2+:mem 3+:slab
 
     # Hack - we need a delay after loading usb-storage to give things
     #        time to settle down before we start looking a block devices
@@ -1774,6 +1874,7 @@ do
     echo Found
 done
 EOF
+make_trace_mem "After block device discovery" 1:shortmem 2+:mem 3+:slab
     
 # HACK: module loading + device creation isn't necessarily synchronous...
 # this will make sure that we have all of our devices before trying
@@ -1818,6 +1919,7 @@ emit "          MD_MIN=\`echo \$i | sed -e's/\(^.*\)\([0-9]\+$\)/\2/'\`"
 emit "          mknod \$i b 9 \$MD_MIN"
 emit "  done"
 emit "fi"
+make_trace_mem "After creation of block devices" 1:shortmem 2+:mem 3+:slab
 
 if [ -n "$vg_list" ]; then
     emit "echo Making device-mapper control node"
@@ -1868,6 +1970,7 @@ if [ -n "$vg_list" ]; then
     emit "   fi"
     emit "done"
 fi
+make_trace_mem "After scanning logical volumes" 1:shortmem 2+:mem 3+:slab
 
 kdump_chk()
 {
@@ -1934,6 +2037,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                         emit "fi"
                     fi
                     emit "echo Saving to partition $config_val"
+                    make_trace_mem "Before dumping vmcore" 1:shortmem 2+:mem 3+:slab
                     emit "monitor_dd_progress 512 &"
                     if [ -z "$CORE_COLLECTOR" ]
                     then
@@ -1948,6 +2052,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                     emit "  echo -e \"\\\033[0JSaving core complete\""
                     emit "fi"
                     emit "sync"
+                    make_trace_mem "After dumping vmcore" 1:shortmem 2+:mem 3+:slab
                     if [ -x "$KDUMP_POST" ]; then
                         emit "$KDUMP_POST \$exitcode"
                     fi
@@ -2049,6 +2154,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                         emit "  mkdir -p /mnt/$SAVE_PATH/$lhost-\$DATE"
                         emit "  VMCORE=/mnt/$SAVE_PATH/$lhost-\$DATE/vmcore"
                         emit "  export VMCORE"
+                        make_trace_mem "  Before dumping vmcore" 1:shortmem 2+:mem 3+:slab
                         emit "  monitor_cp_progress \$VMCORE-incomplete &"
                         emit "  $CORE_COLLECTOR /proc/vmcore \$VMCORE-incomplete >/dev/null"
                         emit "  exitcode=\$?"
@@ -2057,6 +2163,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                         emit "      mv \$VMCORE-incomplete \$VMCORE"
                         emit "      echo -e \"\\\033[0JSaving core complete\""
                         emit "  fi"
+                        make_trace_mem "  After dumping vmcore" 1:shortmem 2+:mem 3+:slab
                         if [ -x "$KDUMP_POST" ]; then
                             emit "  $KDUMP_POST \$exitcode"
                         fi
@@ -2116,6 +2223,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                         emit "ssh -q -o BatchMode=yes -o StrictHostKeyChecking=no $rlocation mkdir $SAVE_PATH/$lhost-\$DATE"
                         emit "VMCORE=$SAVE_PATH/$lhost-\$DATE/vmcore"
                         emit "export VMCORE"
+                        make_trace_mem "Before dumping vmcore" 1:shortmem 2+:mem 3+:slab
                         emit "monitor_scp_progress $rlocation $SAVE_PATH/$lhost-\$DATE/vmcore-incomplete &"
                         if [ -z "$CORE_COLLECTOR" ]
                         then
@@ -2134,6 +2242,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                         fi
                         emit "  echo -e \"\\\033[0JSaving core complete\""
                         emit "fi"
+                        make_trace_mem "After dumping vmcore" 1:shortmem 2+:mem 3+:slab
                         if [ -x "$KDUMP_POST" ]; then
                             emit "$KDUMP_POST \$exitcode"
                         fi
@@ -2162,6 +2271,8 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                     ;;
                 path)
                     ;;
+                debug_mem_level)
+                    ;;
                 *)
                     #test filesystem and directory creation
                     kdump_chk "test -f /sbin/fsck.$config_opt" "Unsupported type $config_opt"
@@ -2219,6 +2330,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                     if [ "$CORE_COLLECTOR" == "cp" ]; then
                         emit "  monitor_cp_progress \$VMCORE-incomplete &"
                     fi
+                    make_trace_mem "  Before dumping vmcore" 1:shortmem 2+:mem 3+:slab
                     emit "  $CORE_COLLECTOR /proc/vmcore \$VMCORE-incomplete >/dev/null"
                     emit "  exitcode=\$?"
                     emit "  if [ \$exitcode == 0 ]"
@@ -2227,6 +2339,7 @@ if [ -n "$KDUMP_CONFIG_FILE" ]; then
                     emit "      echo -e \"\\\033[0JSaving core complete\""
                     emit "  fi"
                     emit "  sync"
+                    make_trace_mem "  After dumping vmcore" 1:shortmem 2+:mem 3+:slab
                     if [ -x "$KDUMP_POST" ]; then
                         emit "  $KDUMP_POST \$exitcode"
                     fi


More information about the scm-commits mailing list