[PATCH 7/7] io_uring: account the remaining per-object allocations to memcg

From: Tao Cui

Date: Fri Nov 06 2026 - 08:21:59 EST


From: Tao Cui <cuitao@xxxxxxxxxx>

A handful of io_uring allocations still scale with user controlled
counts on plain GFP_KERNEL: the per-ring io-wq and its workers, the
alloc cache entry arrays, the provided buffer peek and import iovec
arrays, and the registered eventfd contexts. The tctx side is covered
by commit 0b34e7b20a48 ("io_uring: charge tctx nodes and
personalities").

Charge what is left.

Signed-off-by: Tao Cui <cuitao@xxxxxxxxxx>
---
io_uring/alloc_cache.c | 3 ++-
io_uring/eventfd.c | 2 +-
io_uring/io-wq.c | 4 ++--
io_uring/kbuf.c | 2 +-
4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/io_uring/alloc_cache.c b/io_uring/alloc_cache.c
index 58423888b736..f41df1878633 100644
--- a/io_uring/alloc_cache.c
+++ b/io_uring/alloc_cache.c
@@ -22,7 +22,8 @@ bool io_alloc_cache_init(struct io_alloc_cache *cache,
unsigned max_nr, unsigned int size,
unsigned int init_bytes)
{
- cache->entries = kvmalloc_array(max_nr, sizeof(void *), GFP_KERNEL);
+ cache->entries = kvmalloc_array(max_nr, sizeof(void *),
+ GFP_KERNEL_ACCOUNT);
if (!cache->entries)
return true;

diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c
index 63fe6e5d79ba..52f5d5b85f30 100644
--- a/io_uring/eventfd.c
+++ b/io_uring/eventfd.c
@@ -132,7 +132,7 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,
if (copy_from_user(&fd, fds, sizeof(*fds)))
return -EFAULT;

- ev_fd = kmalloc_obj(*ev_fd);
+ ev_fd = kmalloc_obj(*ev_fd, GFP_KERNEL_ACCOUNT);
if (!ev_fd)
return -ENOMEM;

diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
index 92df54c6f50c..98f3aa378baf 100644
--- a/io_uring/io-wq.c
+++ b/io_uring/io-wq.c
@@ -981,7 +981,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wq_acct *acct)

__set_current_state(TASK_RUNNING);

- worker = kzalloc_obj(*worker);
+ worker = kzalloc_obj(*worker, GFP_KERNEL_ACCOUNT);
if (!worker) {
fail:
atomic_dec(&acct->nr_running);
@@ -1358,7 +1358,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
if (WARN_ON_ONCE(!bounded))
return ERR_PTR(-EINVAL);

- wq = kzalloc_obj(struct io_wq);
+ wq = kzalloc_obj(struct io_wq, GFP_KERNEL_ACCOUNT);
if (!wq)
return ERR_PTR(-ENOMEM);

diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index abf44f5dba26..bc6e552a91dd 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -288,7 +288,7 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
* a speculative peek operation.
*/
if (arg->mode & KBUF_MODE_EXPAND && nr_avail > nr_iovs && arg->max_len) {
- iov = kmalloc_objs(struct iovec, nr_avail);
+ iov = kmalloc_objs(struct iovec, nr_avail, GFP_KERNEL_ACCOUNT);
if (unlikely(!iov))
return -ENOMEM;
arg->iovs = iov;
--
2.43.0