我有一个 USB 记忆棒,我正在尝试测量其读取和写入速度。我无法决定是否应该写入随机数据或零以及写入多少。我想尽可能快地完成此操作,但避免由于操作系统中的缓存而人为地报告速度过高。这是到目前为止我的程序:
测量写入速度
# Partition on the device under test
DEVICE=/dev/sdd5
WRITE_DATA=/tmp/write_data
READ_DATA=/tmp/read_data
BLOCK_COUNT=20
BLOCK_SIZE=524288
# Create a random test file to ensure data integrity.
dd if=/dev/urandom of=${WRITE_DATA} bs=${BLOCK_SIZE} count=${BLOCK_COUNT}
# Deactivate the cache.
hdparm -W0 ${DEVICE}
# Write.
dd if=${WRITE_DATA} of=${DEVICE} bs=${BLOCK_SIZE} count=${BLOCK_COUNT} oflag=direct
测量读取速度
# Cause the kernel to drop clean caches.
# See also: https://www.kernel.org/doc/Documentation/sysctl/vm.txt
echo 3 | sudo tee /proc/sys/vm/drop_caches
# Read.
dd if=${DEVICE} of=${READ_DATA} bs=${BLOCK_SIZE} count=${BLOCK_COUNT} oflag=direct
# Make sure we read back what we wrote.
cmp --silent ${WRITE_DATA} ${READ_DATA} || echo "Files are different."
# Cleanup.
rm ${WRITE_DATA} ${READ_DATA}
U 盘大小:128 GiB
操作系统:Ubuntu 16.04 LTS
问题:
什么是“足够大”的大小来躲避操作系统优化和结果中的噪音?这取决于我的操作系统或 U 盘大小吗?
我写/读回的数据内容重要吗?如果我不小心尝试环回内存中已有的内容(例如全 0 或 1),USB 记忆棒是否会优化?