/*
* Hmm, should we make sure that ->io_size <= ->real_file_size?
+ * -> not for now since there is code assuming it could go either.
*/
max_size = f->io_size;
if (max_size > f->real_file_size)
if (f->last_pos[ddir] < f->real_file_size) {
uint64_t pos;
- if (f->last_pos[ddir] == f->file_offset && o->ddir_seq_add < 0)
- f->last_pos[ddir] = f->real_file_size;
+ if (f->last_pos[ddir] == f->file_offset && o->ddir_seq_add < 0) {
+ if (f->real_file_size > f->io_size)
+ f->last_pos[ddir] = f->io_size;
+ else
+ f->last_pos[ddir] = f->real_file_size;
+ }
pos = f->last_pos[ddir] - f->file_offset;
if (pos && o->ddir_seq_add) {
if (pos >= f->real_file_size) {
if (o->ddir_seq_add > 0)
pos = f->file_offset;
- else
- pos = f->real_file_size + o->ddir_seq_add;
+ else {
+ if (f->real_file_size > f->io_size)
+ pos = f->io_size;
+ else
+ pos = f->real_file_size;
+
+ pos += o->ddir_seq_add;
+ }
}
}
int ddir = io_u->ddir;
unsigned int buflen = 0;
unsigned int minbs, maxbs;
- uint64_t frand_max;
- unsigned long r;
+ uint64_t frand_max, r;
+ bool power_2;
assert(ddir_rw(ddir));
if (buflen < minbs)
buflen = minbs;
} else {
- long perc = 0;
+ long long perc = 0;
unsigned int i;
for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
buflen = bsp->bs;
perc += bsp->perc;
- if ((r * 100UL <= frand_max * perc) &&
+ if (!perc)
+ break;
+ if ((r / perc <= frand_max / 100ULL) &&
io_u_fits(td, io_u, buflen))
break;
}
}
- if (td->o.verify != VERIFY_NONE)
- buflen = (buflen + td->o.verify_interval - 1) &
- ~(td->o.verify_interval - 1);
-
- if (!td->o.bs_unaligned && is_power_of_2(minbs))
+ power_2 = is_power_of_2(minbs);
+ if (!td->o.bs_unaligned && power_2)
buflen &= ~(minbs - 1);
-
+ else if (!td->o.bs_unaligned && !power_2)
+ buflen -= buflen % minbs;
} while (!io_u_fits(td, io_u, buflen));
return buflen;
}
while (td->io_u_in_flight) {
- int fio_unused ret;
+ int ret;
ret = io_u_queued_complete(td, 1);
if (ret > 0)
completed += ret;
}
+ if (td->flags & TD_F_REGROW_LOGS)
+ regrow_logs(td);
+
return completed;
}
static enum fio_ddir rate_ddir(struct thread_data *td, enum fio_ddir ddir)
{
enum fio_ddir odir = ddir ^ 1;
- long usec, now;
+ long usec;
+ uint64_t now;
assert(ddir_rw(ddir));
now = utime_since_now(&td->start);
enum fio_ddir ddir;
/*
- * see if it's time to fsync
- */
- if (td->o.fsync_blocks &&
- !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks) &&
- td->io_issues[DDIR_WRITE] && should_fsync(td))
- return DDIR_SYNC;
-
- /*
- * see if it's time to fdatasync
+ * See if it's time to fsync/fdatasync/sync_file_range first,
+ * and if not then move on to check regular I/Os.
*/
- if (td->o.fdatasync_blocks &&
- !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks) &&
- td->io_issues[DDIR_WRITE] && should_fsync(td))
- return DDIR_DATASYNC;
-
- /*
- * see if it's time to sync_file_range
- */
- if (td->sync_file_range_nr &&
- !(td->io_issues[DDIR_WRITE] % td->sync_file_range_nr) &&
- td->io_issues[DDIR_WRITE] && should_fsync(td))
- return DDIR_SYNC_FILE_RANGE;
+ if (should_fsync(td)) {
+ if (td->o.fsync_blocks && td->io_issues[DDIR_WRITE] &&
+ !(td->io_issues[DDIR_WRITE] % td->o.fsync_blocks))
+ return DDIR_SYNC;
+
+ if (td->o.fdatasync_blocks && td->io_issues[DDIR_WRITE] &&
+ !(td->io_issues[DDIR_WRITE] % td->o.fdatasync_blocks))
+ return DDIR_DATASYNC;
+
+ if (td->sync_file_range_nr && td->io_issues[DDIR_WRITE] &&
+ !(td->io_issues[DDIR_WRITE] % td->sync_file_range_nr))
+ return DDIR_SYNC_FILE_RANGE;
+ }
if (td_rw(td)) {
/*
ddir = DDIR_READ;
else if (td_write(td))
ddir = DDIR_WRITE;
- else
+ else if (td_trim(td))
ddir = DDIR_TRIM;
+ else
+ ddir = DDIR_INVAL;
td->rwmix_ddir = rate_ddir(td, ddir);
return td->rwmix_ddir;
}
if (io_u->offset + io_u->buflen > io_u->file->real_file_size) {
- dprint(FD_IO, "io_u %p, offset too large\n", io_u);
- dprint(FD_IO, " off=%llu/%lu > %llu\n",
+ dprint(FD_IO, "io_u %p, offset + buflen exceeds file size\n",
+ io_u);
+ dprint(FD_IO, " offset=%llu/buflen=%lu > %llu\n",
(unsigned long long) io_u->offset, io_u->buflen,
(unsigned long long) io_u->file->real_file_size);
return 1;
get_trim = 1;
}
- if (get_trim && !get_next_trim(td, io_u))
+ if (get_trim && get_next_trim(td, io_u))
return true;
}
if (td->parent)
td = td->parent;
+ if (!td->o.stats)
+ return;
+
if (no_reduce)
lusec = utime_since(&io_u->issue_time, &icd->time);
icd->nr = nr;
icd->error = 0;
- for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++)
+ for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
icd->bytes_done[ddir] = 0;
}
return -1;
}
- for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++)
+ for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
td->bytes_done[ddir] += icd.bytes_done[ddir];
return 0;
int ret, ddir;
struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, };
- dprint(FD_IO, "io_u_queued_completed: min=%d\n", min_evts);
+ dprint(FD_IO, "io_u_queued_complete: min=%d\n", min_evts);
if (!min_evts)
tvp = &ts;
return -1;
}
- for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++)
+ for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
td->bytes_done[ddir] += icd.bytes_done[ddir];
return ret;
*/
void io_u_queued(struct thread_data *td, struct io_u *io_u)
{
- if (!td->o.disable_slat) {
+ if (!td->o.disable_slat && ramp_time_over(td) && td->o.stats) {
unsigned long slat_time;
slat_time = utime_since(&io_u->start_time, &io_u->issue_time);
io_u->buf_filled_len = 0;
fill_io_buffer(td, io_u->buf, min_write, max_bs);
}
+
+static int do_sync_file_range(const struct thread_data *td,
+ struct fio_file *f)
+{
+ off64_t offset, nbytes;
+
+ offset = f->first_write;
+ nbytes = f->last_write - f->first_write;
+
+ if (!nbytes)
+ return 0;
+
+ return sync_file_range(f->fd, offset, nbytes, td->o.sync_file_range);
+}
+
+int do_io_u_sync(const struct thread_data *td, struct io_u *io_u)
+{
+ int ret;
+
+ if (io_u->ddir == DDIR_SYNC) {
+ ret = fsync(io_u->file->fd);
+ } else if (io_u->ddir == DDIR_DATASYNC) {
+#ifdef CONFIG_FDATASYNC
+ ret = fdatasync(io_u->file->fd);
+#else
+ ret = io_u->xfer_buflen;
+ io_u->error = EINVAL;
+#endif
+ } else if (io_u->ddir == DDIR_SYNC_FILE_RANGE)
+ ret = do_sync_file_range(td, io_u->file);
+ else {
+ ret = io_u->xfer_buflen;
+ io_u->error = EINVAL;
+ }
+
+ if (ret < 0)
+ io_u->error = errno;
+
+ return ret;
+}
+
+int do_io_u_trim(const struct thread_data *td, struct io_u *io_u)
+{
+#ifndef FIO_HAVE_TRIM
+ io_u->error = EINVAL;
+ return 0;
+#else
+ struct fio_file *f = io_u->file;
+ int ret;
+
+ ret = os_trim(f->fd, io_u->offset, io_u->xfer_buflen);
+ if (!ret)
+ return io_u->xfer_buflen;
+
+ io_u->error = ret;
+ return 0;
+#endif
+}