X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=7ac31a0d297872fe82168e74cff63cfce1880dcb;hp=bd7df0cf7f1eb2b8cd37aeada79427a3cae65af2;hb=6ae1f57f2cb8661b97b770372eeb3694f6d5a744;hpb=b271fe62101e84cd6ca2a78c92299beba251db24 diff --git a/io_u.c b/io_u.c index bd7df0cf..7ac31a0d 100644 --- a/io_u.c +++ b/io_u.c @@ -25,11 +25,13 @@ struct io_completion_data { * to yet. Used to make sure we cover the entire range in a fair fashion. */ static int random_map_free(struct thread_data *td, struct fio_file *f, - unsigned long long block) + const unsigned long long block) { unsigned int idx = RAND_MAP_IDX(td, f, block); unsigned int bit = RAND_MAP_BIT(td, f, block); + dprint(FD_RANDOM, "free: b=%llu, idx=%u, bit=%u\n", block, idx, bit); + return (f->file_map[idx] & (1UL << bit)) == 0; } @@ -44,7 +46,7 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u) unsigned int blocks; unsigned int nr_blocks; - block = io_u->offset / (unsigned long long) min_bs; + block = (io_u->offset - f->file_offset) / (unsigned long long) min_bs; blocks = 0; nr_blocks = (io_u->buflen + min_bs - 1) / min_bs; @@ -55,7 +57,7 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u) * If we have a mixed random workload, we may * encounter blocks we already did IO to. */ - if (!td->o.ddir_nr == 1 && !random_map_free(td, f, block)) + if ((td->o.ddir_nr == 1) && !random_map_free(td, f, block)) break; idx = RAND_MAP_IDX(td, f, block); @@ -73,11 +75,12 @@ static void mark_random_map(struct thread_data *td, struct io_u *io_u) } static inline unsigned long long last_block(struct thread_data *td, - struct fio_file *f) + struct fio_file *f, + enum fio_ddir ddir) { unsigned long long max_blocks; - max_blocks = f->io_size / td->o.rw_min_bs; + max_blocks = f->io_size / (unsigned long long) td->o.min_bs[ddir]; if (!max_blocks) return 0; @@ -88,16 +91,17 @@ static inline unsigned long long last_block(struct thread_data *td, * Return the next free block in the map. */ static int get_next_free_block(struct thread_data *td, struct fio_file *f, - unsigned long long *b) + enum fio_ddir ddir, unsigned long long *b) { + unsigned long long min_bs = td->o.rw_min_bs; int i; i = f->last_free_lookup; *b = (i * BLOCKS_PER_MAP); - while ((*b) * td->o.rw_min_bs < f->real_file_size) { + while ((*b) * min_bs < f->real_file_size) { if (f->file_map[i] != -1UL) { *b += fio_ffz(f->file_map[i]); - if (*b > last_block(td, f)) + if (*b > last_block(td, f, ddir)) break; f->last_free_lookup = i; return 0; @@ -112,14 +116,15 @@ static int get_next_free_block(struct thread_data *td, struct fio_file *f, } static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, - unsigned long long *b) + enum fio_ddir ddir, unsigned long long *b) { - unsigned long long r, rb; + unsigned long long r; int loops = 5; do { r = os_random_long(&td->random_state); - *b = last_block(td, f); + dprint(FD_RANDOM, "off rand %llu\n", r); + *b = (last_block(td, f, ddir) - 1) * (r / ((unsigned long long) RAND_MAX + 1.0)); /* * if we are not maintaining a random map, we are done. @@ -128,12 +133,13 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, return 0; /* - * calculate map offset and chec if it's free + * calculate map offset and check if it's free */ - rb = *b; - if (random_map_free(td, f, rb)) + if (random_map_free(td, f, *b)) return 0; + dprint(FD_RANDOM, "get_next_rand_offset: offset %llu busy\n", + *b); } while (--loops); /* @@ -144,7 +150,7 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, loops = 10; do { f->last_free_lookup = (f->num_maps - 1) * (r / (RAND_MAX+1.0)); - if (!get_next_free_block(td, f, b)) + if (!get_next_free_block(td, f, ddir, b)) return 0; r = os_random_long(&td->random_state); @@ -154,7 +160,7 @@ static int get_next_rand_offset(struct thread_data *td, struct fio_file *f, * that didn't work either, try exhaustive search from the start */ f->last_free_lookup = 0; - return get_next_free_block(td, f, b); + return get_next_free_block(td, f, ddir, b); } /* @@ -166,21 +172,23 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u) { struct fio_file *f = io_u->file; unsigned long long b; + enum fio_ddir ddir = io_u->ddir; if (td_random(td) && (td->o.ddir_nr && !--td->ddir_nr)) { td->ddir_nr = td->o.ddir_nr; - if (get_next_rand_offset(td, f, &b)) + if (get_next_rand_offset(td, f, ddir, &b)) return 1; } else { if (f->last_pos >= f->real_file_size) { - if (!td_random(td) || get_next_rand_offset(td, f, &b)) + if (!td_random(td) || + get_next_rand_offset(td, f, ddir, &b)) return 1; } else - b = (f->last_pos - f->file_offset) / td->o.rw_min_bs; + b = (f->last_pos - f->file_offset) / td->o.min_bs[ddir]; } - io_u->offset = (b * td->o.rw_min_bs) + f->file_offset; + io_u->offset = (b * td->o.min_bs[ddir]) + f->file_offset; if (io_u->offset >= f->real_file_size) { dprint(FD_IO, "get_next_offset: offset %llu >= size %llu\n", io_u->offset, f->real_file_size); @@ -219,8 +227,11 @@ static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u) buflen = (buflen + td->o.min_bs[ddir] - 1) & ~(td->o.min_bs[ddir] - 1); } - if (io_u->offset + buflen > io_u->file->real_file_size) + if (io_u->offset + buflen > io_u->file->real_file_size) { + dprint(FD_IO, "lower buflen %u -> %u (ddir=%d)\n", buflen, + td->o.min_bs[ddir], ddir); buflen = td->o.min_bs[ddir]; + } return buflen; } @@ -331,6 +342,9 @@ void requeue_io_u(struct thread_data *td, struct io_u **io_u) struct io_u *__io_u = *io_u; __io_u->flags |= IO_U_F_FREE; + if ((__io_u->flags & IO_U_F_FLIGHT) && (__io_u->ddir != DDIR_SYNC)) + td->io_issues[__io_u->ddir]--; + __io_u->flags &= ~IO_U_F_FLIGHT; list_del(&__io_u->list); @@ -382,6 +396,8 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u) 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", io_u->offset, + io_u->buflen, io_u->file->real_file_size); return 1; }