Re: [PATCH] bpf: ringbuf: add wakeup coalescing
From: Michael S. Tsirkin
Date: Thu Dec 03 2026 - 02:00:57 EST
On Thu, Dec 03, 2026 at 04:03:09AM +0000, Alexei Starovoitov wrote:
> On Tue, Dec 01, 2026 at 11:19 PM Michael S. Tsirkin <mst@xxxxxxxxxx> wrote:
> >> No. Not every ringbuf is a stream of samples.
> >
> > Right. What if I limit it per type or something? Can make it
> > palatable?
>
> No. The type doesn't tell a stream of samples from a one-off signal.
> A ringbuf isn't tied to a prog type either.
> Progs of different types can share one.
Right. I don't have a better generic idea, to be frank.
> > Shrug. I didn't write this thing. So what can be done about misbehaving
> > ones, that hammer the box with wakeups on every event anywhere under /?
> > Any idea?
>
> It's a wakeup per event only while the consumer keeps up with the prog.
> bpf_ringbuf_commit() with flags == 0:
>
> else if (cons_pos == rec_pos && !(flags & BPF_RB_NO_WAKEUP))
> irq_work_queue(&rb->work);
>
> So slow down the consumer. Try cpu.max on the cgroup of the tool.
> Once the tool is out of quota:
>
> prog consumer
> rec 1: cons_pos == rec_pos
> wakeup
> throttled before it reads rec 1
> rec 2 to N: cons_pos != rec_pos
> no wakeup
> next period: reads rec 1 to N
>
> That's per box and per tool. No need for kernel changes.
> If the quota is too low the ring fills up and records are lost.
Lost records is exactly the problem with this approach. If I wanted lost
records, I could just stop the monitor, see? What my patch does is
basically like NAPI for networking. This way, the records are not
lost.
I think I will just have to carry an out of tree patch for now. It's a
bit of a hassle but hey.
--
MST