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 16:30:41 +0000 (12:30 -0400)
commitd2f09c1c0be1557e0beb268d13b2b8134f7ab0a1
treea1e5d7a055339ea7d003840f1a6075649db53ece
parentc3691b8a0bf6cdeada62956d56e17ff57291b5d5
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.025025 seconds and 4 git commands to generate.