Don't re-create/unlink write file for append workload
[fio.git] / filesetup.c
index 4bfa470d0e285539e7de0d441c4d63aedd0eeb9c..5ce0f6803ae7d952c262d25728b1a60ec7bff86f 100644 (file)
@@ -50,10 +50,11 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
         * does that for operations involving reads, or for writes
         * where overwrite is set
         */
-       if (td_read(td) || (td_write(td) && td->o.overwrite) ||
+       if (td_read(td) ||
+          (td_write(td) && td->o.overwrite && !td->o.file_append) ||
            (td_write(td) && td->io_ops->flags & FIO_NOEXTEND))
                new_layout = 1;
-       if (td_write(td) && !td->o.overwrite)
+       if (td_write(td) && !td->o.overwrite && !td->o.file_append)
                unlink_file = 1;
 
        if (unlink_file || new_layout) {
@@ -722,8 +723,13 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
        return ret;
 }
 
-uint64_t get_start_offset(struct thread_data *td)
+uint64_t get_start_offset(struct thread_data *td, struct fio_file *f)
 {
+       struct thread_options *o = &td->o;
+
+       if (o->file_append && f->filetype == FIO_TYPE_FILE)
+               return f->real_file_size;
+
        return td->o.start_offset +
                (td->thread_number - 1) * td->o.offset_increment;
 }
@@ -810,7 +816,7 @@ int setup_files(struct thread_data *td)
        extend_size = total_size = 0;
        need_extend = 0;
        for_each_file(td, f, i) {
-               f->file_offset = get_start_offset(td);
+               f->file_offset = get_start_offset(td, f);
 
                if (!o->file_size_low) {
                        /*
@@ -1052,16 +1058,16 @@ void close_and_free_files(struct thread_data *td)
        dprint(FD_FILE, "close files\n");
 
        for_each_file(td, f, i) {
-               if (td->o.unlink && f->filetype == FIO_TYPE_FILE) {
-                       dprint(FD_FILE, "free unlink %s\n", f->file_name);
-                       unlink(f->file_name);
-               }
-
                if (fio_file_open(f))
                        td_io_close_file(td, f);
 
                remove_file_hash(f);
 
+               if (td->o.unlink && f->filetype == FIO_TYPE_FILE) {
+                       dprint(FD_FILE, "free unlink %s\n", f->file_name);
+                       unlink(f->file_name);
+               }
+
                sfree(f->file_name);
                f->file_name = NULL;
                axmap_free(f->io_axmap);