examples/link-cp: improve memory use
Put the data at the end so we don't have to offset the actual buffer. Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
@@ -66,11 +66,13 @@ static void queue_rw_pair(struct io_uring *ring, off_t size, off_t offset)
|
|||||||
{
|
{
|
||||||
struct io_uring_sqe *sqe;
|
struct io_uring_sqe *sqe;
|
||||||
struct io_data *data;
|
struct io_data *data;
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
data = malloc(size + sizeof(*data));
|
ptr = malloc(size + sizeof(*data));
|
||||||
|
data = ptr + size;
|
||||||
data->index = 0;
|
data->index = 0;
|
||||||
data->offset = offset;
|
data->offset = offset;
|
||||||
data->iov.iov_base = data + 1;
|
data->iov.iov_base = ptr;
|
||||||
data->iov.iov_len = size;
|
data->iov.iov_len = size;
|
||||||
|
|
||||||
sqe = io_uring_get_sqe(ring);
|
sqe = io_uring_get_sqe(ring);
|
||||||
@@ -100,8 +102,11 @@ static int handle_cqe(struct io_uring *ring, struct io_uring_cqe *cqe)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->index == 2)
|
if (data->index == 2) {
|
||||||
free(data);
|
void *ptr = (void *) data - data->iov.iov_len;
|
||||||
|
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
io_uring_cqe_seen(ring, cqe);
|
io_uring_cqe_seen(ring, cqe);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user