From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [PATCH v2 7/8] io_uring: count allocated requests
Date: Fri, 9 May 2025 12:12:53 +0100 [thread overview]
Message-ID: <c8f8308294dc2a1cb8925d984d937d4fc14ab5d4.1746788718.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1746788718.git.asml.silence@gmail.com>
Keep track of the number requests a ring currently has allocated (and
not freed), it'll be needed in the next patch.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
include/linux/io_uring_types.h | 1 +
io_uring/io_uring.c | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 7e23e993280e..73b289b48280 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -435,6 +435,7 @@ struct io_ring_ctx {
/* protected by ->completion_lock */
unsigned evfd_last_cq_tail;
+ unsigned nr_req_allocated;
/*
* Protection for resize vs mmap races - both the mmap and resize
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 9619c46bd25e..14188f49a4ce 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -954,6 +954,8 @@ __cold bool __io_alloc_req_refill(struct io_ring_ctx *ctx)
}
percpu_ref_get_many(&ctx->refs, ret);
+ ctx->nr_req_allocated += ret;
+
while (ret--) {
struct io_kiocb *req = reqs[ret];
@@ -2691,8 +2693,10 @@ static void io_req_caches_free(struct io_ring_ctx *ctx)
kmem_cache_free(req_cachep, req);
nr++;
}
- if (nr)
+ if (nr) {
+ ctx->nr_req_allocated -= nr;
percpu_ref_put_many(&ctx->refs, nr);
+ }
mutex_unlock(&ctx->uring_lock);
}
@@ -2729,6 +2733,9 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
percpu_ref_exit(&ctx->refs);
free_uid(ctx->user);
io_req_caches_free(ctx);
+
+ WARN_ON_ONCE(ctx->nr_req_allocated);
+
if (ctx->hash_map)
io_wq_put_hash(ctx->hash_map);
io_napi_free(ctx);
--
2.49.0
next prev parent reply other threads:[~2025-05-09 11:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 11:12 [PATCH v2 0/8] allocated requests based drain and fixes Pavel Begunkov
2025-05-09 11:12 ` [PATCH v2 1/8] io_uring: account drain memory to cgroup Pavel Begunkov
2025-05-09 11:12 ` [PATCH v2 2/8] io_uring: fix spurious drain flushing Pavel Begunkov
2025-05-09 11:12 ` [PATCH v2 3/8] io_uring: simplify drain ret passing Pavel Begunkov
2025-05-09 11:12 ` [PATCH v2 4/8] io_uring: remove drain prealloc checks Pavel Begunkov
2025-05-09 11:12 ` [PATCH v2 5/8] io_uring: consolidate drain seq checking Pavel Begunkov
2025-05-09 11:12 ` [PATCH v2 6/8] io_uring: open code io_account_cq_overflow() Pavel Begunkov
2025-05-09 11:12 ` Pavel Begunkov [this message]
2025-05-09 11:12 ` [PATCH v2 8/8] io_uring: drain based on allocates reqs Pavel Begunkov
2025-05-13 10:37 ` Andy Shevchenko
2025-05-13 13:35 ` Pavel Begunkov
2025-05-09 14:02 ` [PATCH v2 0/8] allocated requests based drain and fixes Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c8f8308294dc2a1cb8925d984d937d4fc14ab5d4.1746788718.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox