flt.lttng-utils.debug-info: Implement file descriptor cache
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 3 Apr 2019 17:06:08 +0000 (13:06 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:09:19 +0000 (00:09 -0400)
commit4f1568cb340b663eb5299f48aa7afcbb0ea68ef1
tree881d077535d081b5bbd655a73ab299540656a4e9
parent2ac23a23a6c5ce35e21b7d188894b6e9228d0ad2
flt.lttng-utils.debug-info: Implement file descriptor cache

A `flt.lttng-utils.debug-info` component has to open files in order to
do the address resolving when processing a trace. Those file descriptors
are currently associated with a bin_info structure which are stored in a
hash table for each vpid. If, in the same trace, a binary file is loaded
by more than one process, that binary file will be opened twice. This
can create a file descriptor exhaustion problem on long running traces
if the same UST apps are run repeatedly.

This commit implements a file descriptor caching feature to reuse file
descriptors pointing to the same files.

After creating the file descriptor cache (fdcache), users must use the
following two functions to get and put handles to file descriptors:
  struct fd_handle *fd_cache_get_handle(struct fd_cache *fdc, char *path);
  void fd_cache_put_handle(struct fd_cache *fdc, struct fd_handle *handle);

The fd_handles are reference counted internally and their corresponding
file descriptors are closed when the refcount reaches zero.

Files are compared based on the hashed values of inode and device number
rather than solely on the path. This is needed to make sure that a file
opened previously has not changed. This is more likely to happen when
processing a lttng-live trace where the following scenario can happen
and must be supported:
  1. Binary v1 is executed,
  2. Trace data received by debug-info component,
  3. Handle 1 is taken on the bin_a v1 file,
  4. Addresses resolved using handle 1,
  5. Binary is modified,
  6. Binary v2 is compiled,
  7. Binary v2 is executed,
  8. Trace data received by debug-info component,
  9. Handle 2 is taken on the bin_a v2 file,
  10. Addresses resolved using handle 2.

Limitation
----------
It's still be possible to exhaust file descriptors in traces with a
large number of UST apps with no binary file overlap. If this becomes a
problem, we may consider devising an utility to close least recently
used files and reopening file descriptors for later used.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
14 files changed:
Makefile.am
configure.ac
fd-cache/Makefile.am [new file with mode: 0644]
fd-cache/fd-cache.c [new file with mode: 0644]
fd-cache/logging.c [new file with mode: 0644]
fd-cache/logging.h [new file with mode: 0644]
include/babeltrace/fd-cache-internal.h [new file with mode: 0644]
plugins/lttng-utils/Makefile.am
plugins/lttng-utils/debug-info/Makefile.am
plugins/lttng-utils/debug-info/bin-info.c
plugins/lttng-utils/debug-info/bin-info.h
plugins/lttng-utils/debug-info/debug-info.c
tests/plugins/Makefile.am
tests/plugins/test_bin_info.c
This page took 0.025963 seconds and 5 git commands to generate.