linuxディスクIOテスト
4451 ワード
man 2 fsyncはfsyncが本当にファイルのデータをディスクに書き込むことを知っています.
しかし3.2のkernalでテストしたところfsyncは一度集中してやったほうがいいことがわかりました.
fsync実行プロセスは、各ブロックが修正されているかどうかを判断せず、ディスクをブラシする可能性があります.(確認待ち)
[size] time consume:xxxms
このとき測定した
[131072] time consume: 5531ms
[262144] time consume: 2718ms
[524288] time consume: 1464ms
[1048576] time consume: 926ms
[2097152] time consume: 628ms
[4194304] time consume: 404ms
[8388608] time consume: 305ms
[16777216] time consume: 256ms
16777216 = 2^24
でも次のfsyncで見つけたら
[131072] time consume: 331ms
[262144] time consume: 264ms
[524288] time consume: 239ms
[1048576] time consume: 264ms
[2097152] time consume: 239ms
[4194304] time consume: 264ms
[8388608] time consume: 239ms
[16777216] time consume: 263ms
それともmmapが力を与えるのか
....
[64] time consume: 41ms
[128] time consume: 42ms
[256] time consume: 41ms
[512] time consume: 41ms
[1024] time consume: 41ms
[2048] time consume: 41ms
[4096] time consume: 33ms
[8192] time consume: 33ms
[16384] time consume: 33ms
[32768] time consume: 33ms
[65536] time consume: 41ms
[131072] time consume: 42ms
[262144] time consume: 41ms
[524288] time consume: 41ms
[1048576] time consume: 50ms
[2097152] time consume: 74ms
[4194304] time consume: 107ms
[8388608] time consume: 141ms
前の多くのsizeは違いますが、ディスクに書き込む時間は同じで、ディスクのブロック特性を説明しています.
fdisk -l
Disk/dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes/4096 bytes
I/O size (minimum/optimal): 4096 bytes/4096 bytes
Disk identifier: 0xe0940810
しかし3.2のkernalでテストしたところfsyncは一度集中してやったほうがいいことがわかりました.
fsync実行プロセスは、各ブロックが修正されているかどうかを判断せず、ディスクをブラシする可能性があります.(確認待ち)
const int SIZE = 1 << 24;
char buf[SIZE];
void test(int size) {
int fd = open("txt", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
int count = SIZE / size;
for (int i = 0; i < count; ++i) {
write(fd, buf, size);
fsync(fd);
}
//fsync(fd);
close(fd);
}
[size] time consume:xxxms
このとき測定した
[131072] time consume: 5531ms
[262144] time consume: 2718ms
[524288] time consume: 1464ms
[1048576] time consume: 926ms
[2097152] time consume: 628ms
[4194304] time consume: 404ms
[8388608] time consume: 305ms
[16777216] time consume: 256ms
16777216 = 2^24
でも次のfsyncで見つけたら
[131072] time consume: 331ms
[262144] time consume: 264ms
[524288] time consume: 239ms
[1048576] time consume: 264ms
[2097152] time consume: 239ms
[4194304] time consume: 264ms
[8388608] time consume: 239ms
[16777216] time consume: 263ms
それともmmapが力を与えるのか
....
[64] time consume: 41ms
[128] time consume: 42ms
[256] time consume: 41ms
[512] time consume: 41ms
[1024] time consume: 41ms
[2048] time consume: 41ms
[4096] time consume: 33ms
[8192] time consume: 33ms
[16384] time consume: 33ms
[32768] time consume: 33ms
[65536] time consume: 41ms
[131072] time consume: 42ms
[262144] time consume: 41ms
[524288] time consume: 41ms
[1048576] time consume: 50ms
[2097152] time consume: 74ms
[4194304] time consume: 107ms
[8388608] time consume: 141ms
struct node {
int fd_, size_;
node () { }
node (int fd, int size) {
fd_ = fd;
size_ = size;
}
};
void test_prefetch(node t) {
char *p = (char*)mmap(NULL, t.size_, PROT_WRITE, MAP_SHARED, t.fd_, 0);
if (p == MAP_FAILED) {
perror("mmap");
exit(1);
}
memcpy(p, buf, t.size_);
msync(p, t.size_, MS_SYNC);
munmap(p, t.size_);
}
前の多くのsizeは違いますが、ディスクに書き込む時間は同じで、ディスクのブロック特性を説明しています.
fdisk -l
Disk/dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes/4096 bytes
I/O size (minimum/optimal): 4096 bytes/4096 bytes
Disk identifier: 0xe0940810