Skip to content

Commit 89d528b

Browse files
DylanZAaxboe
authored andcommitted
io_uring: indicate if io_kbuf_recycle did recycle anything
It can be useful to know if io_kbuf_recycle did actually recycle the buffer on the request, or if it left the request alone. Signed-off-by: Dylan Yudaken <dyudaken@gmail.com> Link: https://lore.kernel.org/r/20231106203909.197089-2-dyudaken@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f688944 commit 89d528b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

io_uring/kbuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx,
5252
return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL));
5353
}
5454

55-
void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
55+
bool io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
5656
{
5757
struct io_ring_ctx *ctx = req->ctx;
5858
struct io_buffer_list *bl;
@@ -65,7 +65,7 @@ void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
6565
* multiple use.
6666
*/
6767
if (req->flags & REQ_F_PARTIAL_IO)
68-
return;
68+
return false;
6969

7070
io_ring_submit_lock(ctx, issue_flags);
7171

@@ -76,7 +76,7 @@ void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags)
7676
req->buf_index = buf->bgid;
7777

7878
io_ring_submit_unlock(ctx, issue_flags);
79-
return;
79+
return true;
8080
}
8181

8282
unsigned int __io_put_kbuf(struct io_kiocb *req, unsigned issue_flags)

io_uring/kbuf.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg);
5353

5454
unsigned int __io_put_kbuf(struct io_kiocb *req, unsigned issue_flags);
5555

56-
void io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags);
56+
bool io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags);
5757

5858
void *io_pbuf_get_address(struct io_ring_ctx *ctx, unsigned long bgid);
5959

60-
static inline void io_kbuf_recycle_ring(struct io_kiocb *req)
60+
static inline bool io_kbuf_recycle_ring(struct io_kiocb *req)
6161
{
6262
/*
6363
* We don't need to recycle for REQ_F_BUFFER_RING, we can just clear
@@ -80,8 +80,10 @@ static inline void io_kbuf_recycle_ring(struct io_kiocb *req)
8080
} else {
8181
req->buf_index = req->buf_list->bgid;
8282
req->flags &= ~REQ_F_BUFFER_RING;
83+
return true;
8384
}
8485
}
86+
return false;
8587
}
8688

8789
static inline bool io_do_buffer_select(struct io_kiocb *req)
@@ -91,12 +93,13 @@ static inline bool io_do_buffer_select(struct io_kiocb *req)
9193
return !(req->flags & (REQ_F_BUFFER_SELECTED|REQ_F_BUFFER_RING));
9294
}
9395

94-
static inline void io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
96+
static inline bool io_kbuf_recycle(struct io_kiocb *req, unsigned issue_flags)
9597
{
9698
if (req->flags & REQ_F_BUFFER_SELECTED)
97-
io_kbuf_recycle_legacy(req, issue_flags);
99+
return io_kbuf_recycle_legacy(req, issue_flags);
98100
if (req->flags & REQ_F_BUFFER_RING)
99-
io_kbuf_recycle_ring(req);
101+
return io_kbuf_recycle_ring(req);
102+
return false;
100103
}
101104

102105
static inline unsigned int __io_put_kbuf_list(struct io_kiocb *req,

0 commit comments

Comments
 (0)