Fix: alignment of ring buffer shm space reservation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 10 May 2019 15:51:10 +0000 (11:51 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 10 May 2019 17:39:48 +0000 (13:39 -0400)
commit61ec560d6d9b02e8792574bd1a794c2e2c4efe3f
treebaf899ad5dc432e27cdb0d01992e25a4986e239d
parentcac721e112c0f1c2f8cc5bc1fc6c7bbfe9115b62
Fix: alignment of ring buffer shm space reservation

commit a9ff648cc "Implement file-backed ring buffer" changes the order
of backend fields with respect to the frontend per-subbuffer
commit_counters_hot and commit_counters_cold arrays, but does not change
that order when calculating the space needed in the initial pass.

This discrepancy can be an issue for field alignment calculation.
Let's analyse the situation. If the incorrect position of alignment
calculation leads to a larger space reserved than the actual
allocations, no ill effect will be perceived by the user. However,
if space calculation is less than the allocations, it will cause the
ring buffer (and thus channel) creation to fail.

The fields that are incorrectly misplaced in size calculation (in
officially released versions) are:

* struct commit_counters_hot is aligned on CAA_CACHE_LINE_SIZE,
* struct commit_counters_cold is aligned on CAA_CACHE_LINE_SIZE,

Those are placed after (should be before) the backend fields:

* struct lttng_ust_lib_ring_buffer_backend_pages_shmp aligned on the
  natural alignment of ssize_t,
* alignment on page size,
* struct lttng_ust_lib_ring_buffer_backend_pages, aligned on the natural
  alignment of ssize_t,
* struct lttng_ust_lib_ring_buffer_backend_subbuffer, aligned on natural
  alignment of unsigned long,
* struct lttng_ust_lib_ring_buffer_backend_counts, aligned on natural
  alignment of uint64_t.

The largest alignment is the alignment on page size in the backend
fields. If we have a channel configured within specific ranges of
sub-buffer count, we should reach commit counters array dimensions
which cause the page size alignment to be lower than it should be in
the space calculation, and therefore leads to a problematic scenario
where space allocation will fail, thus leading to channel creation
failures.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/ring_buffer_backend.c
This page took 0.024997 seconds and 4 git commands to generate.