Skip to content

"cannot allocate memory in static TLS block" #147

Closed

Description

@pitrou

Take this bug report with a grain of salt, but when enabling mimalloc (note: not using it, just linking our .so with it) some of our CI builds fail deterministically with a "cannot allocate memory in static TLS block" error.

I also know that jemalloc faced a similar issue and provided a build-time option to work around it. It happens in the cases where jemalloc or the jemalloc-containing library (in case jemalloc was statically linked) is loaded lazily using dlopen. This seems to correspond exactly to the cases where we get the aforementioned error.

(amusingly, we were the ones reporting the jemalloc error already :-))

Here is the jemalloc report and discussion:
jemalloc/jemalloc#937
Here is the fix committed to jemalloc. It seems to consist in an additional option that disables -ftls-model=initial-exec:
https://github.com/jemalloc/jemalloc/pull/1180/files

Activity

  1. daanx commented on Sep 3, 2019

    @daanx
    Collaborator

    Darn, mimalloc has just 2 thread local variables, one for the default heap for that thread, and one for the recursion guard. I was hoping that would avoid this error. Is it possible for you try this with commenting out the static mi_decl_thread bool recurse = false; in options.c (just make it static for the test). I wonder if requiring just one slot makes a difference.

    I am working currently also on fixing the TLS recursion guard on Apple (and some BSD) systems so perhaps I will add another way than requiring initial-exec. (Also, it seems building with -ftls-model=gnu2 instead of -ftls-model=initial-exec may work too.)

  2. daanx commented on Sep 3, 2019

    @daanx
    Collaborator

    Just wanted to add that using -ftls-model=local-dynamic should also work and seems to add almost no overhead; maybe 2% in my tests.

  3. pitrou commented on Sep 3, 2019

    @pitrou
    ContributorAuthor

    It seems that -ftls-model=local-dynamic would fix the issue, at least according to my local tests.

  4. pitrou commented on Sep 3, 2019

    @pitrou
    ContributorAuthor

    static bool recurse = false; doesn't seem to work, though (I still get the TLS-related error).

  5. pitrou commented on Sep 3, 2019

    @pitrou
    ContributorAuthor

    And gnu2 isn't recognized here (gcc 7.4.0, Ubuntu 18.04):

    gcc-7: error: unknown TLS model ‘gnu2’
    gcc-7: note: valid arguments to ‘-ftls-model=’ are: global-dynamic initial-exec local-dynamic local-exec
    
  6. daanx commented on Sep 4, 2019

    @daanx
    Collaborator

    Good to hear -- -ftls-model=local-dynamic seems the proper solution for this. Maybe we can make it a build option.

  7. added a commit that references this issue on Sep 4, 2019
    b69a4b5
  8. pitrou commented on Sep 4, 2019

    @pitrou
    ContributorAuthor

    I opened #148.

  9. added a commit that references this issue on Sep 9, 2019
    270e765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions