Skip to content

GH-50428: [C++] Better mimalloc configuration on macOS#50549

Open
pitrou wants to merge 4 commits into
apache:mainfrom
pitrou:gh50428-mimalloc-macos
Open

GH-50428: [C++] Better mimalloc configuration on macOS#50549
pitrou wants to merge 4 commits into
apache:mainfrom
pitrou:gh50428-mimalloc-macos

Conversation

@pitrou

@pitrou pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member

Rationale for this change

On macOS, two independently-linked mimalloc v3 instances built with default TLS settings can end up using the same hard-coded TLS slots and crash due to conflicting expectations. See upstream issue at microsoft/mimalloc#1327

This can manifest when PyArrow is loaded side-by-side with another Python extension module that bundles its own instance of mimalloc.

What changes are included in this PR?

Configure macOS to use C thread-local variables for thread-local storage, avoiding conflicting accesses to hard-coded TLS slots on macOS.

Also, unrelatedly, make sure the default malloc is not overriden by our mimalloc build on macOS.

Are these changes tested?

By existing CI jobs.

Are there any user-facing changes?

No, just a bugfix.

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelmacos*

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50428 has been automatically assigned in GitHub to PR creator.

@github-actions

This comment was marked as outdated.

@pitrou pitrou added the CI: Extra: C++ Run extra C++ CI label Jul 20, 2026
@pitrou
pitrou marked this pull request as ready for review July 20, 2026 13:27
@pitrou
pitrou requested a review from raulcd July 20, 2026 13:27
-DMI_LOCAL_DYNAMIC_TLS=ON
# GH-50428: Make sure several mimalloc instances can cohabit in the same process
# (also https://github.com/microsoft/mimalloc/issues/1327#issuecomment-4964140817)
-DMI_TLS_MODEL_THREAD_LOCAL=ON

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the built wheel logs I can see that MI_TLS_MODEL_THREAD_LOCAL don't seem to be used:

 CMake Warning:
  Manually-specified variables were not used by the project:

    BUILD_STATIC_LIBS
    BUILD_TESTING
    CMAKE_CXX_COMPILER
    CMAKE_CXX_FLAGS
    CMAKE_CXX_FLAGS_DEBUG
    CMAKE_CXX_FLAGS_MISIZEREL
    CMAKE_CXX_FLAGS_RELEASE
    CMAKE_CXX_FLAGS_RELWITHDEBINFO
    CMAKE_C_FLAGS_MISIZEREL
    CMAKE_POLICY_VERSION_MINIMUM
    MI_TLS_MODEL_THREAD_LOCAL

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, you're right, I was blindly copying the suggestion from the mimalloc issue.

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Jul 20, 2026
Comment thread cpp/cmake_modules/ThirdpartyToolchain.cmake Outdated
@github-actions github-actions Bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jul 20, 2026
@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelmacos*

@github-actions

This comment was marked as outdated.

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

Silly me: the option I'm adding was only added in mimalloc 3.4.0 🤦

@raulcd

raulcd commented Jul 20, 2026

Copy link
Copy Markdown
Member

Silly me: the option I'm adding was only added in mimalloc 3.4.0 🤦

I am trying to bump here:

But there are several CI failures which I haven't diagnosed yet, do you want me to try this change there?

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

I've pushed the 3.4.1 change here and we'll see...

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelmacoscp314

@github-actions

Copy link
Copy Markdown

Revision: 0bf57cb

Submitted crossbow builds: ursacomputing/crossbow @ actions-ea3f09b433

Task Status
wheel-macos-monterey-cp314-cp314-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-arm64 GitHub Actions

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelmacos*

@github-actions

Copy link
Copy Markdown

Revision: c5a439d

Submitted crossbow builds: ursacomputing/crossbow @ actions-e31f2f43ac

Task Status
wheel-macos-monterey-cp311-cp311-amd64 GitHub Actions
wheel-macos-monterey-cp311-cp311-arm64 GitHub Actions
wheel-macos-monterey-cp312-cp312-amd64 GitHub Actions
wheel-macos-monterey-cp312-cp312-arm64 GitHub Actions
wheel-macos-monterey-cp313-cp313-amd64 GitHub Actions
wheel-macos-monterey-cp313-cp313-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-arm64 GitHub Actions

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit wheelcp314*

@github-actions

Copy link
Copy Markdown

Revision: c5a439d

Submitted crossbow builds: ursacomputing/crossbow @ actions-bf2306637b

Task Status
wheel-macos-monterey-cp314-cp314-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314-arm64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-amd64 GitHub Actions
wheel-macos-monterey-cp314-cp314t-arm64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314-amd64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314-arm64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314t-amd64 GitHub Actions
wheel-manylinux-2-28-cp314-cp314t-arm64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314-amd64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314-arm64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314t-amd64 GitHub Actions
wheel-musllinux-1-2-cp314-cp314t-arm64 GitHub Actions
wheel-windows-cp314-cp314-amd64 GitHub Actions
wheel-windows-cp314-cp314t-amd64 GitHub Actions

@pitrou

pitrou commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

The combination of the version bump + the new TLS model option seems to work fine. @raulcd

Comment on lines +2583 to +2584
set(MIMALLOC_CMAKE_ARGS
${MIMALLOC_CMAKE_ARGS}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(MIMALLOC_CMAKE_ARGS
${MIMALLOC_CMAKE_ARGS}
list(APPEND MIMALLOC_CMAKE_ARGS

@github-actions github-actions Bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants