Skip to content

Commit 3114b67

Browse files
vincentkfuaxboe
authored andcommitted
fio: enable cross-thread overlap checking with processes
Overlap checking with io_submit_mode=offload requires relevant jobs to access each other's io_u's and io_u_all members. This patch modifies the fio_memalign and io_u_queue helpers to include an indicator signifying whether operations should use the shared memory pool. When fio is carrying out cross-job overlap checking in offload submission mode, these variables will be allocated from shared memory so that processes can be used and threads will no longer be required. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1368d95 commit 3114b67

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

backend.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1189,14 +1189,14 @@ static void cleanup_io_u(struct thread_data *td)
11891189
if (td->io_ops->io_u_free)
11901190
td->io_ops->io_u_free(td, io_u);
11911191

1192-
fio_memfree(io_u, sizeof(*io_u));
1192+
fio_memfree(io_u, sizeof(*io_u), td_offload_overlap(td));
11931193
}
11941194

11951195
free_io_mem(td);
11961196

11971197
io_u_rexit(&td->io_u_requeues);
1198-
io_u_qexit(&td->io_u_freelist);
1199-
io_u_qexit(&td->io_u_all);
1198+
io_u_qexit(&td->io_u_freelist, false);
1199+
io_u_qexit(&td->io_u_all, td_offload_overlap(td));
12001200

12011201
free_file_completion_logging(td);
12021202
}
@@ -1211,8 +1211,8 @@ static int init_io_u(struct thread_data *td)
12111211

12121212
err = 0;
12131213
err += !io_u_rinit(&td->io_u_requeues, td->o.iodepth);
1214-
err += !io_u_qinit(&td->io_u_freelist, td->o.iodepth);
1215-
err += !io_u_qinit(&td->io_u_all, td->o.iodepth);
1214+
err += !io_u_qinit(&td->io_u_freelist, td->o.iodepth, false);
1215+
err += !io_u_qinit(&td->io_u_all, td->o.iodepth, td_offload_overlap(td));
12161216

