Commit | Line | Data |
---|---|---|
2866c82d JA |
1 | /* |
2 | * regular read/write sync io engine | |
3 | * | |
4 | */ | |
5 | #include <stdio.h> | |
6 | #include <stdlib.h> | |
7 | #include <unistd.h> | |
8 | #include <errno.h> | |
9 | #include <assert.h> | |
10 | #include <sys/mman.h> | |
5f350952 JA |
11 | |
12 | #include "../fio.h" | |
13 | #include "../os.h" | |
2866c82d | 14 | |
2866c82d JA |
15 | static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u) |
16 | { | |
53cdc686 JA |
17 | struct fio_file *f = io_u->file; |
18 | unsigned long long real_off = io_u->offset - f->file_offset; | |
2866c82d JA |
19 | |
20 | if (io_u->ddir == DDIR_READ) | |
cec6b55d | 21 | memcpy(io_u->xfer_buf, f->mmap + real_off, io_u->xfer_buflen); |
87dc1ab1 | 22 | else if (io_u->ddir == DDIR_WRITE) |
cec6b55d | 23 | memcpy(f->mmap + real_off, io_u->xfer_buf, io_u->xfer_buflen); |
b907a5b5 JA |
24 | else if (io_u->ddir == DDIR_SYNC) { |
25 | if (msync(f->mmap, f->file_size, MS_SYNC)) | |
26 | io_u->error = errno; | |
27 | } | |
2866c82d JA |
28 | |
29 | /* | |
30 | * not really direct, but should drop the pages from the cache | |
31 | */ | |
b907a5b5 | 32 | if (td->odirect && io_u->ddir != DDIR_SYNC) { |
cec6b55d | 33 | if (msync(f->mmap + real_off, io_u->xfer_buflen, MS_SYNC) < 0) |
2866c82d | 34 | io_u->error = errno; |
cec6b55d | 35 | if (madvise(f->mmap + real_off, io_u->xfer_buflen, MADV_DONTNEED) < 0) |
2866c82d JA |
36 | io_u->error = errno; |
37 | } | |
38 | ||
36167d82 | 39 | if (io_u->error) |
95bcd815 | 40 | td_verror(td, io_u->error); |
2866c82d | 41 | |
36167d82 | 42 | return FIO_Q_COMPLETED; |
2866c82d JA |
43 | } |
44 | ||
5f350952 | 45 | static struct ioengine_ops ioengine = { |
2866c82d JA |
46 | .name = "mmap", |
47 | .version = FIO_IOOPS_VERSION, | |
2866c82d | 48 | .queue = fio_mmapio_queue, |
d9257bea | 49 | .flags = FIO_SYNCIO | FIO_MMAPIO, |
2866c82d | 50 | }; |
5f350952 JA |
51 | |
52 | static void fio_init fio_mmapio_register(void) | |
53 | { | |
54 | register_ioengine(&ioengine); | |
55 | } | |
56 | ||
57 | static void fio_exit fio_mmapio_unregister(void) | |
58 | { | |
59 | unregister_ioengine(&ioengine); | |
60 | } |