Last active
December 3, 2019 11:03
-
-
Save mirzak/ca0b5a622761beb3b97a483395ec9e47 to your computer and use it in GitHub Desktop.
Testing disk write speed on embedded Linux devices (WARNING! USE WITH CARE! As it might overwrite your system partitions )
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 | |
# This script copies data synchronously from one block device to a second one. | |
# | |
# It will perform the same operation using multiple block sizes, which makes | |
# it easy to find the optimal one for the current device and configuration. | |
# | |
# WARNING! | |
# | |
# This will blindly write data to a partition and if not used with care, it | |
# has the possibility overwrite your system partitions! | |
set -e | |
# Clear PageCache, dentries and inodes. | |
function drop_cache() { | |
sync; echo 3 > /proc/sys/vm/drop_caches | |
} | |
INPUT_FILE=$1 | |
OUTPUT_FILE=$2 | |
if [ ! -b ${INPUT_FILE} ] || [ ! -b ${OUTPUT_FILE} ] \ | |
|| [ -z "${INPUT_FILE}" ] || [ -z "${OUTPUT_FILE}" ]; then | |
echo "You must specify block devices as arguments...." | |
echo "" | |
echo "Usage:" | |
echo " ./write-speed-test.sh /dev/mmcblk0p2 /dev/mmcblk0p3" | |
exit 1 | |
fi | |
INPUT_FILE_SIZE=$(blockdev --getsize64 ${INPUT_FILE}) | |
OUTPUT_FILE_SIZE=$(blockdev --getsize64 ${OUTPUT_FILE}) | |
if [ ${INPUT_FILE_SIZE} -ne ${OUTPUT_FILE_SIZE} ]; then | |
echo "The input and target block device size do not match" | |
echo "Input size: ${INPUT_FILE_SIZE}" | |
echo "Input size: ${OUTPUT_FILE_SIZE}" | |
exit 1 | |
fi | |
echo "Block size: $(( ${INPUT_FILE_SIZE} / 1024 / 1024 )) MiB (${INPUT_FILE_SIZE})" | |
#sizes=(512 1KiB 4KiB 8KiB 16KiB 32KiB 64KiB 512KiB 1MiB 4MiB 8Mib) | |
sizes=(1KiB 4KiB 8KiB 16KiB 32KiB 64KiB 128KiB 256KiB 512KiB 1MiB 4MiB 8MiB) | |
for size in "${sizes[@]}"; do | |
echo "" | |
echo "************************************************************" | |
echo "Testing with ${size} block size" | |
drop_cache | |
time dd if=${INPUT_FILE} of=${OUTPUT_FILE} bs=${size} oflag=dsync | |
echo "************************************************************" | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment