public
Created

Set disk values to maximize a resync, or restore the default settings. Dynamically detects the underlying volumes that make up the MD device. Based on the fine advice from Vivek Gite posted at http://www.cyberciti.biz/tips/linux-raid-increase-resync-rebuild-speed.html.

  • Download Gist
mdadm-fastsync
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#!/bin/zsh
#
# @author Jinn Ko <https://gist.github.com/jinnko>
# @since 2013-08-11
 
MD_DEV=$1
ACTION=$2
 
MIN_SPEED=50000
MAX_SPEED=200000
READAHEAD=$(( 512 * 512 ))
 
if [[ -z "$MD_DEV" || -z "$ACTION" ]]; then
echo "Set disk values to maximize a resync or restore the default settings."
echo "Dynamically detects the underlying volumes that make up the MD device."
echo
echo "Usage: $(basename $0) MD_DEV (fast|normal)"
echo "Both arguments are required, where:"
echo " MD_DEV the base name of the MD device. For example: md0"
echo " [fast|normal] 'fast' sets:"
echo " sync_speed_min = $MIN_SPEED"
echo " read ahead = $READAHEAD"
echo " ncq = 1"
echo " 'normal' attempts to return values to those saved"
echo " prior to using 'fast'."
echo
echo " e.g. $(basename $0) md0 fast"
exit 1
fi
 
if [ "$ACTION" = "fast" ]; then
echo "Setting fast config for $MD_DEV."
 
# Set min speed
echo $MIN_SPEED >! /sys/block/${MD_DEV}/md/sync_speed_min
echo $MAX_SPEED >! /sys/block/${MD_DEV}/md/sync_speed_max
 
# Set read ahead
[ ! -r /tmp/md-raid-${MD_DEV}-ra ] && blockdev --getra /dev/${MD_DEV} > /tmp/md-raid-${MD_DEV}-ra
blockdev --setra $READAHEAD /dev/${MD_DEV}
 
# Set strip-cache_size - increases us by approx 25% at this point
[ ! -r /tmp/md-raid-${MD_DEV}-stripe_cache_size ] && cat /sys/block/${MD_DEV}/md/stripe_cache_size > /tmp/md-raid-${MD_DEV}-stripe_cache_size
echo 32768 >! /sys/block/${MD_DEV}/md/stripe_cache_size
 
# Disable NCQ - increases performance by 200% !!!
cd /sys/block/${MD_DEV}/md
for x in {0..$(( $(cat /sys/block/${MD_DEV}/md/raid_disks) - 1))};do
RAID_DEV=${$(basename $(readlink -f rd$x))/dev\-/}
RAID_DEV=${RAID_DEV/[0-9]/}
[ ! -r /tmp/md-raid-${RAID_DEV}-ncq ] && cat /sys/block/${RAID_DEV}/device/queue_depth > /tmp/md-raid-${RAID_DEV}-ncq
echo 1 >! /sys/block/${RAID_DEV}/device/queue_depth
done
 
elif [ "$ACTION" = "normal" ]; then
echo "Setting fast config for $MD_DEV."
 
# Set min speed
echo 1000 >! /sys/block/${MD_DEV}/md/sync_speed_min
echo 200000 >! /sys/block/${MD_DEV}/md/sync_speed_max
 
# Set read ahead
if [ -r /tmp/md-raid-${MD_DEV}-ra ]; then
blockdev --setra $(cat /tmp/md-raid-${MD_DEV}-ra) /dev/${MD_DEV}
else
echo "Unable to reset readahead - no saved setting file"
fi
 
# Set strip-cache_size - increases us by approx 25% at this point
if [ -f /tmp/md-raid-${MD_DEV}-stripe_cache_size ]; then
cat /tmp/md-raid-${MD_DEV}-stripe_cache_size >! /sys/block/${MD_DEV}/md/stripe_cache_size
else
echo "Unable to reset strip_cache_size - no saved setting file"
fi
 
# Disable NCQ - increases performance by 200% !!!
cd /sys/block/${MD_DEV}/md
for x in {0..$(( $(cat /sys/block/${MD_DEV}/md/raid_disks) - 1))};do
RAID_DEV=${$(basename $(readlink -f rd$x))/dev\-/}
RAID_DEV=${RAID_DEV/[0-9]/}
if [ -r /tmp/md-raid-${RAID_DEV}-ncq ]; then
cat /tmp/md-raid-${RAID_DEV}-ncq >! /sys/block/${RAID_DEV}/device/queue_depth
else
echo "Unable to reset NCQ - no saved setting file"
fi
done
else
echo "Uknown action; $ACTION."
echo "Aborting"
exit 1
fi

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.