Last active
August 29, 2015 14:18
-
-
Save ZuluPro/4b45ae39de7f348cf52e to your computer and use it in GitHub Desktop.
Launch dd against block device with multiple jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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