From: Pavel Begunkov <asml.silence@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: io-uring <io-uring@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH v8 5/5] selftests/io_uring: add a bpf io_uring selftest
Date: Fri, 20 Feb 2026 11:41:39 +0000 [thread overview]
Message-ID: <84e2f3ad-28f0-4e9a-804f-2647cba9b30f@gmail.com> (raw)
In-Reply-To: <CAADnVQK0RaOA9ZYZdYyQxOzLde9MR8HpMM0SexcW59A9u7X2Jw@mail.gmail.com>
On 2/19/26 19:01, Alexei Starovoitov wrote:
> On Tue, Feb 17, 2026 at 3:33 AM Pavel Begunkov <asml.silence@gmail.com> wrote:
>> +
>> +static inline void write_stats(int idx, unsigned int v)
>> +{
>> + u32 key = idx;
>> + u64 *val;
>> +
>> + val = bpf_map_lookup_elem(&res_map, &key);
>> + if (val)
>> + *val += v;
>> +}
>
> Since these examples will be copied around, let's use
> good coding practices. Use properly named global variables
> for stats and counters, and drop this opaque array.
ok
...
>> + unsigned to_wait = cq_hdr->tail - cq_hdr->head;
>> + to_wait = t_min(to_wait, CQ_ENTRIES);
>> + for (int i = 0; i < to_wait; i++) {
>> + struct io_uring_cqe *cqe = &cqes[cq_hdr->head & (CQ_ENTRIES - 1)];
>> +
>> + if (cqe->user_data != REQ_TOKEN) {
>> + write_result(-3);
>> + return IOU_LOOP_STOP;
>> + }
>> + cq_hdr->head++;
>> + }
>
> CQ_ENTRIES is just 8.
> Is it enough for real progs?
> Does the above approach scale ?
Depends on the workload. If you're keeping queue depth 8 with a
storage workload, it's all you need, and those don't go too high.
For net recv workloads, it's batched well if you get 8-16 CQEs per
wait, but unfortunately too often it's close to 1. You'd still bump
the CQ size in cases there are bursts in traffic.
We can come up with cases when it's higher, but what's important is
that you don't need to process all CQEs in a single BPF call. I bound
the loop at CQ_ENTRIES for convenience, but the user can set the CQ
size to whatever is needed, process some capped number every time,
and finish the rest if any next time it's called. E.g.
CQ_ENTRIES = 2^14
const max_cqes_batch = 32;
cqes_to_process = cq_hdr->tail - cq_hdr->head;
cqes_to_process = min(cqes_to_process, max_cqes_batch);
process_cqes_nr(cqes_to_process, ...);
if (cqes_left)
to_wait = 0;
I'll make the CQ size a load time constant and clean up the
program, should make it a better example.
> I mean the above works as a bounded loop because loop
> count is small, but for 100+ you want open coded iterators.
Sure, but let's do that as a follow up when it's needed?
> In general all progs seem to be toy progs.
> Would be good to have something more realistic.
The other two programs are not toys but rather tests. Nop requests in
this one do nothing useful, but that'll be a good queue processing
starting template. Replace nops with reads and it's doing actual IO.
Add writes requests with some offset logic and it copies data b/w files.
I had such examples, but selftests is not the best place for that.
It can use abstractions, and I want to make them reusable instead
of people copy-pasting from selftests.
--
Pavel Begunkov
next prev parent reply other threads:[~2026-02-20 11:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 11:33 [PATCH v8 0/5] BPF controlled io_uring Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 1/5] io_uring: introduce callback driven main loop Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 2/5] io_uring/bpf-ops: implement loop_step with BPF struct_ops Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 3/5] io_uring/bpf-ops: add kfunc helpers Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 4/5] io_uring/bpf-ops: implement bpf ops registration Pavel Begunkov
2026-02-17 11:33 ` [PATCH v8 5/5] selftests/io_uring: add a bpf io_uring selftest Pavel Begunkov
2026-02-19 19:01 ` Alexei Starovoitov
2026-02-20 11:41 ` Pavel Begunkov [this message]
2026-02-20 17:45 ` Alexei Starovoitov
2026-02-20 22:35 ` Pavel Begunkov
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=84e2f3ad-28f0-4e9a-804f-2647cba9b30f@gmail.com \
--to=asml.silence@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=axboe@kernel.dk \
--cc=bpf@vger.kernel.org \
--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