Re: Tackling thread local storage in Chromium

225 views
Skip to first unread message

Kentaro Hara

unread,
Oct 18, 2023, 4:37:14 PM10/18/23
to Benoit Lize, memory-s...@chromium.org, Andre Kempe, Bartek Nowierski, Joe Mason, Peter Kasting, Takashi Sakamoto, Keishi Hattori, Richard Townsend
Thanks Andre for kicking off the discussion! Cc-ing @memory-s...@chromium.org since this is an important discussion :)


On Wed, Oct 18, 2023 at 8:45 PM Benoit Lize <li...@chromium.org> wrote:
Thanks, left some comments in the document.

I have a more general question (it's been a while since I looked at TLS in PA): can we use PA's restricted TLS implementation for all the use cases where we must not allocate?
It's restricted, doesn't handle non-trivial constructors and destructors for instance, but it works.

On Wed, Oct 18, 2023 at 1:18 PM Andre Kempe <Andre...@arm.com> wrote:

Hej everyone.

 

I think we all have run into this issue a couple of times now: Crashes introduced by thread local data which is implemented on top of some allocating low level library. Takashi has just provided a patch to solve another of these crashes, see https://chromium-review.googlesource.com/c/chromium/src/+/4864264. The problem seems to be so widespread that by now we have 4 different approaches to solving them. All these approaches have different drawbacks, i.e., not being usable in allocation hooks because they allocate themselves.

 

One of the problems seems to be pthreads and its distinction of allocating vs. non-allocating paths. We have no way to really check if the key is non-allocating. However, there are multiple instances that try to create a pthread-key with non-allocating properties using an early init approach, thus creating a competition for a ‘good’ key.

 

Would it be worthwhile to think about a solution to these allocation problems while trying to unify the solutions that we currently implement? What’s your opinion on this? To start a discussion and exchange on that topic, we‘ve created this document https://docs.google.com/document/d/1a8UTCusOmeN5tNJXq_m6CNnaKjUkjhxSXdxTF6j_sWQ/edit?usp=sharing in which we tried to summarize the known world of thread local storage in Chromium and also to sketch some possible solutions. If you think that’s something that should be addressed, please comment in the document, or reply via email.

 

Thanks & Best Regards,

André

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


--
Kentaro Hara, Tokyo

Andre Kempe

unread,
Oct 19, 2023, 5:41:44 PM10/19/23
to Joe Mason, memory-s...@chromium.org, Benoit Lize, Kentaro Hara, Bartek Nowierski, Peter Kasting, Takashi Sakamoto, Keishi Hattori, Richard Townsend

Kentaro added memory-s...@chromium.org Unfortunately they got somewhere on the road, so readding them.

 

I am not sure about the restricted TLS that PA implements. I found only this one which it seems to be a wrapper around pthread: https://source.chromium.org/chromium/chromium/src/+/main:base/allocator/partition_allocator/src/partition_alloc/partition_tls.h;drc=0bcc023b8cdbc073aa5c48db373810db3f765c87;l=67

 

 

From: Joe Mason <joenot...@google.com>
Sent: Wednesday, October 18, 2023 7:12 PM
To: Andre Kempe <Andre...@arm.com>
Cc: Benoit Lize <li...@chromium.org>; Kentaro Hara <har...@google.com>; Bartek Nowierski <bar...@google.com>; Peter Kasting <pkas...@google.com>; Takashi Sakamoto <ta...@google.com>; Keishi Hattori <kei...@google.com>; Richard Townsend <Richard....@arm.com>
Subject: Re: Tackling thread local storage in Chromium

 

For PoissonAllocationSampler, and possible other allocator hooks, it would be possible to just bail out of the hook and disable the feature if it runs out of preallocated TLS space. As long as the initial allocation is created before the hook is installed to prevent recursion.

 

On Wed, Oct 18, 2023 at 1:50 PM Andre Kempe <Andre...@arm.com> wrote:

I am not familiar with PA's restricted TLS.

 

Base/allocator/dispatcher/tls.h implements a full TLS emulation, very much like emuTLS, but by using mmapped memory to provide thread specific instances while using pthread for the thread-to-instance mapping. It should be possible to switch from pthread to PA’s restricted TLS.

 

I am not sure about base::threading::ThreadLocalStorage, though.

Reply all
Reply to author
Forward
0 new messages