]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Add default stack checking
authorBrian Behlendorf <behlendorf1@llnl.gov>
Sun, 12 Jun 2011 05:48:49 +0000 (22:48 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 13 Jun 2011 20:50:21 +0000 (13:50 -0700)
When your kernel is built with kernel stack tracing enabled and you
have the debugfs filesystem mounted.  Then the zfs.sh script will clear
the worst observed kernel stack depth on module load and check the worst
case usage on module removal.  If the stack depth ever exceeds 7000
bytes the full stack will be printed for debugging.  This is dangerously
close to overrunning the default 8k stack.

This additional advisory debugging is particularly valuable when running
the regression tests on a kernel built with 16k stacks.  In this case,
almost no matter how bad the stack overrun is you will see be able to
get a clean stack trace for debugging.  Since the worst case stack usage
can be highly variable it's helpful to always check the worst case usage.

scripts/common.sh.in
scripts/zfs.sh

index cf558594502daf67ce5b5cbf4b2714b66bf9d6b4..51671ebc019314bae11f39022f2745479ad3f427 100644 (file)
@@ -635,3 +635,29 @@ wait_udev() {
 
        return 0
 }
 
        return 0
 }
+
+stack_clear() {
+       local STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size
+       local STACK_TRACER_ENABLED=/proc/sys/kernel/stack_tracer_enabled
+
+       if [ -e $STACK_MAX_SIZE ]; then
+               echo 1 >$STACK_TRACER_ENABLED
+               echo 0 >$STACK_MAX_SIZE
+       fi
+}
+
+stack_check() {
+       local STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size
+       local STACK_TRACE=/sys/kernel/debug/tracing/stack_trace
+       local STACK_LIMIT=7000
+
+       if [ -e $STACK_MAX_SIZE ]; then
+               STACK_SIZE=`cat $STACK_MAX_SIZE`
+
+               if [ $STACK_SIZE -ge $STACK_LIMIT ]; then
+                       echo
+                       echo "Warning: max stack size $STACK_SIZE bytes"
+                       cat $STACK_TRACE
+               fi
+       fi
+}
index 4a707fabf34019a4a49c04086d85d5a1f728c93e..f44053e888ea4dac31aab057ffc79d05de2b26ef 100755 (executable)
@@ -66,8 +66,10 @@ fi
 
 if [ ${UNLOAD} ]; then
        umount -t zfs -a
 
 if [ ${UNLOAD} ]; then
        umount -t zfs -a
+       stack_check
        unload_modules
 else
        unload_modules
 else
+       stack_clear
        check_modules || die "${ERROR}"
        load_modules "$@"
        wait_udev /dev/zfs 30
        check_modules || die "${ERROR}"
        load_modules "$@"
        wait_udev /dev/zfs 30