ringbuf: add UnsafeReader as zero-copy ringbuf reader#1979
Draft
jschwinger233 wants to merge 3 commits intocilium:mainfrom
Draft
ringbuf: add UnsafeReader as zero-copy ringbuf reader#1979jschwinger233 wants to merge 3 commits intocilium:mainfrom
jschwinger233 wants to merge 3 commits intocilium:mainfrom
Conversation
No functional change intended. This commit only reshapes internal call paths so upcoming zero-copy APIs can reuse the same read/poll machinery. Introduce two internal APIs: - readWithPoll: centralizes the Reader poll/wait loop (deadline, flush, pending errors, busy/EOR handling) and executes a caller-supplied record read callback. - readRecordFunc: centralizes ring record decoding and yields a zero-copy sample view plus remaining bytes and next consumer position to a caller-supplied callback. Signed-off-by: graymon <greyschwinger@gmail.com>
Add a new ringbuf.UnsafeReader dedicated to zero-copy consumption. It supports two ways of reading: either call Read/ReadInto and then Commit explicitly, or use ReadFunc and have the record committed automatically after the callback returns. The new type reuses the same internal polling and ring decoding paths as Reader (readWithPoll + readRecordFunc), and keeps Reader’s existing copy-based behavior unchanged. This API is intentionally unsafe for concurrent use. Signed-off-by: graymon <greyschwinger@gmail.com>
Signed-off-by: graymon <greyschwinger@gmail.com>
Member
Author
|
@ti-mo I drafted this PR to address the comments and move the discussion forward: #1968 (comment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ringbuf.Reader.ReadInto always copies sample bytes into user-owned memory. That is safe and convenient, but it becomes a visible bottleneck as sample size grows.
This PR introduces that path as a separate type (UnsafeReader) so the tradeoff is explicit: performance vs safety/concurrency guarantees.
APIs
Read
ReadInto
ReadFunc
Benchmark Results
Benchmark is done by https://github.com/jschwinger233/bpf_ringbuf_zc_benchmark
Observed throughput (UnsafeReader.ReadInto vs Reader.ReadInto):
Trend: small records show modest gains; larger records show strong scaling, peaking at ~6.4x.
Related
#1968
#1930
#1915