Honor random/zero/compressible settings for filling an initial file
authorJens Axboe <axboe@kernel.dk>
Fri, 3 May 2013 13:12:33 +0000 (15:12 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 3 May 2013 13:12:33 +0000 (15:12 +0200)
Right now we only do that for when the job writes, do it for the
initial setup as well. Otherwise you just get zero filled files
initially, which might not be what you want.

Also fixes a bug with compression if compress_chunk isn't set.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
filesetup.c
io_u.c
ioengine.h

index 9f186fb46436a4d46998709a787050be24905316..6427f3e4e2317901159f7061ce9a74538d288aaa 100644 (file)
@@ -127,7 +127,6 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
        }
 
        b = malloc(td->o.max_bs[DDIR_WRITE]);
        }
 
        b = malloc(td->o.max_bs[DDIR_WRITE]);
-       memset(b, 0, td->o.max_bs[DDIR_WRITE]);
 
        left = f->real_file_size;
        while (left && !td->terminate) {
 
        left = f->real_file_size;
        while (left && !td->terminate) {
@@ -135,6 +134,8 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
                if (bs > left)
                        bs = left;
 
                if (bs > left)
                        bs = left;
 
+               fill_io_buffer(td, b, bs, bs);
+
                r = write(f->fd, b, bs);
 
                if (r > 0) {
                r = write(f->fd, b, bs);
 
                if (r > 0) {
diff --git a/io_u.c b/io_u.c
index d03049e52332e2b01510364863af812ecfd8e496..2cf2b8d0e398923590c01281b5082361d8c7eca1 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1602,14 +1602,9 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u)
        }
 }
 
        }
 }
 
-/*
- * "randomly" fill the buffer contents
- */
-void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
-                     unsigned int min_write, unsigned int max_bs)
+void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
+                   unsigned int max_bs)
 {
 {
-       io_u->buf_filled_len = 0;
-
        if (!td->o.zero_buffers) {
                unsigned int perc = td->o.compress_percentage;
 
        if (!td->o.zero_buffers) {
                unsigned int perc = td->o.compress_percentage;
 
@@ -1617,10 +1612,23 @@ void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
                        unsigned int seg = min_write;
 
                        seg = min(min_write, td->o.compress_chunk);
                        unsigned int seg = min_write;
 
                        seg = min(min_write, td->o.compress_chunk);
-                       fill_random_buf_percentage(&td->buf_state, io_u->buf,
+                       if (!seg)
+                               seg = min_write;
+
+                       fill_random_buf_percentage(&td->buf_state, buf,
                                                perc, seg, max_bs);
                } else
                                                perc, seg, max_bs);
                } else
-                       fill_random_buf(&td->buf_state, io_u->buf, max_bs);
+                       fill_random_buf(&td->buf_state, buf, max_bs);
        } else
        } else
-               memset(io_u->buf, 0, max_bs);
+               memset(buf, 0, max_bs);
+}
+
+/*
+ * "randomly" fill the buffer contents
+ */
+void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
+                     unsigned int min_write, unsigned int max_bs)
+{
+       io_u->buf_filled_len = 0;
+       fill_io_buffer(td, io_u->buf, min_write, max_bs);
 }
 }
index d52b2b97a274ca4faae4dedbbf9d7a37d623d723..362ab3e5d6bd8c923b66b8316b1386a2f8b761c9 100644 (file)
@@ -198,6 +198,7 @@ extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t
 extern void io_u_queued(struct thread_data *, struct io_u *);
 extern void io_u_log_error(struct thread_data *, struct io_u *);
 extern void io_u_mark_depth(struct thread_data *, unsigned int);
 extern void io_u_queued(struct thread_data *, struct io_u *);
 extern void io_u_log_error(struct thread_data *, struct io_u *);
 extern void io_u_mark_depth(struct thread_data *, unsigned int);
+extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
 void io_u_mark_complete(struct thread_data *, unsigned int);
 void io_u_mark_submit(struct thread_data *, unsigned int);
 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
 void io_u_mark_complete(struct thread_data *, unsigned int);
 void io_u_mark_submit(struct thread_data *, unsigned int);