Skip to content

Instantly share code, notes, and snippets.

@ZuluPro
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZuluPro/4b45ae39de7f348cf52e to your computer and use it in GitHub Desktop.
Save ZuluPro/4b45ae39de7f348cf52e to your computer and use it in GitHub Desktop.
Launch dd against block device with multiple jobs
#!/bin/bash
[[ -z "$1" ]] && echo "No given device" && exit 1
[[ -z "$2" ]] && echo "No given mode (read|write)" && exit 1
device=$1
mode=$2
cpu_num=$(cat /proc/cpuinfo | grep proc | wc -l)
bytes_to_write=$(fdisk -l $device | grep -E 'Disk .* bytes$' | awk '{print $(NF-1)}')
process_num=$((cpu_num*2))
count_by_process=$((bytes_to_write/1024/1024/process_num))
declare -a pids
# Launch dds
for p in $(seq 1 $process_num) ; do
if [[ "$mode" -eq 'read' ]] ; then
dd of=/dev/null if=$device bs=1M count=$count_by_process skip=$((count_by_process*p)) \
iflag=skip_bytes &
elif [[ "$mode" -eq 'write' ]] ; then
dd if=/dev/zero of=$device bs=1M count=$count_by_process seek=$((count_by_process*p)) \
oflag=seek_bytes oflag=direct &
else
echo "Bad acces mode '$mode' (read|write)" && exit
fi
pid=$!
pids[$pid]=$pid
echo "Launch dd ($pid)"
done
# Track dd tasks
while [[ $(echo ${pids[@]} | wc -w) -ne 0 ]] ; do
sleep 3
enumerate=0
for pid in "${pids[@]}"; do
sleep 1
echo "===== $pid ====="
kill -USR1 $pid 2> /dev/null
if [[ $? -ne 0 ]] ; then
unset pids[$pid]
echo "End dd ($pid)"
fi
done
done
sync
echo "Done"
@ZuluPro
Copy link
Author

ZuluPro commented Apr 3, 2015

Tests with RunAbove ra.intel.ha.l 50GB High-Speed and Ubuntu 14.04

Read:
dd : 150 seconds
mdd : 40 seconds

Write:
mdd : 160 seconds
dd : 190 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment