]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
io_uring: cap cached iovec/bvec size
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 7 Mar 2025 16:00:37 +0000 (16:00 +0000)
committerJens Axboe <axboe@kernel.dk>
Fri, 7 Mar 2025 20:41:08 +0000 (13:41 -0700)
Bvecs can be large, put an arbitrary limit on the max vector size it
can cache.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/823055fa6628daa24bbc9cd77c2da87e9a1e1e32.1741362889.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/net.c
io_uring/rsrc.h
io_uring/rw.c

index 40ecf421798f4a39b42dc0e64650f9c52fa5c1d3..34a28689ec998f826cc8f441279e7c257824b859 100644 (file)
@@ -152,6 +152,9 @@ static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags)
 
        /* Let normal cleanup path reap it if we fail adding to the cache */
        io_alloc_cache_vec_kasan(&hdr->vec);
+       if (hdr->vec.nr > IO_VEC_CACHE_SOFT_CAP)
+               io_vec_free(&hdr->vec);
+
        if (io_alloc_cache_put(&req->ctx->netmsg_cache, hdr)) {
                req->async_data = NULL;
                req->flags &= ~REQ_F_ASYNC_DATA;
index 0d5c182961306d8763c29ca93920cc8b354ac79a..b0097c06b577e7fc9b7dba1d9b7f9f748548a7bb 100644 (file)
@@ -5,6 +5,8 @@
 #include <linux/io_uring_types.h>
 #include <linux/lockdep.h>
 
+#define IO_VEC_CACHE_SOFT_CAP          256
+
 enum {
        IORING_RSRC_FILE                = 0,
        IORING_RSRC_BUFFER              = 1,
index e62f4ce34171d08951f77645560e44592c41653f..bf35599d1078fa786c6c286b7ce6f4a98755151b 100644 (file)
@@ -150,6 +150,9 @@ static void io_rw_recycle(struct io_kiocb *req, unsigned int issue_flags)
                return;
 
        io_alloc_cache_vec_kasan(&rw->vec);
+       if (rw->vec.nr > IO_VEC_CACHE_SOFT_CAP)
+               io_vec_free(&rw->vec);
+
        if (io_alloc_cache_put(&req->ctx->rw_cache, rw)) {
                req->async_data = NULL;
                req->flags &= ~REQ_F_ASYNC_DATA;