* [PATCH v2 0/9] Clean up alloc_cache allocations
@ 2024-11-22 21:15 Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 1/9] io_uring: Fold allocation into alloc_cache helper Gabriel Krisman Bertazi
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
Hi,
This v2 of the alloc_cache allocations has small changes, renaming the
allocation helper and introducing a callback instead of zeroing the
entire object, as suggested by Jens.
This was tested against liburing testsuite, with lockdep and KASAN
enabled.
For v1, please see:
https://lore.kernel.org/io-uring/[email protected]/T/#t
Gabriel Krisman Bertazi (9):
io_uring: Fold allocation into alloc_cache helper
io_uring: Add generic helper to allocate async data
io_uring/futex: Allocate ifd with generic alloc_cache helper
io_uring/poll: Allocate apoll with generic alloc_cache helper
io_uring/uring_cmd: Allocate async data through generic helper
io_uring/net: Allocate msghdr async data through helper
io_uring/rw: Allocate async data through helper
io_uring: Move old async data allocation helper to header
io_uring/msg_ring: Drop custom destructor
io_uring/alloc_cache.h | 13 +++++++++++++
io_uring/futex.c | 13 +------------
io_uring/io_uring.c | 17 ++---------------
io_uring/io_uring.h | 23 +++++++++++++++++++++++
io_uring/msg_ring.c | 7 -------
io_uring/msg_ring.h | 1 -
io_uring/net.c | 35 ++++++++++++++++++-----------------
io_uring/poll.c | 13 +++++--------
io_uring/rw.c | 36 ++++++++++++++++--------------------
io_uring/timeout.c | 5 ++---
io_uring/uring_cmd.c | 20 ++------------------
io_uring/waitid.c | 4 ++--
12 files changed, 84 insertions(+), 103 deletions(-)
--
2.47.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/9] io_uring: Fold allocation into alloc_cache helper
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 2/9] io_uring: Add generic helper to allocate async data Gabriel Krisman Bertazi
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
The allocation paths that use alloc_cache duplicate the same code
pattern, sometimes in a quite convoluted way. Fold the allocation into
the cache code itself, making it just an allocator function, and keeping
the cache policy invisible to callers. Another justification for doing
this, beyond code simplicity, is that it makes it trivial to test the
impact of disabling the cache and using slab directly, which I've used
for slab improvement experiments.
One relevant detail is that we provide a callback to optionally
initialize memory only when we actually reach slab. This allows us to
avoid blindly executing the allocation with GFP_ZERO and only clean
fields when they matter.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
since v1:
- add a callback to initialize objects coming from slab
- rename io_alloc_cache_alloc -> io_cache_alloc
---
io_uring/alloc_cache.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/io_uring/alloc_cache.h b/io_uring/alloc_cache.h
index b7a38a2069cf..a3a8cfec32ce 100644
--- a/io_uring/alloc_cache.h
+++ b/io_uring/alloc_cache.h
@@ -30,6 +30,19 @@ static inline void *io_alloc_cache_get(struct io_alloc_cache *cache)
return NULL;
}
+static inline void *io_cache_alloc(struct io_alloc_cache *cache, gfp_t gfp,
+ void (*init_once)(void *obj))
+{
+ if (unlikely(!cache->nr_cached)) {
+ void *obj = kmalloc(cache->elem_size, gfp);
+
+ if (obj && init_once)
+ init_once(obj);
+ return obj;
+ }
+ return io_alloc_cache_get(cache);
+}
+
/* returns false if the cache was initialized properly */
static inline bool io_alloc_cache_init(struct io_alloc_cache *cache,
unsigned max_nr, size_t size)
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/9] io_uring: Add generic helper to allocate async data
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 1/9] io_uring: Fold allocation into alloc_cache helper Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 3/9] io_uring/futex: Allocate ifd with generic alloc_cache helper Gabriel Krisman Bertazi
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
This helper replaces io_alloc_async_data by using the folded allocation.
Do it in a header to allow the compiler to decide whether to inline.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/io_uring.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 4070d4c8ef97..ddf3f05c3622 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -222,6 +222,16 @@ static inline void io_req_set_res(struct io_kiocb *req, s32 res, u32 cflags)
req->cqe.flags = cflags;
}
+static inline void *io_uring_alloc_async_data(struct io_alloc_cache *cache,
+ struct io_kiocb *req,
+ void (*init_once)(void *obj))
+{
+ req->async_data = io_cache_alloc(cache, GFP_KERNEL, init_once);
+ if (req->async_data)
+ req->flags |= REQ_F_ASYNC_DATA;
+ return req->async_data;
+}
+
static inline bool req_has_async_data(struct io_kiocb *req)
{
return req->flags & REQ_F_ASYNC_DATA;
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/9] io_uring/futex: Allocate ifd with generic alloc_cache helper
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 1/9] io_uring: Fold allocation into alloc_cache helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 2/9] io_uring: Add generic helper to allocate async data Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 4/9] io_uring/poll: Allocate apoll " Gabriel Krisman Bertazi
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
Instead of open-coding the allocation, use the generic alloc_cache
helper.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/futex.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/io_uring/futex.c b/io_uring/futex.c
index e29662f039e1..30139cc150f2 100644
--- a/io_uring/futex.c
+++ b/io_uring/futex.c
@@ -251,17 +251,6 @@ static void io_futex_wake_fn(struct wake_q_head *wake_q, struct futex_q *q)
io_req_task_work_add(req);
}
-static struct io_futex_data *io_alloc_ifd(struct io_ring_ctx *ctx)
-{
- struct io_futex_data *ifd;
-
- ifd = io_alloc_cache_get(&ctx->futex_cache);
- if (ifd)
- return ifd;
-
- return kmalloc(sizeof(struct io_futex_data), GFP_NOWAIT);
-}
-
int io_futexv_wait(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
@@ -331,7 +320,7 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags)
}
io_ring_submit_lock(ctx, issue_flags);
- ifd = io_alloc_ifd(ctx);
+ ifd = io_cache_alloc(&ctx->futex_cache, GFP_NOWAIT, NULL);
if (!ifd) {
ret = -ENOMEM;
goto done_unlock;
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/9] io_uring/poll: Allocate apoll with generic alloc_cache helper
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
` (2 preceding siblings ...)
2024-11-22 21:15 ` [PATCH v2 3/9] io_uring/futex: Allocate ifd with generic alloc_cache helper Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 5/9] io_uring/uring_cmd: Allocate async data through generic helper Gabriel Krisman Bertazi
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
This abstracts away the cache details to simplify the code.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/poll.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/io_uring/poll.c b/io_uring/poll.c
index bced9edd5233..cc01c40b43d3 100644
--- a/io_uring/poll.c
+++ b/io_uring/poll.c
@@ -648,15 +648,12 @@ static struct async_poll *io_req_alloc_apoll(struct io_kiocb *req,
if (req->flags & REQ_F_POLLED) {
apoll = req->apoll;
kfree(apoll->double_poll);
- } else if (!(issue_flags & IO_URING_F_UNLOCKED)) {
- apoll = io_alloc_cache_get(&ctx->apoll_cache);
- if (!apoll)
- goto alloc_apoll;
- apoll->poll.retries = APOLL_MAX_RETRY;
} else {
-alloc_apoll:
- apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC);
- if (unlikely(!apoll))
+ if (!(issue_flags & IO_URING_F_UNLOCKED))
+ apoll = io_cache_alloc(&ctx->apoll_cache, GFP_ATOMIC, NULL);
+ else
+ apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC);
+ if (!apoll)
return NULL;
apoll->poll.retries = APOLL_MAX_RETRY;
}
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 5/9] io_uring/uring_cmd: Allocate async data through generic helper
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
` (3 preceding siblings ...)
2024-11-22 21:15 ` [PATCH v2 4/9] io_uring/poll: Allocate apoll " Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 6/9] io_uring/net: Allocate msghdr async data through helper Gabriel Krisman Bertazi
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
This abstracts away the cache details and simplify the code.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/io_uring.h | 1 +
io_uring/uring_cmd.c | 20 ++------------------
2 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index ddf3f05c3622..91414a4da1b2 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -8,6 +8,7 @@
#include <linux/poll.h>
#include <linux/io_uring_types.h>
#include <uapi/linux/eventpoll.h>
+#include "alloc_cache.h"
#include "io-wq.h"
#include "slist.h"
#include "filetable.h"
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index e9d99d3ecc34..8c1c732b3f15 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -16,22 +16,6 @@
#include "rsrc.h"
#include "uring_cmd.h"
-static struct uring_cache *io_uring_async_get(struct io_kiocb *req)
-{
- struct io_ring_ctx *ctx = req->ctx;
- struct uring_cache *cache;
-
- cache = io_alloc_cache_get(&ctx->uring_cache);
- if (cache) {
- req->flags |= REQ_F_ASYNC_DATA;
- req->async_data = cache;
- return cache;
- }
- if (!io_alloc_async_data(req))
- return req->async_data;
- return NULL;
-}
-
static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
{
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
@@ -181,8 +165,8 @@ static int io_uring_cmd_prep_setup(struct io_kiocb *req,
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
struct uring_cache *cache;
- cache = io_uring_async_get(req);
- if (unlikely(!cache))
+ cache = io_uring_alloc_async_data(&req->ctx->uring_cache, req, NULL);
+ if (!cache)
return -ENOMEM;
if (!(req->flags & REQ_F_FORCE_ASYNC)) {
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 6/9] io_uring/net: Allocate msghdr async data through helper
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
` (4 preceding siblings ...)
2024-11-22 21:15 ` [PATCH v2 5/9] io_uring/uring_cmd: Allocate async data through generic helper Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 7/9] io_uring/rw: Allocate " Gabriel Krisman Bertazi
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
This abstracts away the cache details.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/net.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index df1f7dc6f1c8..8457408194e7 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -155,30 +155,31 @@ static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
}
}
+static void io_msg_async_data_init(void *obj)
+{
+ struct io_async_msghdr *hdr = (struct io_async_msghdr *)obj;
+
+ hdr->free_iov = NULL;
+ hdr->free_iov_nr = 0;
+}
+
static struct io_async_msghdr *io_msg_alloc_async(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
struct io_async_msghdr *hdr;
- hdr = io_alloc_cache_get(&ctx->netmsg_cache);
- if (hdr) {
- if (hdr->free_iov) {
- kasan_mempool_unpoison_object(hdr->free_iov,
- hdr->free_iov_nr * sizeof(struct iovec));
- req->flags |= REQ_F_NEED_CLEANUP;
- }
- req->flags |= REQ_F_ASYNC_DATA;
- req->async_data = hdr;
- return hdr;
- }
+ hdr = io_uring_alloc_async_data(&ctx->netmsg_cache, req,
+ io_msg_async_data_init);
+ if (!hdr)
+ return NULL;
- if (!io_alloc_async_data(req)) {
- hdr = req->async_data;
- hdr->free_iov_nr = 0;
- hdr->free_iov = NULL;
- return hdr;
+ /* If the async data was cached, we might have an iov cached inside. */
+ if (hdr->free_iov) {
+ kasan_mempool_unpoison_object(hdr->free_iov,
+ hdr->free_iov_nr * sizeof(struct iovec));
+ req->flags |= REQ_F_NEED_CLEANUP;
}
- return NULL;
+ return hdr;
}
/* assign new iovec to kmsg, if we need to */
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 7/9] io_uring/rw: Allocate async data through helper
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
` (5 preceding siblings ...)
2024-11-22 21:15 ` [PATCH v2 6/9] io_uring/net: Allocate msghdr async data through helper Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 8/9] io_uring: Move old async data allocation helper to header Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 9/9] io_uring/msg_ring: Drop custom destructor Gabriel Krisman Bertazi
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
This abstract away the cache details.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/rw.c | 36 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index b62cdb5fc936..0db9259bcdd8 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -208,33 +208,29 @@ static void io_req_rw_cleanup(struct io_kiocb *req, unsigned int issue_flags)
}
}
+static void io_rw_async_data_init(void *obj)
+{
+ struct io_async_rw *rw = (struct io_async_rw *)obj;
+
+ rw->free_iovec = 0;
+ rw->bytes_done = 0;
+}
+
static int io_rw_alloc_async(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
struct io_async_rw *rw;
- rw = io_alloc_cache_get(&ctx->rw_cache);
- if (rw) {
- if (rw->free_iovec) {
- kasan_mempool_unpoison_object(rw->free_iovec,
- rw->free_iov_nr * sizeof(struct iovec));
- req->flags |= REQ_F_NEED_CLEANUP;
- }
- req->flags |= REQ_F_ASYNC_DATA;
- req->async_data = rw;
- goto done;
- }
-
- if (!io_alloc_async_data(req)) {
- rw = req->async_data;
- rw->free_iovec = NULL;
- rw->free_iov_nr = 0;
-done:
+ rw = io_uring_alloc_async_data(&ctx->rw_cache, req, io_rw_async_data_init);
+ if (!rw)
+ return -ENOMEM;
+ if (rw->free_iovec) {
+ kasan_mempool_unpoison_object(rw->free_iovec,
+ rw->free_iov_nr * sizeof(struct iovec));
+ req->flags |= REQ_F_NEED_CLEANUP;
rw->bytes_done = 0;
- return 0;
}
-
- return -ENOMEM;
+ return 0;
}
static int io_prep_rw_setup(struct io_kiocb *req, int ddir, bool do_import)
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 8/9] io_uring: Move old async data allocation helper to header
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
` (6 preceding siblings ...)
2024-11-22 21:15 ` [PATCH v2 7/9] io_uring/rw: Allocate " Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 9/9] io_uring/msg_ring: Drop custom destructor Gabriel Krisman Bertazi
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
There are two remaining uses of the old async data allocator that do not
rely on the alloc cache. I don't want to make them use the new
allocator helper because that would require a if(cache) check, which
will result in dead code for the cached case (for callers passing a
cache, gcc can't prove the cache isn't NULL, and will therefore preserve
the check. Since this is an inline function and just a few lines long,
keep a second helper to deal with cases where we don't have an async
data cache.
No functional change intended here. This is just moving the helper
around and making it inline.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/io_uring.c | 13 -------------
io_uring/io_uring.h | 12 ++++++++++++
io_uring/timeout.c | 5 ++---
io_uring/waitid.c | 4 ++--
4 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index bd71782057de..08c42a0e3e74 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1616,19 +1616,6 @@ io_req_flags_t io_file_get_flags(struct file *file)
return res;
}
-bool io_alloc_async_data(struct io_kiocb *req)
-{
- const struct io_issue_def *def = &io_issue_defs[req->opcode];
-
- WARN_ON_ONCE(!def->async_size);
- req->async_data = kmalloc(def->async_size, GFP_KERNEL);
- if (req->async_data) {
- req->flags |= REQ_F_ASYNC_DATA;
- return false;
- }
- return true;
-}
-
static u32 io_get_sequence(struct io_kiocb *req)
{
u32 seq = req->ctx->cached_sq_head;
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 91414a4da1b2..cbd2c0358bb1 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -12,6 +12,7 @@
#include "io-wq.h"
#include "slist.h"
#include "filetable.h"
+#include "opdef.h"
#ifndef CREATE_TRACE_POINTS
#include <trace/events/io_uring.h>
@@ -233,6 +234,17 @@ static inline void *io_uring_alloc_async_data(struct io_alloc_cache *cache,
return req->async_data;
}
+static inline void *io_uring_alloc_async_data_nocache(struct io_kiocb *req)
+{
+ const struct io_issue_def *def = &io_issue_defs[req->opcode];
+
+ WARN_ON_ONCE(!def->async_size);
+ req->async_data = kmalloc(def->async_size, GFP_KERNEL);
+ if (req->async_data)
+ req->flags |= REQ_F_ASYNC_DATA;
+ return req->async_data;
+}
+
static inline bool req_has_async_data(struct io_kiocb *req)
{
return req->flags & REQ_F_ASYNC_DATA;
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index 5b12bd6a804c..078dfd6fcf71 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -526,10 +526,9 @@ static int __io_timeout_prep(struct io_kiocb *req,
if (WARN_ON_ONCE(req_has_async_data(req)))
return -EFAULT;
- if (io_alloc_async_data(req))
+ data = io_uring_alloc_async_data_nocache(req);
+ if (!data)
return -ENOMEM;
-
- data = req->async_data;
data->req = req;
data->flags = flags;
diff --git a/io_uring/waitid.c b/io_uring/waitid.c
index daef5dd644f0..6778c0ee76c4 100644
--- a/io_uring/waitid.c
+++ b/io_uring/waitid.c
@@ -303,10 +303,10 @@ int io_waitid(struct io_kiocb *req, unsigned int issue_flags)
struct io_waitid_async *iwa;
int ret;
- if (io_alloc_async_data(req))
+ iwa = io_uring_alloc_async_data_nocache(req);
+ if (!iwa)
return -ENOMEM;
- iwa = req->async_data;
iwa->req = req;
ret = kernel_waitid_prepare(&iwa->wo, iw->which, iw->upid, &iw->info,
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 9/9] io_uring/msg_ring: Drop custom destructor
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
` (7 preceding siblings ...)
2024-11-22 21:15 ` [PATCH v2 8/9] io_uring: Move old async data allocation helper to header Gabriel Krisman Bertazi
@ 2024-11-22 21:15 ` Gabriel Krisman Bertazi
8 siblings, 0 replies; 10+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-11-22 21:15 UTC (permalink / raw)
To: axboe, asml.silence; +Cc: io-uring, Gabriel Krisman Bertazi
kfree can handle slab objects nowadays. Drop the extra callback and just
use kfree.
Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
---
io_uring/io_uring.c | 4 ++--
io_uring/msg_ring.c | 7 -------
io_uring/msg_ring.h | 1 -
3 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 08c42a0e3e74..1e591234f32b 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -361,7 +361,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free);
io_alloc_cache_free(&ctx->uring_cache, kfree);
- io_alloc_cache_free(&ctx->msg_cache, io_msg_cache_free);
+ io_alloc_cache_free(&ctx->msg_cache, kfree);
io_futex_cache_free(ctx);
kvfree(ctx->cancel_table.hbs);
xa_destroy(&ctx->io_bl_xa);
@@ -2693,7 +2693,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free);
io_alloc_cache_free(&ctx->uring_cache, kfree);
- io_alloc_cache_free(&ctx->msg_cache, io_msg_cache_free);
+ io_alloc_cache_free(&ctx->msg_cache, kfree);
io_futex_cache_free(ctx);
io_destroy_buffers(ctx);
io_unregister_cqwait_reg(ctx);
diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index e63af34004b7..d41ea29802a6 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -358,10 +358,3 @@ int io_uring_sync_msg_ring(struct io_uring_sqe *sqe)
}
return ret;
}
-
-void io_msg_cache_free(const void *entry)
-{
- struct io_kiocb *req = (struct io_kiocb *) entry;
-
- kmem_cache_free(req_cachep, req);
-}
diff --git a/io_uring/msg_ring.h b/io_uring/msg_ring.h
index 38e7f8f0c944..32236d2fb778 100644
--- a/io_uring/msg_ring.h
+++ b/io_uring/msg_ring.h
@@ -4,4 +4,3 @@ int io_uring_sync_msg_ring(struct io_uring_sqe *sqe);
int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags);
void io_msg_ring_cleanup(struct io_kiocb *req);
-void io_msg_cache_free(const void *entry);
--
2.47.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-11-22 21:16 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-22 21:15 [PATCH v2 0/9] Clean up alloc_cache allocations Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 1/9] io_uring: Fold allocation into alloc_cache helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 2/9] io_uring: Add generic helper to allocate async data Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 3/9] io_uring/futex: Allocate ifd with generic alloc_cache helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 4/9] io_uring/poll: Allocate apoll " Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 5/9] io_uring/uring_cmd: Allocate async data through generic helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 6/9] io_uring/net: Allocate msghdr async data through helper Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 7/9] io_uring/rw: Allocate " Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 8/9] io_uring: Move old async data allocation helper to header Gabriel Krisman Bertazi
2024-11-22 21:15 ` [PATCH v2 9/9] io_uring/msg_ring: Drop custom destructor Gabriel Krisman Bertazi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox