summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile13
-rw-r--r--results.txt257
-rw-r--r--test-file-zero-alloc-speed.c177
3 files changed, 447 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..482c49b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+# (C) Copyright 2009 Red Hat Inc.
+# Author: Amit Shah <amit.shah@redhat.com>
+
+CC = gcc
+CFLAGS = -Werror -Os
+
+.PHONY: all
+
+all: test-file-zero-alloc-speed
+
+clean:
+ rm -f *.o *~ test-file-zero-alloc-speed
+
diff --git a/results.txt b/results.txt
new file mode 100644
index 0000000..3618ec5
--- /dev/null
+++ b/results.txt
@@ -0,0 +1,257 @@
+-- These tests conducted on a laptop --
+
+1st run, with only posix-fallocate on ext3
+$ ./test-file-zero-speed
+seconds:microseconds: 1235557175:156446
+seconds:microseconds: 1235557212:186703
+
+-------------------------------------------------------------------
+
+2nd run, same program as above
+$ ./test-file-zero-speed
+seconds:microseconds: 1235557363:187840
+seconds:microseconds: 1235557396:43475
+
+-------------------------------------------------------------------
+
+3rd run, same program (with no printf between gtod() and actual call)
+$ ./test-file-zero-speed
+posix-fallocate run time:
+ seconds:microseconds: 1235558782:292459
+ seconds:microseconds: 1235558816:331028
+ (approx 34s)
+$ sudo filefrag ../tmp/10gfile-pf
+../tmp/10gfile-pf: 134 extents found, perfection would be 9 extents
+
+-------------------------------------------------------------------
+
+With all three:
+$ ./test-file-zero-speed
+posix-fallocate run time:
+ seconds:microseconds: 1235569716:953548
+ seconds:microseconds: 1235569749:595276
+ (approx 33s)
+mmap run time:
+ seconds:microseconds: 1235569749:595577
+ seconds:microseconds: 1235569789:622942
+ (approx 40s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235569791:134534
+ seconds:microseconds: 1235569839:132586
+ (approx 48s)
+$ sudo filefrag ../tmp/*
+../tmp/file-chunk: 57 extents found, perfection would be 9 extents
+../tmp/file-mmap: 106 extents found, perfection would be 9 extents
+../tmp/file-pf: 132 extents found, perfection would be 9 extents
+
+-------------------------------------------------------------------
+
+Added free(), 8k-chunk, close(fd) in time calculation
+
+$ free -m
+ total used free shared buffers cached
+Mem: 1954 859 1095 0 7 388
+-/+ buffers/cache: 462 1491
+Swap: 4094 742 3351
+$ ./test-file-zero-speed
+posix-fallocate run time:
+ seconds:microseconds: 1235571071:797642
+ seconds:microseconds: 1235571104:428998
+ (approx 33s)
+mmap run time:
+ seconds:microseconds: 1235571104:429523
+ seconds:microseconds: 1235571147:770146
+ (approx 43s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235571149:318119
+ seconds:microseconds: 1235571187:731919
+ (approx 38s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235571189:614692
+ seconds:microseconds: 1235571228:355714
+ (approx 39s)
+$ free -m
+ total used free shared buffers cached
+Mem: 1954 853 1101 0 1 415
+-/+ buffers/cache: 436 1517
+Swap: 4094 742 3351
+$ sudo filefrag ../tmp/*
+[sudo] password for amit:
+../tmp/file-chunk4: 60 extents found, perfection would be 9 extents
+../tmp/file-chunk8: 86 extents found, perfection would be 9 extents
+../tmp/file-mmap: 117 extents found, perfection would be 9 extents
+../tmp/file-pf: 133 extents found, perfection would be 9 extents
+
+-------------------------------------------------------------------
+
+
+-- These tests conducted on a desktop --
+
+$ sudo ./test-file-zero-speed /mnt/btrfs/
+posix-fallocate run time:
+ seconds:microseconds: 1235757533:559903
+ seconds:microseconds: 1235757533:560119
+ (approx 0s)
+mmap run time:
+ seconds:microseconds: 1235757533:564220
+ seconds:microseconds: 1235757551:589402
+ (approx 18s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235757552:688346
+ seconds:microseconds: 1235757572:585343
+ (approx 20s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235757576:143821
+ seconds:microseconds: 1235757592:424030
+ (approx 16s)
+
+-------------------------------------------------------------------
+
+sudo ./test-file-zero-speed /mnt/ext4/
+posix-fallocate run time:
+ seconds:microseconds: 1235757627:972541
+ seconds:microseconds: 1235757642:159940
+ (approx 15s)
+mmap run time:
+ seconds:microseconds: 1235757643:901565
+ seconds:microseconds: 1235757646:690830
+ (approx 3s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235757647:879737
+ seconds:microseconds: 1235757668:701027
+ (approx 21s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235757670:722389
+ seconds:microseconds: 1235757686:780528
+ (approx 16s)
+
+-------------------------------------------------------------------
+[ Extents were not enabled]
+
+$ sudo ./test-file-zero-alloc-speed /mnt/ext4
+posix-fallocate run time:
+ seconds:microseconds: 1235977123:542643
+ seconds:microseconds: 1235977137:673307
+ (approx 14s)
+mmap run time:
+ seconds:microseconds: 1235977137:673494
+ seconds:microseconds: 1235977154:435404
+ (approx 17s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235977155:826068
+ seconds:microseconds: 1235977173:98883
+ (approx 18s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235977174:91821
+ seconds:microseconds: 1235977190:862035
+ (approx 16s)
+
+$ sudo filefrag /mnt/ext4/*
+/mnt/ext4/file-chunk4: 292 extents found, perfection would be 9 extents
+/mnt/ext4/file-chunk8: 282 extents found, perfection would be 9 extents
+/mnt/ext4/file-mmap: 295 extents found, perfection would be 9 extents
+/mnt/ext4/file-pf: 279 extents found, perfection would be 9 extents
+
+-------------------------------------------------------------------
+
+[After enabling extents]
+$ sudo ./test-file-zero-alloc-speed /mnt/ext4
+posix-fallocate run time:
+ seconds:microseconds: 1235979104:790662
+ seconds:microseconds: 1235979104:848372
+ (approx 0s)
+mmap run time:
+ seconds:microseconds: 1235979105:33407
+ seconds:microseconds: 1235979118:535711
+ (approx 13s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235979120:297221
+ seconds:microseconds: 1235979135:520910
+ (approx 15s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235979135:639915
+ seconds:microseconds: 1235979153:502270
+ (approx 18s)
+
+$ sudo filefrag /mnt/ext4/*
+File is stored in extents format
+/mnt/ext4/file-chunk4: 29 extents found
+File is stored in extents format
+/mnt/ext4/file-chunk8: 20 extents found
+File is stored in extents format
+/mnt/ext4/file-mmap: 38 extents found
+File is stored in extents format
+/mnt/ext4/file-pf: 1 extent found
+
+-------------------------------------------------------------------
+$ sudo ./test-file-zero-alloc-speed /mnt/xfs/
+posix-fallocate run time:
+ seconds:microseconds: 1235977241:411119
+ seconds:microseconds: 1235977241:469611
+ (approx 0s)
+mmap run time:
+ seconds:microseconds: 1235977241:469981
+ seconds:microseconds: 1235977255:687663
+ (approx 14s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235977256:603450
+ seconds:microseconds: 1235977274:549963
+ (approx 18s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235977274:649325
+ seconds:microseconds: 1235977293:365759
+ (approx 19s)
+
+$ sudo filefrag /mnt/xfs/*
+/mnt/xfs/file-chunk4: 3 extents found
+/mnt/xfs/file-chunk8: 4 extents found
+/mnt/xfs/file-mmap: 2 extents found
+/mnt/xfs/file-pf: 1 extent found
+-------------------------------------------------------------------
+$ sudo ./test-file-zero-alloc-speed /mnt/ext3/
+posix-fallocate run time:
+ seconds:microseconds: 1235977308:469496
+ seconds:microseconds: 1235977326:366806
+ (approx 18s)
+mmap run time:
+ seconds:microseconds: 1235977326:367325
+ seconds:microseconds: 1235977346:260276
+ (approx 20s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235977347:161513
+ seconds:microseconds: 1235977369:771397
+ (approx 22s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235977369:865221
+ seconds:microseconds: 1235977393:23403
+ (approx 24s)
+
+$ sudo filefrag /mnt/ext3/*
+/mnt/ext3/file-chunk4: 38 extents found, perfection would be 9 extents
+/mnt/ext3/file-chunk8: 9 extents found
+/mnt/ext3/file-mmap: 44 extents found, perfection would be 9 extents
+/mnt/ext3/file-pf: 9 extents found
+-------------------------------------------------------------------
+$ sudo ./test-file-zero-alloc-speed /mnt/btrfs/
+posix-fallocate run time:
+ seconds:microseconds: 1235977416:649716
+ seconds:microseconds: 1235977416:650009
+ (approx 0s)
+mmap run time:
+ seconds:microseconds: 1235977416:650118
+ seconds:microseconds: 1235977434:626664
+ (approx 18s)
+4096-sized chunk run time:
+ seconds:microseconds: 1235977435:634000
+ seconds:microseconds: 1235977452:208026
+ (approx 17s)
+8192-sized chunk run time:
+ seconds:microseconds: 1235977452:294473
+ seconds:microseconds: 1235977471:143672
+ (approx 19s)
+
+$ sudo /mnt/btrfs/*
+FIBMAP: Invalid argument
+...
+-------------------------------------------------------------------
+-------------------------------------------------------------------
diff --git a/test-file-zero-alloc-speed.c b/test-file-zero-alloc-speed.c
new file mode 100644
index 0000000..8e8fe5c
--- /dev/null
+++ b/test-file-zero-alloc-speed.c
@@ -0,0 +1,177 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <asm/unistd.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#define GB (1024 * 1024 * 1024)
+
+int do_posix_fallocate(char *name, off_t len)
+{
+ int r, fd;
+ struct timeval tv1, tv2;
+
+ unlink(name);
+ fd = open(name, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+ if (fd < 0) {
+ perror("open");
+ return -1;
+ }
+
+ printf("posix-fallocate run time:\n");
+ gettimeofday(&tv1, NULL);
+ r = posix_fallocate(fd, 0, len);
+ close(fd);
+ gettimeofday(&tv2, NULL);
+ if (r < 0)
+ return r;
+ printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec);
+ printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec);
+ printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec);
+
+ return 0;
+}
+
+#if 1
+int do_fallocate(char *name, off_t len)
+{
+ int r, fd;
+ struct timeval tv1, tv2;
+
+ unlink(name);
+ fd = open(name, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+ if (fd < 0) {
+ perror("open");
+ return -1;
+ }
+
+ printf("fallocate run time:\n");
+ gettimeofday(&tv1, NULL);
+ r = syscall(__NR_fallocate, fd, 0, len);
+ close(fd);
+ gettimeofday(&tv2, NULL);
+ if (r < 0) {
+ perror("fallocate");
+ return r;
+ }
+ printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec);
+ printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec);
+ printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec);
+
+ return 0;
+}
+#endif
+
+int do_mmap(char *name, off_t len)
+{
+ int fd;
+ struct timeval tv1, tv2;
+ char *addr;
+
+ unlink(name);
+ fd = open(name, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+ if (fd < 0) {
+ perror("open");
+ return -1;
+ }
+ /* memset has to have the mmap'ed file backed by something on
+ * disk -- bus error otherwise */
+ lseek(fd, len - 1, SEEK_SET);
+ write(fd, "0", 1);
+
+ addr = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+ if (addr == MAP_FAILED) {
+ perror("mmap");
+ return -2;
+ }
+
+ printf("mmap run time:\n");
+ gettimeofday(&tv1, NULL);
+ memset(addr, 0, len);
+ munmap(addr, len);
+ close(fd);
+ gettimeofday(&tv2, NULL);
+
+ printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec);
+ printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec);
+ printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec);
+
+ return 0;
+}
+
+int do_write_chunks(char *name, off_t len, size_t chunk_size)
+{
+ int fd;
+ struct timeval tv1, tv2;
+
+ unsigned long long remain = len;
+ char *zeros;
+
+ zeros = calloc(1, len);
+
+ unlink(name);
+ fd = open(name, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+ if (fd < 0) {
+ perror("open");
+ return -1;
+ }
+
+ printf("%llu-sized chunk run time:\n", chunk_size);
+ gettimeofday(&tv1, NULL);
+ while (remain) {
+ int bytes = chunk_size;
+ if (bytes > remain)
+ bytes = remain;
+ if ((bytes = write(fd, zeros, bytes)) < 0) {
+ perror("write");
+ return -2;
+ }
+ remain -= bytes;
+ }
+ close(fd);
+ gettimeofday(&tv2, NULL);
+
+ printf("\tseconds:microseconds: %llu:%llu\n", tv1.tv_sec, tv1.tv_usec);
+ printf("\tseconds:microseconds: %llu:%llu\n", tv2.tv_sec, tv2.tv_usec);
+ printf("\t(approx %us)\n", tv2.tv_sec - tv1.tv_sec);
+ free(zeros);
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ char *basename;
+ char *filename;
+
+ if (argc < 2) {
+ printf("usage: %s base-dir\n", argv[0]);
+ return -1;
+ }
+
+ basename = argv[1];
+
+ sprintf(filename, "%s/file-pf", basename);
+ do_posix_fallocate(filename, 1 * GB);
+
+#if 0
+ sprintf(filename, "%s/file-pf", basename);
+ do_fallocate(filename, 1 * GB);
+#endif
+
+ sprintf(filename, "%s/file-mmap", basename);
+ do_mmap(filename, 1 * GB);
+
+ sprintf(filename, "%s/file-chunk4", basename);
+ do_write_chunks(filename, 1 * GB, 4 * 1024);
+
+ sprintf(filename, "%s/file-chunk8", basename);
+ do_write_chunks(filename, 1 * GB, 8 * 1024);
+
+ return 0;
+}