Re: [RFC v2 4/5] io_uring/bpf: add handle events callback

From: Jens Axboe
Date: Thu Jun 12 2025 - 10:16:51 EST


On 6/11/25 8:28 PM, Alexei Starovoitov wrote:
> On Fri, Jun 6, 2025 at 6:58?AM Pavel Begunkov <asml.silence@xxxxxxxxx> wrote:
>>
>> +static inline int io_run_bpf(struct io_ring_ctx *ctx, struct iou_loop_state *state)
>> +{
>> + scoped_guard(mutex, &ctx->uring_lock) {
>> + if (!ctx->bpf_ops)
>> + return IOU_EVENTS_STOP;
>> + return ctx->bpf_ops->handle_events(ctx, state);
>> + }
>> +}
>
> you're grabbing the mutex before calling bpf prog and doing
> it in a loop million times a second?
> Looks like massive overhead for program invocation.
> I'm surprised it's fast.

Grabbing a mutex is only expensive if it's contended, or obviously
if it's already held. Repeatedly grabbing it on submission where
submission is the only one expected to grab it (or off that path, at
least) means it should be very cheap.

--
Jens Axboe