]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/solib-rocm.c
gdb/solib-rocm: limit the number of opened file descriptors
authorLancelot Six <lancelot.six@amd.com>
Thu, 20 Jul 2023 10:15:50 +0000 (10:15 +0000)
committerLancelot SIX <lancelot.six@amd.com>
Fri, 21 Jul 2023 08:21:07 +0000 (09:21 +0100)
commit1c850ca80dc53ffa2bfadabbacda231c941dee76
tree3acb857db22435fc4bd00f3188ae2c93f1610f54
parent178e197078e105ba4fc1b40a0bb6d7384098128e
gdb/solib-rocm: limit the number of opened file descriptors

ROCm programs can load a high number of compute kernels on GPU devices,
especially if lazy code-object loading have been disabled.  Each code
object containing such program is loaded once for each device available,
and each instance is reported by GDB as an individual shared library.

We came across situations where the number of shared libraries opened by
GDB gets higher than the allowed number of opened files for the process.
Increasing the opened files limit works around the problem, but there is a
better way this patch proposes to follow.

Under the hood, the GPU code objects are embedded inside the host
application binary and shared library binaries.  GDB currently opens the
underlying file once for each shared library it sees.  That means that
the same file is re-opened every time a code object is loaded on a GPU.

This patch proposes to only open each underlying file once.  This is
done by implementing a reference counting mechanism so the underlying
file is opened when the underlying file first needs to be opened, and
closed when the last BFD using the underlying file is closed.

On a program where GDB used to open about 1500 files to load all shared
libraries, this patch makes it so only 54 opened file descriptors are
needed.

I have tested this patch on downstream ROCgdb's full testsuite and
upstream GDB testsuite with no regression.

Approved-By: Pedro Alves <pedro@palves.net>
gdb/solib-rocm.c