Commit 43f6d98d authored by Kirill Smelkov's avatar Kirill Smelkov

X bench for fallocate on tmpfs

parent 24397957
host: deco
os: Linux deco 4.13.0-1-amd64 #1 SMP Debian 4.13.13-1 (2017-11-16) x86_64 GNU/Linux
BenchmarkTmpfsFallocate/xpage=4K 786432 0.448 µs/op # t_total: 0.352s
BenchmarkTmpfsFallocate/xpage=32K 98304 2.653 µs/op # t_total: 0.261s
BenchmarkTmpfsFallocate/xpage=256K 12288 20.263 µs/op # t_total: 0.249s
BenchmarkTmpfsFallocate/xpage=2048K 1536 161.343 µs/op # t_total: 0.248s
// This program benchmarks fallocate on tmpfs
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/user.h>
#include <sys/mman.h>
// microtime returns current time as double
double microtime() {
int err;
struct timeval tv;
err = gettimeofday(&tv, NULL);
if (err == -1) {
perror("gettimeofday");
abort();
}
return tv.tv_sec + 1E-6 * tv.tv_usec;
}
int bench_tmpfs_fallocate(size_t xpagesize) {
int fd, err, i;
double Tstart, Tend;
fd = open("/dev/shm/y.dat", O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd == -1) {
perror("open");
abort();
}
size_t filesize = (3*1024*1024*1024ULL); // whole file size
//size_t xpagesize = 1 * PAGE_SIZE;
//size_t xpagesize = 512 * PAGE_SIZE;
size_t niter = filesize / xpagesize;
err = ftruncate(fd, filesize);
if (err == -1) {
perror("ftruncate");
abort();
}
Tstart = microtime();
for (i=0; i<niter; i++) {
err = fallocate(fd, /*mode*/0, i*xpagesize, xpagesize);
if (err == -1) {
perror("fallocate");
abort();
}
}
Tend = microtime();
printf("BenchmarkTmpfsFallocate/xpage=%ldK\t%ld\t%.3lf µs/op\t# t_total: %.3lfs\n",
xpagesize / 1024, niter, (Tend - Tstart) * 1E6 / niter, (Tend - Tstart));
err = close(fd);
if (err == -1) {
perror("close");
abort();
}
return 0;
}
int main() {
bench_tmpfs_fallocate(1*PAGE_SIZE);
bench_tmpfs_fallocate(8*PAGE_SIZE);
bench_tmpfs_fallocate(64*PAGE_SIZE);
bench_tmpfs_fallocate(512*PAGE_SIZE);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment