Skip to content

Commit de3d5e6

Browse files
committed
Merge branch 'mmap-fixes' of https://github.com/geertj/fio
* 'mmap-fixes' of https://github.com/geertj/fio: engines/mmap: fix full/limited prep logic engines/mmap: fix logic when "offset" > 0 engines/mmap: support fadvise_hint
2 parents 7c8dbca + 1a3e01f commit de3d5e6

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

engines/mmap.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "../verify.h"
1616

1717
/*
18-
* Limits us to 1GiB of mapped files in total
18+
* Limits us to 1GiB of mapped files in total on 32-bit architectures
1919
*/
2020
#define MMAP_TOTAL_SZ (1 * 1024 * 1024 * 1024UL)
2121

@@ -53,6 +53,7 @@ static bool fio_madvise_file(struct thread_data *td, struct fio_file *f,
5353
size_t length)
5454

5555
{
56+
int flags;
5657
struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
5758
#ifdef CONFIG_HAVE_THP
5859
struct mmap_options *o = td->eo;
@@ -65,16 +66,20 @@ static bool fio_madvise_file(struct thread_data *td, struct fio_file *f,
6566
if (!td->o.fadvise_hint)
6667
return true;
6768

68-
if (!td_random(td)) {
69-
if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_SEQUENTIAL) < 0) {
70-
td_verror(td, errno, "madvise");
71-
return false;
72-
}
73-
} else {
74-
if (posix_madvise(fmd->mmap_ptr, length, POSIX_MADV_RANDOM) < 0) {
75-
td_verror(td, errno, "madvise");
76-
return false;
77-
}
69+
if (td->o.fadvise_hint == F_ADV_TYPE)
70+
flags = td_random(td) ? POSIX_MADV_RANDOM : POSIX_MADV_SEQUENTIAL;
71+
else if (td->o.fadvise_hint == F_ADV_RANDOM)
72+
flags = POSIX_MADV_RANDOM;
73+
else if (td->o.fadvise_hint == F_ADV_SEQUENTIAL)
74+
flags = POSIX_MADV_SEQUENTIAL;
75+
else {
76+
log_err("fio: unknown madvise type %d\n", td->o.fadvise_hint);
77+
return false;
78+
}
79+
80+
if (posix_madvise(fmd->mmap_ptr, length, flags) < 0) {
81+
td_verror(td, errno, "madvise");
82+
return false;
7883
}
7984

8085
return true;
@@ -152,11 +157,8 @@ static int fio_mmapio_prep_limited(struct thread_data *td, struct io_u *io_u)
152157
return EIO;
153158
}
154159

155-
fmd->mmap_sz = mmap_map_size;
156-
if (fmd->mmap_sz > f->io_size)
157-
fmd->mmap_sz = f->io_size;
158-
159160
fmd->mmap_off = io_u->offset;
161+
fmd->mmap_sz = io_u->buflen;
160162

161163
return fio_mmap_file(td, f, fmd->mmap_sz, fmd->mmap_off);
162164
}
@@ -172,14 +174,14 @@ static int fio_mmapio_prep_full(struct thread_data *td, struct io_u *io_u)
172174

173175
if (fio_file_partial_mmap(f))
174176
return EINVAL;
175-
if (io_u->offset != (size_t) io_u->offset ||
176-
f->io_size != (size_t) f->io_size) {
177+
178+
if (sizeof(size_t) < 8 && f->io_size > mmap_map_size) {
177179
fio_file_set_partial_mmap(f);
178180
return EINVAL;
179181
}
180182

181183
fmd->mmap_sz = f->io_size;
182-
fmd->mmap_off = 0;
184+
fmd->mmap_off = f->file_offset;
183185

184186
ret = fio_mmap_file(td, f, fmd->mmap_sz, fmd->mmap_off);
185187
if (ret)
@@ -218,8 +220,7 @@ static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u)
218220
}
219221

220222
done:
221-
io_u->mmap_data = fmd->mmap_ptr + io_u->offset - fmd->mmap_off -
222-
f->file_offset;
223+
io_u->mmap_data = fmd->mmap_ptr + io_u->offset - fmd->mmap_off;
223224
return 0;
224225
}
225226

0 commit comments

Comments
 (0)