MaeBPF.RingBuf (maebpf v0.1.0)

Copy Markdown View Source

Zero-polling BPF_MAP_TYPE_RINGBUF consumer backed by ring_buffer__epoll_fd and BEAM enif_select.

Supports bounded list draining (consume/2) and single-allocation packed binary draining (consume_packed/2) with zero-copy pure-Elixir decoders (decode_packed/1, fold_packed/3).

Summary

Functions

Stops enif_select registration and releases the underlying ring buffer.

Drains up to :max_events (default 512) currently available samples from the ring buffer without blocking.

Drains up to :max_events (default 1024) or :max_bytes (default 262_144) samples into a single contiguous little-endian length-prefixed binary

Decodes a packed ring buffer binary into a list of zero-copy sub-binaries.

Folds over a packed ring buffer binary without allocating an intermediate list.

Returns the duplicated map file descriptor owned by this ring buffer handle.

Opens a kernel ring buffer from an already-opened pinned map handle.

Opens a kernel ring buffer map from a loaded eBPF object.

Arms BEAM enif_select readiness notification on the ring buffer's epoll FD.

Functions

close(ringbuf)

Stops enif_select registration and releases the underlying ring buffer.

consume(ringbuf, opts \\ [])

Drains up to :max_events (default 512) currently available samples from the ring buffer without blocking.

Returns {:ok, events, has_more} where has_more is true when the event bound was reached and callers should yield before draining further.

consume_packed(ringbuf, opts \\ [])

Drains up to :max_events (default 1024) or :max_bytes (default 262_144) samples into a single contiguous little-endian length-prefixed binary:

<<len::little-unsigned-32, payload::binary-size(len), ...>>

Returns {:ok, count, packed_binary, has_more}.

decode_packed(packed_bin)

Decodes a packed ring buffer binary into a list of zero-copy sub-binaries.

fold_packed(bin, acc, fun)

Folds over a packed ring buffer binary without allocating an intermediate list.

map_fd(ringbuf)

Returns the duplicated map file descriptor owned by this ring buffer handle.

open(pinned_map)

Opens a kernel ring buffer from an already-opened pinned map handle.

open(object, map_name)

Opens a kernel ring buffer map from a loaded eBPF object.

select(ringbuf, ref)

Arms BEAM enif_select readiness notification on the ring buffer's epoll FD.

When kernel events arrive, the calling process receives {:select, ringbuf, ref, :ready_input}.