Created
March 26, 2025 20:46
-
-
Save syuu1228/a1e686f8281e88eada4f3768f93ef6e6 to your computer and use it in GitHub Desktop.
fio benchmark script
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 | |
DEV_NAME=$1 | |
DEV_NODE=$(basename $DEV_NAME) | |
if [ "$DEV_NAME" = "" ]; then | |
echo "device not specified" | |
exit 1 | |
fi | |
function CheckHasFS | |
{ | |
local device=$1 # The device path. | |
# Check whether the device exists. | |
if [ ! -b "$device" ]; then | |
echo "Error: The $device device does not exist." | |
exit 1 | |
fi | |
# Run the blkid command to check the partition table and file system type. | |
local pt_type=$(sudo blkid -o value -s PTTYPE "$device") | |
local fs_type=$(sudo blkid -o value -s TYPE "$device") | |
if [ -n "$pt_type" ] || [ -n "$fs_type" ]; then | |
return 1 | |
else | |
return 0 | |
fi | |
} | |
CheckHasFS "$DEV_NAME" | |
if [ $? -eq 1 ]; then | |
echo "The $DEV_NAME device contains a partition table or a file system. The fio script is stopped." | |
exit 1 | |
fi | |
function RunFio | |
{ | |
numjobs=$1 # The number of test threads. In this example, the value is 10. | |
iodepth=$2 # The maximum number of concurrent I/O requests. In this example, the value is 64. | |
bs=$3 # The data block size per I/O. In this example, the value is 4k. | |
rw=$4 # The read and write policy. In this example, the value is randwrite. | |
size=$5 | |
filename=$6 # The name of the test file. In this example, the value is /dev/your_device. | |
nr_cpus=`cat /proc/cpuinfo |grep "processor" |wc -l` | |
if [ $nr_cpus -lt $numjobs ];then | |
echo "The value of the numjobs parameter is greater than the number of CPU cores. The test is stopped." | |
exit -1 | |
fi | |
let nu=$numjobs+1 | |
cpulist="" | |
for ((i=1;i<10;i++)) | |
do | |
list=`cat /sys/block/$DEV_NODE/mq/*/cpu_list | awk '{if(i<=NF) print $i;}' i="$i" | tr -d ',' | tr '\n' ','` | |
if [ -z $list ];then | |
break | |
fi | |
cpulist=${cpulist}${list} | |
done | |
spincpu=`echo $cpulist | cut -d ',' -f 2-${nu}` | |
echo $spincpu | |
fio --ioengine=libaio --runtime=30s --numjobs=${numjobs} --iodepth=${iodepth} --bs=${bs} --size=${size} --rw=${rw} --filename=${filename} --time_based=1 --direct=1 --name=test --group_reporting --cpus_allowed=$spincpu --cpus_allowed_policy=split --output $bs-$rw.json --output-format=json | |
} | |
echo 2 > /sys/block/$DEV_NODE/queue/rq_affinity | |
sleep 5 | |
NR_CPUS=`cat /proc/cpuinfo |grep "processor" |wc -l` | |
RunFio $NR_CPUS 128 4k randwrite 1024g $DEV_NAME | |
RunFio $NR_CPUS 128 4k randread 1024g $DEV_NAME | |
RunFio $NR_CPUS 128 1024k write 1024g $DEV_NAME | |
RunFio $NR_CPUS 128 1024k read 1024g $DEV_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment