]> git.ipfire.org Git - thirdparty/glibc.git/commit
elf: Fix slow tls access after dlopen [BZ #19924]
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 16 Feb 2021 12:55:13 +0000 (12:55 +0000)
committerSunil K Pandey <skpgkp2@gmail.com>
Fri, 10 Jan 2025 20:10:09 +0000 (12:10 -0800)
commit889f99c149b012e83e2b76ef773158cd54c62da9
treebf836e4f5d9467b0863f69e7fbf3e32983d76781
parent543efedcb3dd774e7df985346cd8440f08b073e6
elf: Fix slow tls access after dlopen [BZ #19924]

In short: __tls_get_addr checks the global generation counter and if
the current dtv is older then _dl_update_slotinfo updates dtv up to the
generation of the accessed module. So if the global generation is newer
than generation of the module then __tls_get_addr keeps hitting the
slow dtv update path. The dtv update path includes a number of checks
to see if any update is needed and this already causes measurable tls
access slow down after dlopen.

It may be possible to detect up-to-date dtv faster.  But if there are
many modules loaded (> TLS_SLOTINFO_SURPLUS) then this requires at
least walking the slotinfo list.

This patch tries to update the dtv to the global generation instead, so
after a dlopen the tls access slow path is only hit once.  The modules
with larger generation than the accessed one were not necessarily
synchronized before, so additional synchronization is needed.

This patch uses acquire/release synchronization when accessing the
generation counter.

Note: in the x86_64 version of dl-tls.c the generation is only loaded
once, since relaxed mo is not faster than acquire mo load.

I have not benchmarked this. Tested by Adhemerval Zanella on aarch64,
powerpc, sparc, x86 who reported that it fixes the performance issue
of bug 19924.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
(cherry picked from commit d2123d68275acc0f061e73d5f86ca504e0d5a344)
elf/dl-close.c
elf/dl-open.c
elf/dl-reloc.c
elf/dl-tls.c
sysdeps/generic/ldsodefs.h
sysdeps/x86_64/dl-tls.c