lttng: Warn on session start when client-visible shm path is too small
Observed issue
==============
When adding one or more channels to a session, it is possible to
configure sessions such that the minimum memory required to
successfully trace exceeds the size of the shared memory location.
There is no user feedback when starting sessions that are configured
in such a way that they will never work. It therefore leads to
user confusion when no events are recorded.
Steps to reproduce
==================
On a system with 4 cpus:
```
sudo mount -t tmpfs -o size=64M tmpfs /mnt
lttng create --shm-path=/mnt
lttng enable-channel -u --subbuf-size=8M a0
lttng enable-event -u --all -c a0
lttng start
lttng stop
```
Cause
=====
As allocations are made lazily, there is no feedback for this type of
scenario visible to an lttng client. The session can successfully
start; however, there will be allocation errors visible in the
consumer daemon logs.
Solution
========
When starting a session, the minimum shared memory size required is
estimated using the configured non-kernel channels. This assumes
per-PID or per-UID buffers with a single PID or a single UID. An extra
set of buffers are estimated when the session is configured in
snapshot mode.
E.g.
```
$ lttng create
Session auto-
20241112-102937 created.
Traces will be output to
/home/kstewart/src/efficios/lttng/master/home//lttng-traces/auto-
20241112-102937
$ lttng enable-channel -u --subbuf-size=256M --num-subbuf=8 a2
user space channel `a2` enabled for session `auto-
20241112-102937`
$ lttng start
Warning: The estimated minimum shared memory size for all non-kernel channels of session 'auto-
20241112-102937' is greater than the total shared memory allocated to the default shared memory location (8192MiB >= 7873MiB). Tracing for this session may not record events due to allocation failures.
Tracing started for session `auto-
20241112-102937`
$ lttng list
Available recording sessions:
1) auto-
20241112-102937 [active]
Trace output:
/home/kstewart/src/efficios/lttng/master/home//lttng-traces/auto-
20241112-102937
```
Known drawbacks
===============
The intention of this change is to be backwards compatible, and
therefore doesn't stop the session from being started.
With per-PID or per-UID sub-buffers, the estimate is based only a
single PID or UID. Additional PIDs or UIDs could cause allocation
failures later on in the runtime which will continue to only be
visible in the consumer daemon logs.
The shm path is estimated by the lttng client rather than the consumer
daemon. It is possible for the consumer daemon be running in a
different container whose shared memory path maps to a different
backing storage.
This checks only against the total size of the shared memory storage -
not the current available usage. It does not take into account other
current enabled sessions.
Change-Id: I589ec461ec4a89b72bcdf1271065591ac471acca
Signed-off-by: Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>