我正在尝试探索文件系统性能如何受到应用程序访问特性的显着影响。我想将请求大小从 1KB (1024) 更改为 64KB (65536)。
当我达到 8KB 时,我得到一个写入文件错误。我没有分配足够的空间吗?
./test
error writing file (rc = 200704, errno 0)
我在这里调整 1KB - 64KB 大小:
request_size = 32*(1<<13); /* 1KB is 1^10 (or 1<<10) */
所以,这应该是 8kb = 8192
我现在应该请求 4mb 文件吗?我不确定那会是什么转变?
int main(int c, char *argv[]) {
int fd;
void *buffer, *buffer_aligned;
int i, rc;
unsigned long file_size, request_size;
struct timeval start, stop;
double seconds;
/* allocate a 64KB page-aligned buffer */
buffer = malloc(65536+4096);
buffer_aligned = buffer+(4096-(((unsigned long)buffer)%4096));
/* write a 1MB file with 32KB requests */
fd = open("foo", O_CREAT|O_RDWR, 0644);
file_size = 1*(1<<20); /* 1MB is 2^20 (or 1<<20). 1GB is 2^30 (or 1<<30) */
request_size = 32*(1<<13); /* 1KB is 1^10 (or 1<<10) */
gettimeofday(&start, NULL);
for (i=0; i<file_size/request_size; i++) {
if ((rc=write(fd, buffer_aligned, request_size))!=request_size) {
fprintf(stderr, "error writing file (rc = %i, errno %i)\n", rc, errno);
return 1;
}
}
gettimeofday(&stop, NULL);
seconds = ((stop.tv_sec*1e6+stop.tv_usec)-(start.tv_sec*1e6+start.tv_usec))/1e6;
printf("file size is %uMB\n", file_size>>20);
printf("request size is %uKB\n", request_size>>13);
printf("elapsed time is %.2lf seconds\n", seconds);
printf("bandwidth is %.2lf MB/sec\n", file_size/seconds/(1<<20));
close(fd);
/* free buffer */
free(buffer);
return 0;
}
这不是8KB吗?
request_size = 32*(1<<13); /* 1KB is 1^10 (or 1<<10) */