12171217
if (err) {
12181218
log_err("fio: failed setting up IO queues\n");
@@ -1227,7 +1227,7 @@ static int init_io_u(struct thread_data *td)
12271227
if (td->terminate)
12281228
return 1;
12291229

1230-
ptr = fio_memalign(cl_align, sizeof(*io_u));
1230+
ptr = fio_memalign(cl_align, sizeof(*io_u), td_offload_overlap(td));
12311231
if (!ptr) {
12321232
log_err("fio: unable to allocate aligned memory\n");
12331233
break;

io_u_queue.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#include <stdlib.h>
2+
#include <string.h>
23
#include "io_u_queue.h"
4+
#include "smalloc.h"
35

4-
bool io_u_qinit(struct io_u_queue *q, unsigned int nr)
6+
bool io_u_qinit(struct io_u_queue *q, unsigned int nr, bool shared)
57
{
6-
q->io_us = calloc(nr, sizeof(struct io_u *));
8+
if (shared)
9+
q->io_us = smalloc(nr * sizeof(struct io_u *));
10+
else
11+
q->io_us = calloc(nr, sizeof(struct io_u *));
12+
713
if (!q->io_us)
814
return false;
915

@@ -12,9 +18,12 @@ bool io_u_qinit(struct io_u_queue *q, unsigned int nr)
1218
return true;
1319
}
1420

15-
void io_u_qexit(struct io_u_queue *q)
21+
void io_u_qexit(struct io_u_queue *q, bool shared)
1622
{
17-
free(q->io_us);
23+
if (shared)
24+
sfree(q->io_us);
25+
else
26+
free(q->io_us);
1827
}
1928

2029
bool io_u_rinit(struct io_u_ring *ring, unsigned int nr)

io_u_queue.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static inline int io_u_qempty(const struct io_u_queue *q)
4545
#define io_u_qiter(q, io_u, i) \
4646
for (i = 0; i < (q)->nr && (io_u = (q)->io_us[i]); i++)
4747

48-
bool io_u_qinit(struct io_u_queue *q, unsigned int nr);
49-
void io_u_qexit(struct io_u_queue *q);
48+
bool io_u_qinit(struct io_u_queue *q, unsigned int nr, bool shared);
49+
void io_u_qexit(struct io_u_queue *q, bool shared);
5050

5151
struct io_u_ring {
5252
unsigned int head;

lib/memalign.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <stdlib.h>
33

44
#include "memalign.h"
5+
#include "smalloc.h"
56

67
#define PTR_ALIGN(ptr, mask) \
78
(char *)((uintptr_t)((ptr) + (mask)) & ~(mask))
@@ -10,14 +11,18 @@ struct align_footer {
1011
unsigned int offset;
1112
};
1213

13-
void *fio_memalign(size_t alignment, size_t size)
14+
void *fio_memalign(size_t alignment, size_t size, bool shared)
1415
{
1516
struct align_footer *f;
1617
void *ptr, *ret = NULL;
1718

1819
assert(!(alignment & (alignment - 1)));
1920

20-
ptr = malloc(size + alignment + sizeof(*f) - 1);
21+
if (shared)
22+
ptr = smalloc(size + alignment + sizeof(*f) - 1);
23+
else
24+
ptr = malloc(size + alignment + sizeof(*f) - 1);
25+
2126
if (ptr) {
2227
ret = PTR_ALIGN(ptr, alignment - 1);
2328
f = ret + size;
@@ -27,9 +32,12 @@ void *fio_memalign(size_t alignment, size_t size)
2732
return ret;
2833
}
2934

30-
void fio_memfree(void *ptr, size_t size)
35+
void fio_memfree(void *ptr, size_t size, bool shared)
3136
{
3237
struct align_footer *f = ptr + size;
3338

34-
free(ptr - f->offset);
39+
if (shared)
40+
sfree(ptr - f->offset);
41+
else
42+
free(ptr - f->offset);
3543
}

lib/memalign.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#define FIO_MEMALIGN_H
33

44
#include <inttypes.h>
5+
#include <stdbool.h>
56

6-
extern void *fio_memalign(size_t alignment, size_t size);
7-
extern void fio_memfree(void *ptr, size_t size);
7+
extern void *fio_memalign(size_t alignment, size_t size, bool shared);
8+
extern void fio_memfree(void *ptr, size_t size, bool shared);
89

910
#endif

t/dedupe.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ static int col_check(struct chunk *c, struct item *i)
158158
char *cbuf, *ibuf;
159159
int ret = 1;
160160

161-
cbuf = fio_memalign(blocksize, blocksize);
162-
ibuf = fio_memalign(blocksize, blocksize);
161+
cbuf = fio_memalign(blocksize, blocksize, false);
162+
ibuf = fio_memalign(blocksize, blocksize, false);
163163

164164
e = flist_entry(c->extent_list[0].next, struct extent, list);
165165
if (read_block(file.fd, cbuf, e->offset))
@@ -170,8 +170,8 @@ static int col_check(struct chunk *c, struct item *i)
170170

171171
ret = memcmp(ibuf, cbuf, blocksize);
172172
out:
173-
fio_memfree(cbuf, blocksize);
174-
fio_memfree(ibuf, blocksize);
173+
fio_memfree(cbuf, blocksize, false);
174+
fio_memfree(ibuf, blocksize, false);
175175
return ret;
176176
}
177177

@@ -309,7 +309,7 @@ static void *thread_fn(void *data)
309309
struct worker_thread *thread = data;
310310
void *buf;
311311

312-
buf = fio_memalign(blocksize, chunk_size);
312+
buf = fio_memalign(blocksize, chunk_size, false);
313313

314314
do {
315315
if (get_work(&thread->cur_offset, &thread->size)) {
@@ -323,7 +323,7 @@ static void *thread_fn(void *data)
323323
} while (1);
324324

325325
thread->done = 1;
326-
fio_memfree(buf, chunk_size);
326+
fio_memfree(buf, chunk_size, false);
327327
return NULL;
328328
}
329329

0 commit comments

Comments
 (0)