X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=51da223d3e02ab194c45a77e6249870d9d0a62d4;hp=787f382e2c73db251690fa296da787913b49e957;hb=799441286648bdced4f42d3040f37fd2e35eaf1d;hpb=4c07ad86c6cc6e158c70a5c625f60144db03f20d diff --git a/io_u.c b/io_u.c index 787f382e..51da223d 100644 --- a/io_u.c +++ b/io_u.c @@ -341,26 +341,35 @@ 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; unsigned int uninitialized_var(buflen); unsigned int minbs, maxbs; - long r, rand_max; + unsigned long r, rand_max; assert(ddir_rw(ddir)); 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; } @@ -423,7 +429,7 @@ static void set_rwmix_bytes(struct thread_data *td) static inline enum fio_ddir get_rand_ddir(struct thread_data *td) { unsigned int v; - long r; + unsigned long r; if (td->o.use_os_rand) { r = os_random_long(&td->rwmix_state); @@ -849,7 +855,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, do { int opened = 0; - long r; + unsigned long r; if (td->o.use_os_rand) { r = os_random_long(&td->next_file_state);