diff --git a/ringbuf/reader_test.go b/ringbuf/reader_test.go index bed7d0096..131336802 100644 --- a/ringbuf/reader_test.go +++ b/ringbuf/reader_test.go @@ -59,7 +59,7 @@ func TestRingbufReader(t *testing.T) { } defer rd.Close() - if uint32(rd.BufferSize()) != 2*events.MaxEntries() { + if uint32(rd.BufferSize()) != events.MaxEntries() { t.Errorf("expected %d BufferSize, got %d", events.MaxEntries(), rd.BufferSize()) } diff --git a/ringbuf/ring.go b/ringbuf/ring.go index 35534c51e..4b062ce78 100644 --- a/ringbuf/ring.go +++ b/ringbuf/ring.go @@ -77,8 +77,11 @@ func (rr *ringReader) isEmpty() bool { return prod == cons } +// To be able to wrap around data, data pages in ring buffers are mapped twice in +// a single contiguous virtual region. +// Therefore the returned usable size is half the size of the mmaped region. func (rr *ringReader) size() int { - return cap(rr.ring) + return cap(rr.ring) / 2 } // Read a record from an event ring.