Skip to content

Commit 8a3e8ee

Browse files
committed
io_uring: add flag for disabling provided buffer recycling
If we need to continue doing this IO, then we don't want a potentially selected buffer recycled. Add a flag for that. Set this for recv/recvmsg if they do partial IO. Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7ba89d2 commit 8a3e8ee

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

fs/io_uring.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ enum {
783783
REQ_F_SKIP_LINK_CQES_BIT,
784784
REQ_F_SINGLE_POLL_BIT,
785785
REQ_F_DOUBLE_POLL_BIT,
786+
REQ_F_PARTIAL_IO_BIT,
786787
/* keep async read/write and isreg together and in order */
787788
REQ_F_SUPPORT_NOWAIT_BIT,
788789
REQ_F_ISREG_BIT,
@@ -845,6 +846,8 @@ enum {
845846
REQ_F_SINGLE_POLL = BIT(REQ_F_SINGLE_POLL_BIT),
846847
/* double poll may active */
847848
REQ_F_DOUBLE_POLL = BIT(REQ_F_DOUBLE_POLL_BIT),
849+
/* request has already done partial IO */
850+
REQ_F_PARTIAL_IO = BIT(REQ_F_PARTIAL_IO_BIT),
848851
};
849852

850853
struct async_poll {
@@ -1392,6 +1395,9 @@ static void io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
13921395

13931396
if (likely(!(req->flags & REQ_F_BUFFER_SELECTED)))
13941397
return;
1398+
/* don't recycle if we already did IO to this buffer */
1399+
if (req->flags & REQ_F_PARTIAL_IO)
1400+
return;
13951401

13961402
if (issue_flags & IO_URING_F_UNLOCKED)
13971403
mutex_lock(&ctx->uring_lock);
@@ -5477,6 +5483,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
54775483
ret = -EINTR;
54785484
if (ret > 0 && io_net_retry(sock, flags)) {
54795485
sr->done_io += ret;
5486+
req->flags |= REQ_F_PARTIAL_IO;
54805487
return io_setup_async_msg(req, kmsg);
54815488
}
54825489
req_set_fail(req);
@@ -5546,6 +5553,7 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
55465553
sr->len -= ret;
55475554
sr->buf += ret;
55485555
sr->done_io += ret;
5556+
req->flags |= REQ_F_PARTIAL_IO;
55495557
return -EAGAIN;
55505558
}
55515559
req_set_fail(req);

0 commit comments

Comments
 (0)