Skip to content

Commit 1a3e01f

Browse files
committed
engines/mmap: fix full/limited prep logic
The engine supports a "full" mode where the entire range for a job is mapped, and a "limited" mode that tries to map less memory. This fixes a bug and implements the following simplified logic: - If we are on a 64-bit architecture, or if io_size <= mmap_map_size, then we map the entire io_size region, and re-use for all IO. - Otherwise, we map the range for each individual IOs. Previously, we would fallback to limited mode in case of 32-bit overflow of the job size. That isn't strict enough as we want to stay below mmap_map_size for a single mapping. This fixes that. Also, in limited mode, this code previously tried to map min(io_size, mmap_map_size) bytes, starting at the offset. This could allow a future IO use the same mapping if happens at a higher offset. I think it's better to keep it simple and get the consistent performance of always having one mmap per IO in limited mode. Signed-off-by: Geert Jansen <[email protected]>
1 parent 4857911 commit 1a3e01f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

engines/mmap.c

Lines changed: 4 additions & 7 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

@@ -157,11 +157,8 @@ static int fio_mmapio_prep_limited(struct thread_data *td, struct io_u *io_u)
157157
return EIO;
158158
}
159159

160-
fmd->mmap_sz = mmap_map_size;
161-
if (fmd->mmap_sz > f->io_size)
162-
fmd->mmap_sz = f->io_size;
163-
164160
fmd->mmap_off = io_u->offset;
161+
fmd->mmap_sz = io_u->buflen;
165162

166163
return fio_mmap_file(td, f, fmd->mmap_sz, fmd->mmap_off);
167164
}
@@ -177,8 +174,8 @@ static int fio_mmapio_prep_full(struct thread_data *td, struct io_u *io_u)
177174

178175
if (fio_file_partial_mmap(f))
179176
return EINVAL;
180-
if (io_u->offset != (size_t) io_u->offset ||
181-
f->io_size != (size_t) f->io_size) {
177+
178+
if (sizeof(size_t) < 8 && f->io_size > mmap_map_size) {
182179
fio_file_set_partial_mmap(f);
183180
return EINVAL;
184181
}

0 commit comments

Comments
 (0)