Track last file offset
authorJens Axboe <jens.axboe@oracle.com>
Tue, 2 Feb 2010 08:48:13 +0000 (09:48 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 2 Feb 2010 08:48:13 +0000 (09:48 +0100)
Avoids doing an lseek() in the sync IO engine.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
engines/sync.c
file.h

index c375e9a8ca8212b148920feaf0452ea6590d2e23..12b85f6a65917c8e2fc197bd35c844bd61684b28 100644 (file)
@@ -33,6 +33,9 @@ static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
        if (ddir_sync(io_u->ddir))
                return 0;
 
+       if (f->file_pos != -1ULL && f->file_pos == io_u->offset)
+               return 0;
+
        if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
                td_verror(td, errno, "lseek");
                return 1;
@@ -43,6 +46,9 @@ static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
 
 static int fio_io_end(struct thread_data *td, struct io_u *io_u, int ret)
 {
+       if (io_u->file && ret >= 0)
+               io_u->file->file_pos = io_u->offset + ret;
+
        if (ret != (int) io_u->xfer_buflen) {
                if (ret >= 0) {
                        io_u->resid = io_u->xfer_buflen - ret;
diff --git a/file.h b/file.h
index dc22d4e058a177f373131acb370c838d4441b88f..2abe3ba4db9c3a3b04312aa6c9f6d4514547e4c0 100644 (file)
--- a/file.h
+++ b/file.h
@@ -74,6 +74,11 @@ struct fio_file {
 
        unsigned long long last_pos;
 
+       /*
+        * For use by the io engine
+        */
+       unsigned long long file_pos;
+
        /*
         * if io is protected by a semaphore, this is set
         */
@@ -147,6 +152,7 @@ static inline void fio_file_reset(struct fio_file *f)
 {
        f->last_free_lookup = 0;
        f->last_pos = f->file_offset;
+       f->file_pos = -1ULL;
        if (f->file_map)
                memset(f->file_map, 0, f->num_maps * sizeof(int));
 }