1、背景
fio涉及到随机读写、blocksize、对齐等有以下几个参数
- randwrite/write
- blocksize/bs
- blocksize_range/bs_range
- blocksize_unaligned
- blockalign/ba
这几个参数和random搭配之后,fio会怎样准备IO的,以下的内容作了一些case,摸清楚了fio这几个参数的真实含义
2、准备
为了研究fio发送的每个io的位置(offset)和blocksize,准备了两个脚本用来收集和分析fio --debug=io的输出结果
#shell脚本
fio --debug=io jobfile > fio.log
grep queue: fio.log > queue.log
python read_queue.py
#read_queue.py
import re
f=open("queue.log","r")
offset_list=[]
bs_list=[]
pattern=re.compile(r'.*off=(\S+),len=(\S+),ddir')
for line in f.readlines():
match=pattern.match(line)
if match:
(offset,bs)=match.groups()
offset_list.append(int(offset,16)/512)
bs_list.append(int(bs,16)/512)
#每一个元素包含一个io起始的sector位置和io的长度
io_seq_list=zip(offset_list,bs_list)
#print io_seq_list
def choose_first(item):
return item[0]
#将随机的io顺序排列
io_seq_list.sort(key=choose_first)
print io_seq_list
3、测试结果
3.1 bs=4k 随机写
rw=randwrite
numjobs=1
bs=4k
size=1024k
测试结果:
#每个元素的第一个值为IO的offset,第二个值为block size(单位都是sector,下同)
[(0, 8), (8, 8), (16, 8), (24, 8), (32, 8), (40, 8), (48, 8), (56, 8), (64, 8), (72, 8), (80, 8), (88, 8), (96, 8), (104, 8), (112, 8),...]
- 随机写,整个io区间都被写过
3.2 ba=bs
rw=randwrite
numjobs=1
bs=4k
ba=4k
size=1024k
测试结果:
[(0, 8), (8, 8), (16, 8), (24, 8), (32, 8), (40, 8), (48, 8), (56, 8), (64, 8), (72, 8), (80, 8), (88, 8), (96, 8), (104, 8), (112, 8),...]
- 随机写,整个io区间都被写过
- ba默认值等于4k,测试结果和case1相同
3.3 ba=512b
rw=randwrite
numjobs=1
bs=4k
ba=512b
size=1024k
测试结果:
[(8, 8), (29, 8), (40, 8), (49, 8), (54, 8), (55, 8), (56, 8), (62, 8), (72, 8), (73, 8), (91, 8)...]
- 随机写,写完之后IO区域内有空洞(某些sector没有写过)
- ba=512b意味着offset会以512b对齐(也就是offset完全不对齐)
3.4 ba=4k bs=64k
rw=randwrite
numjobs=1
bs=64k
ba=4k
size=1024k
测试结果:
[(112, 128), (128, 128), (472, 128), (680, 128), (728, 128), (752, 128), (768, 128), (904, 128), (1072, 128), (1248, 128),...]
- 随机写,写完之后IO区域内有空洞(某些sector没有写过)
- ba=4k意味着offset会以4k对齐
3.5 write ba不等于bs
rw=write
numjobs=1
bs=64k
ba=2k
size=1024k
测试结果:
[(0, 128), (128, 128), (256, 128), (384, 128), (512, 128), (640, 128), (768, 128), (896, 128), (1024, 128), ,...]
- 顺序写,写完之后IO区域没有空洞
- ba参数在顺序写时无效,顺序读写完全按照block size对齐
3.6 write ba不等于bs,offset=1k
rw=write
numjobs=1
bs=64k
ba=2k
size=1024k
offset=1k
测试结果:
[(2, 128), (130, 128), (258, 128), (386, 128), (514, 128), (642, 128), (770, 128), (898, 128), (1026, 128), (1154, 128), ,...]
- 顺序写,写完之后IO区域没有空洞
- ba参数在顺序写时无效,顺序读写完全按照block size,在offset+size的空间内对齐
3.7 bsrange=2k-4k
rw=randwrite
numjobs=1
bsrange=2k-4k
size=1024k
测试结果:
[(0, 4), (4, 4), (8, 4), (12, 4), (16, 4), (20, 8), (28, 4), (32, 8), (40, 4), (44, 4), (48, 4), (52, 4),...]
- 随机写,写完之后IO区域没有空洞
- block size有2k和4k两种
3.8 bsrange=2k-4k ba=4k
rw=randwrite
numjobs=1
bsrange=2k-4k
size=1024k
ba=4k
测试结果:
[(0, 8), (8, 4), (24, 4), (32, 8), (40, 4), (48, 4), (48, 4), (48, 8), (56, 4), (56, 4), (64, 4), (72, 4), (72, 8), (80, 4), (88, 8), (88, 8)...]
- 随机写,写完之后IO区域有空洞,offset会以4k对齐
- block size只有2k和4k两种
- 同一个job中存在覆盖写的情况
3.9 bsrange=2k-4k bs_unaligned
rw=randwrite
numjobs=1
bsrange=2k-4k
size=1024k
bs_unaligned
测试结果: 报错,不能配置这样的参数
- bs_unaligned不能和direct的io同时使用
3.10 bsrange=512b-4k
rw=randwrite
numjobs=1
bsrange=512b-4k
size=1024k
测试结果:
[(0, 7), (7, 1), (8, 1), (9, 7), (16, 8), (24, 4), (28, 1), (29, 3), (32, 3), (35, 5), (40, 2), (42, 1), (43, 3), (46, 1), (47, 2), (49, 4), (53, 1), (54, 1),..]
- 随机写,写完之后IO区域内没有空洞
- block size有512b\1k\1.5k\2k\2.5k\3k\3.5k\4k
- 没有覆盖写的情况
3.11 bsrange=512b-4k numjobs=2
rw=randwrite
numjobs=2
bsrange=512b-4k
size=1024k
测试结果
[(0, 1), (0, 7), (1, 2), (3, 2), (5, 3), (7, 1), (8, 1), (8, 2), (9, 7), (10, 5), (15, 3), (16, 8), (18, 1), (19, 2), (21, 8), (24, 4), (28, 1), (29, 3), (29, 1), ...]
- 随机写,写完之后IO区域内没有空洞
- block size有512b\1k\1.5k\2k\2.5k\3k\3.5k\4k
- 存在覆盖写的情况