unsigned long long ret, sized;
unsigned long r;
- if (td->o.use_os_rand) {
- r = os_random_long(&td->file_size_state);
- sized = td->o.file_size_high - td->o.file_size_low;
- ret = (unsigned long long) ((double) sized * (r / (OS_RAND_MAX + 1.0)));
- } else {
- r = __rand(&td->__file_size_state);
- sized = td->o.file_size_high - td->o.file_size_low;
- ret = (unsigned long long) ((double) sized * (r / (FRAND_MAX + 1.0)));
- }
-
+ r = __rand(&td->file_size_state);
+ sized = td->o.file_size_high - td->o.file_size_low;
+ ret = (unsigned long long) ((double) sized * (r / (FRAND_MAX + 1.0)));
ret += td->o.file_size_low;
ret -= (ret % td->o.rw_min_bs);
return ret;
if (td->io_ops->invalidate)
ret = td->io_ops->invalidate(td, f);
- else if (f->mmap_ptr) {
- ret = posix_madvise(f->mmap_ptr, f->mmap_sz, POSIX_MADV_DONTNEED);
-#ifdef FIO_MADV_FREE
- if (f->filetype == FIO_TYPE_BD)
- (void) posix_madvise(f->mmap_ptr, f->mmap_sz, FIO_MADV_FREE);
-#endif
- } else if (f->filetype == FIO_TYPE_FILE) {
+ else if (f->filetype == FIO_TYPE_FILE)
ret = posix_fadvise(f->fd, off, len, POSIX_FADV_DONTNEED);
- } else if (f->filetype == FIO_TYPE_BD) {
+ else if (f->filetype == FIO_TYPE_BD) {
ret = blockdev_invalidate_cache(f);
if (ret < 0 && errno == EACCES && geteuid()) {
if (!root_warn) {
dprint(FD_FILE, "fd open %s\n", f->file_name);
- if (td_trim(td) && f->filetype != FIO_TYPE_BD) {
- log_err("fio: trim only applies to block device\n");
- return 1;
- }
-
if (!strcmp(f->file_name, "-")) {
if (td_rw(td)) {
log_err("fio: can't read/write to stdin/out\n");
}
}
- if (!o->size || o->size > total_size)
+ if (td->o.block_error_hist) {
+ int len;
+
+ assert(td->o.nr_files == 1); /* checked in fixup_options */
+ f = td->files[0];
+ len = f->io_size / td->o.bs[DDIR_TRIM];
+ if (len > MAX_NR_BLOCK_INFOS || len <= 0) {
+ log_err("fio: cannot calculate block histogram with "
+ "%d trim blocks, maximum %d\n",
+ len, MAX_NR_BLOCK_INFOS);
+ td_verror(td, EINVAL, "block_error_hist");
+ goto err_out;
+ }
+
+ td->ts.nr_block_infos = len;
+ for (int i = 0; i < len; i++)
+ td->ts.block_infos[i] =
+ BLOCK_INFO(0, BLOCK_STATE_UNINIT);
+ } else
+ td->ts.nr_block_infos = 0;
+
+ if (!o->size || (total_size && o->size > total_size))
o->size = total_size;
if (o->size < td_min_bs(td)) {
{
unsigned int range_size, seed;
unsigned long nranges;
- uint64_t file_size;
+ uint64_t fsize;
range_size = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]);
- file_size = min(f->real_file_size, f->io_size);
+ fsize = min(f->real_file_size, f->io_size);
- nranges = (file_size + range_size - 1) / range_size;
+ nranges = (fsize + range_size - 1) / range_size;
seed = jhash(f->file_name, strlen(f->file_name), 0) * td->thread_number;
if (!td->o.rand_repeatable)
if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
zipf_init(&f->zipf, nranges, td->o.zipf_theta.u.f, seed);
- else
+ else if (td->o.random_distribution == FIO_RAND_DIST_PARETO)
pareto_init(&f->zipf, nranges, td->o.pareto_h.u.f, seed);
+ else if (td->o.random_distribution == FIO_RAND_DIST_GAUSS)
+ gauss_init(&f->gauss, nranges, td->o.gauss_dev.u.f, seed);
return 1;
}
return 0;
for_each_file(td, f, i) {
- uint64_t file_size = min(f->real_file_size, f->io_size);
+ uint64_t fsize = min(f->real_file_size, f->io_size);
- blocks = file_size / (unsigned long long) td->o.rw_min_bs;
+ blocks = fsize / (unsigned long long) td->o.rw_min_bs;
if (td->o.random_generator == FIO_RAND_GEN_LFSR) {
unsigned long seed;
seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
- if (!lfsr_init(&f->lfsr, blocks, seed, 0))
+ if (!lfsr_init(&f->lfsr, blocks, seed, 0)) {
+ fio_file_set_lfsr(f);
continue;
+ }
} else if (!td->o.norandommap) {
f->io_axmap = axmap_new(blocks);
- if (f->io_axmap)
+ if (f->io_axmap) {
+ fio_file_set_axmap(f);
continue;
+ }
} else if (td->o.norandommap)
continue;
sfree(f->file_name);
f->file_name = NULL;
- axmap_free(f->io_axmap);
- f->io_axmap = NULL;
+ if (fio_file_axmap(f)) {
+ axmap_free(f->io_axmap);
+ f->io_axmap = NULL;
+ }
sfree(f);
}
void fio_file_reset(struct thread_data *td, struct fio_file *f)
{
- f->last_pos = f->file_offset;
- f->last_start = -1ULL;
- if (f->io_axmap)
+ int i;
+
+ for (i = 0; i < DDIR_RWDIR_CNT; i++) {
+ f->last_pos[i] = f->file_offset;
+ f->last_start[i] = -1ULL;
+ }
+
+ if (fio_file_axmap(f))
axmap_reset(f->io_axmap);
- if (td->o.random_generator == FIO_RAND_GEN_LFSR)
+ else if (fio_file_lfsr(f))
lfsr_reset(&f->lfsr, td->rand_seeds[FIO_RAND_BLOCK_OFF]);
}