From e943b8785fa19ab5536d91242f1063ae809cdf2b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 2 Feb 2010 09:48:13 +0100 Subject: [PATCH] Track last file offset Avoids doing an lseek() in the sync IO engine. Signed-off-by: Jens Axboe --- engines/sync.c | 6 ++++++ file.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/engines/sync.c b/engines/sync.c index c375e9a8..12b85f6a 100644 --- a/engines/sync.c +++ b/engines/sync.c @@ -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 dc22d4e0..2abe3ba4 100644 --- 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)); } -- 2.25.1