X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=51da223d3e02ab194c45a77e6249870d9d0a62d4;hp=d35b8441b313b6efb28c9f65647aa0cb08b6cb3d;hb=799441286648bdced4f42d3040f37fd2e35eaf1d;hpb=76a3179ec3b849e4d4b0324ab3f517beec816bdf diff --git a/io_u.c b/io_u.c index d35b8441..51da223d 100644 --- a/io_u.c +++ b/io_u.c @@ -341,6 +341,14 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u) return __get_next_offset(td, io_u); } +static inline int io_u_fits(struct thread_data *td, struct io_u *io_u, + unsigned int buflen) +{ + struct fio_file *f = io_u->file; + + return io_u->offset + buflen <= f->io_size + td->o.start_offset; +} + static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u) { const int ddir = io_u->ddir; @@ -353,14 +361,15 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u) minbs = td->o.min_bs[ddir]; maxbs = td->o.max_bs[ddir]; + if (minbs == maxbs) + return minbs; + if (td->o.use_os_rand) rand_max = OS_RAND_MAX; else rand_max = FRAND_MAX; - if (minbs == maxbs) - buflen = minbs; - else { + do { if (td->o.use_os_rand) r = os_random_long(&td->bsrange_state); else @@ -380,19 +389,16 @@ static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u) buflen = bsp->bs; perc += bsp->perc; - if (r <= ((rand_max / 100L) * perc)) + if ((r <= ((rand_max / 100L) * perc)) && + io_u_fits(td, io_u, buflen)) break; } } + if (!td->o.bs_unaligned && is_power_of_2(minbs)) buflen = (buflen + minbs - 1) & ~(minbs - 1); - } - if (io_u->offset + buflen > io_u->file->real_file_size) { - dprint(FD_IO, "lower buflen %u -> %u (ddir=%d)\n", buflen, - minbs, ddir); - buflen = minbs; - } + } while (!io_u_fits(td, io_u, buflen)); return buflen; }