summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <clm@fb.com>2017-07-31 12:52:29 -0700
committerChris Mason <clm@fb.com>2017-07-31 12:52:29 -0700
commitdc487544aa0bfe68169450f5a5985bc147abac5f (patch)
treecb6d20a3a73a4de4a4bce1cf3c88efdb2bc31127
parent3479f8ced8621705ac5ac7590f66eaab91239421 (diff)
downloadsimoop-dc487544aa0bfe68169450f5a5985bc147abac5f.tar.gz
Add -z to use fallocate for creating initial file set
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r--simoop.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/simoop.c b/simoop.c
index d305795..6c25bb8 100644
--- a/simoop.c
+++ b/simoop.c
@@ -55,6 +55,7 @@
#define DATA_FILE NULL
#define RESULT_FILE "extra"
#define TMP_FILE "tmp"
+#define FILL_FILE "fill"
/* each path in the paths array gets a thread pool hammering on it. */
char **paths;
@@ -101,6 +102,9 @@ static int cpu_threads = 24;
/* how long we sleep while processing requests */
static int sleeptime = 10000;
+/* should we use fallocate instead of writing initial file contents */
+static int zallocate = 0;
+
static uint64_t global_rand_seed = 0x89ABCEF;
/*
@@ -418,7 +422,7 @@ unsigned long long parse_size(char *s)
return ret;
}
-char *option_string = "t:s:C:c:r:n:f:FR:T:m:W:M:w:i:D:oaOV";
+char *option_string = "t:s:C:c:r:n:f:FR:T:m:W:M:w:i:D:oaOVz";
static struct option long_options[] = {
{"appendmode", required_argument, 0, 'a'},
{"mmapsize", required_argument, 0, 'M'},
@@ -440,6 +444,7 @@ static struct option long_options[] = {
{"oddsizes", no_argument, 0, 'o'},
{"odirect", no_argument, 0, 'O'},
{"verifystartup", no_argument, 0, 'V'},
+ {"zallocate", no_argument, 0, 'z'},
{"help", no_argument, 0, HELP_LONG_OPT},
{0, 0, 0, 0}
};
@@ -467,6 +472,7 @@ static void print_usage(void)
"\t-F (--funksync): fsync sometimes\n"
"\t-o (--oddsizes): randomize sizes to unaligned values\n"
"\t-O (--odirect): use O_DIRECT sometimes\n"
+ "\t-z (--zallocate): use fallocate for initial file creation\n"
"\t dir1 [dir2 ... dirN]\n"
"\nall sizes are in bytes k,m,g,t modifiers can be used\n"
);
@@ -554,6 +560,9 @@ static void parse_options(int ac, char **av)
case 'V':
check_initial_files = 1;
break;
+ case 'z':
+ zallocate = 1;
+ break;
case '?':
case HELP_LONG_OPT:
print_usage();
@@ -1308,7 +1317,7 @@ static void write_to_file(char *path, int seq, char *buf)
if (append_mode) {
postfix = DATA_FILE;
- fd = open_path(path, seq, DATA_FILE, O_APPEND);
+ fd = open_path(path, seq, DATA_FILE, O_APPEND|O_CREAT);
offset = lseek(fd, 0, SEEK_CUR);
if (offset < 0) {
perror("lseek");
@@ -1372,8 +1381,18 @@ static void make_files(char *path, unsigned long seq_start,
if (read_size && check_initial_files)
read_whole_file(path, seq, DATA_FILE, buf, BUF_SIZE);
- fd = open_path(path, seq, DATA_FILE, O_APPEND);
- fill_one_file(fd, xxhash_state, buf, BUF_SIZE);
+ if (zallocate) {
+ loff_t this_size = randomize_size(file_size);
+ fd = open_path(path, seq, FILL_FILE, O_CREAT);
+ ret = fallocate(fd, 0, 0, this_size);
+ if (ret) {
+ perror("fallocate");
+ exit(1);
+ }
+ } else {
+ fd = open_path(path, seq, DATA_FILE, O_APPEND);
+ fill_one_file(fd, xxhash_state, buf, BUF_SIZE);
+ }
close(fd);
/* cleanup from the last run */
@@ -1408,6 +1427,7 @@ void run_filler_threads(void)
int ret;
int j;
pthread_t *tids;
+ pthread_t *this_tid;
tids = malloc(sizeof(*tids) * total_paths * FILES_SPLIT);
if (!tids) {
@@ -1415,6 +1435,7 @@ void run_filler_threads(void)
exit(1);
}
fprintf(stderr, "Creating working files\n");
+ this_tid = tids;
for (i = 0; i < total_paths; i++) {
for (j = 0; j < FILES_SPLIT; j++) {
pthread_t tid;
@@ -1429,12 +1450,15 @@ void run_filler_threads(void)
fprintf(stderr, "error %d from pthread_create\n", ret);
exit(1);
}
- tids[i * j] = tid;
+ *this_tid = tid;
+ this_tid++;
}
}
+ this_tid = tids;
for (i = 0; i < total_paths; i++) {
for (j = 0; j < FILES_SPLIT; j++) {
- pthread_join(tids[i * j], NULL);
+ pthread_join(*this_tid, NULL);
+ this_tid++;
}
}
fprintf(stderr, "done creating working files\n");