reducing the contention in dl_iterate_phdr

Thomas Neumann tneumann@users.sourceforge.net
Sat May 16 10:07:14 GMT 2020


Hi,

while trying to speed up exception handling, I noticed the very
unfortunate exclusive lock on dl_load_write_lock within dl_iterate_phdr.
Currently, this prevents multiple threads from unwinding simultaneously.
I think we could improve that significantly and relatively easily by
switching that lock to a rwlock, and locking in shared mode during
dl_iterate_phdr and in exclusive mode in dlclose and friends.
Performance would still not be ideal, as multiple threads would still
fight over the shared cache line of the rwlock, but it would be much
better than now and the change would be minor.

Does that sound like a viable strategy? I am a bit concerned that the
lock is currently marked as recursive lock, which would be problematic
for rwlocks when trying to lock exclusive. I manually checked the code,
and recursive locking can only happen if somebody calls dlopen or
dlclose from within the dl_iterate_phdr callback. But I think that would
be broken in the current code, too, as that could modify the list we are
currently iterating. And in practice that callback is not arbitrary user
code but the unwind library, which does not call dlopen/dlclose.

Thomas



More information about the Libc-help mailing list