From 12fbfa08c5a2c4ad874de84bc47b0024fa21abee Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 17 Sep 2025 16:56:08 +0200 Subject: [PATCH 1/7] GH-47588: [C++] Bump mimalloc version to 3.0.9 According to microsoft/mimalloc#1073 , mimalloc v3 is preferred over v2 for production usage. --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 5 +++-- cpp/thirdparty/versions.txt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 7d110e8dbb8..e671055d7bd 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2276,9 +2276,9 @@ if(ARROW_MIMALLOC) endif() set(MIMALLOC_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/mimalloc_ep/src/mimalloc_ep") - set(MIMALLOC_INCLUDE_DIR "${MIMALLOC_PREFIX}/include/mimalloc-2.2") + set(MIMALLOC_INCLUDE_DIR "${MIMALLOC_PREFIX}/include") set(MIMALLOC_STATIC_LIB - "${MIMALLOC_PREFIX}/lib/mimalloc-2.2/${CMAKE_STATIC_LIBRARY_PREFIX}${MIMALLOC_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${MIMALLOC_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${MIMALLOC_LIB_BASE_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" ) set(MIMALLOC_C_FLAGS ${EP_C_FLAGS}) @@ -2291,6 +2291,7 @@ if(ARROW_MIMALLOC) ${EP_COMMON_CMAKE_ARGS} "-DCMAKE_C_FLAGS=${MIMALLOC_C_FLAGS}" "-DCMAKE_INSTALL_PREFIX=${MIMALLOC_PREFIX}" + -DMI_INSTALL_TOPLEVEL=ON -DMI_OVERRIDE=OFF -DMI_LOCAL_DYNAMIC_TLS=ON -DMI_BUILD_OBJECT=OFF diff --git a/cpp/thirdparty/versions.txt b/cpp/thirdparty/versions.txt index 092f7939b44..682846cd056 100644 --- a/cpp/thirdparty/versions.txt +++ b/cpp/thirdparty/versions.txt @@ -82,8 +82,8 @@ ARROW_JEMALLOC_BUILD_VERSION=5.3.0 ARROW_JEMALLOC_BUILD_SHA256_CHECKSUM=2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa ARROW_LZ4_BUILD_VERSION=v1.10.0 ARROW_LZ4_BUILD_SHA256_CHECKSUM=537512904744b35e232912055ccf8ec66d768639ff3abe5788d90d792ec5f48b -ARROW_MIMALLOC_BUILD_VERSION=v2.2.4 -ARROW_MIMALLOC_BUILD_SHA256_CHECKSUM=754a98de5e2912fddbeaf24830f982b4540992f1bab4a0a8796ee118e0752bda +ARROW_MIMALLOC_BUILD_VERSION=v3.0.9 +ARROW_MIMALLOC_BUILD_SHA256_CHECKSUM=689a0d23e6798b257a44bbbedc78491cb3a64e93000f0fa09b7cda90f04d01a5 ARROW_NLOHMANN_JSON_BUILD_VERSION=v3.12.0 ARROW_NLOHMANN_JSON_BUILD_SHA256_CHECKSUM=4b92eb0c06d10683f7447ce9406cb97cd4b453be18d7279320f7b2f025c10187 ARROW_OPENTELEMETRY_BUILD_VERSION=v1.21.0 From 8544e75ec1126c1b4b6637376546a49b836e350d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 17 Sep 2025 17:13:43 +0200 Subject: [PATCH 2/7] Try 3.1.5 instead --- cpp/thirdparty/versions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/thirdparty/versions.txt b/cpp/thirdparty/versions.txt index 682846cd056..7ba1f4f876b 100644 --- a/cpp/thirdparty/versions.txt +++ b/cpp/thirdparty/versions.txt @@ -82,8 +82,8 @@ ARROW_JEMALLOC_BUILD_VERSION=5.3.0 ARROW_JEMALLOC_BUILD_SHA256_CHECKSUM=2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa ARROW_LZ4_BUILD_VERSION=v1.10.0 ARROW_LZ4_BUILD_SHA256_CHECKSUM=537512904744b35e232912055ccf8ec66d768639ff3abe5788d90d792ec5f48b -ARROW_MIMALLOC_BUILD_VERSION=v3.0.9 -ARROW_MIMALLOC_BUILD_SHA256_CHECKSUM=689a0d23e6798b257a44bbbedc78491cb3a64e93000f0fa09b7cda90f04d01a5 +ARROW_MIMALLOC_BUILD_VERSION=v3.1.5 +ARROW_MIMALLOC_BUILD_SHA256_CHECKSUM=1c6949032069d5ebea438ec5cedd602d06f40a92ddf0f0d9dcff0993e5f6635c ARROW_NLOHMANN_JSON_BUILD_VERSION=v3.12.0 ARROW_NLOHMANN_JSON_BUILD_SHA256_CHECKSUM=4b92eb0c06d10683f7447ce9406cb97cd4b453be18d7279320f7b2f025c10187 ARROW_OPENTELEMETRY_BUILD_VERSION=v1.21.0 From 1bae54e24f76ab2ce77a053a62fad62a6d3b86b1 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 18 Sep 2025 15:00:27 +0200 Subject: [PATCH 3/7] Apply temporary patch --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 5 ++++ cpp/cmake_modules/mimalloc-1138.patch | 33 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 cpp/cmake_modules/mimalloc-1138.patch diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index e671055d7bd..432ed756374 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2287,6 +2287,10 @@ if(ARROW_MIMALLOC) set(MIMALLOC_C_FLAGS "${MIMALLOC_C_FLAGS} -DERROR_COMMITMENT_MINIMUM=635") endif() + find_program(PATCH patch REQUIRED) + set(MIMALLOC_PATCH_COMMAND ${PATCH} -p1 -i + ${CMAKE_CURRENT_LIST_DIR}/mimalloc-1138.patch) + set(MIMALLOC_CMAKE_ARGS ${EP_COMMON_CMAKE_ARGS} "-DCMAKE_C_FLAGS=${MIMALLOC_C_FLAGS}" @@ -2304,6 +2308,7 @@ if(ARROW_MIMALLOC) ${EP_COMMON_OPTIONS} URL ${MIMALLOC_SOURCE_URL} URL_HASH "SHA256=${ARROW_MIMALLOC_BUILD_SHA256_CHECKSUM}" + PATCH_COMMAND ${MIMALLOC_PATCH_COMMAND} CMAKE_ARGS ${MIMALLOC_CMAKE_ARGS} BUILD_BYPRODUCTS "${MIMALLOC_STATIC_LIB}") diff --git a/cpp/cmake_modules/mimalloc-1138.patch b/cpp/cmake_modules/mimalloc-1138.patch new file mode 100644 index 00000000000..1ffa4bffbba --- /dev/null +++ b/cpp/cmake_modules/mimalloc-1138.patch @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +Fix for https://github.com/microsoft/mimalloc/issues/1138 + +diff --git a/src/arena.c b/src/arena.c +index b26f4442..d7e99b55 100644 +--- a/src/arena.c ++++ b/src/arena.c +@@ -797,6 +797,9 @@ mi_page_t* _mi_arenas_page_alloc(mi_heap_t* heap, size_t block_size, size_t bloc + else { + page = mi_arenas_page_singleton_alloc(heap, block_size, block_alignment); + } ++ if mi_unlikely(page == NULL) { ++ return NULL; ++ } + // mi_assert_internal(page == NULL || _mi_page_segment(page)->subproc == tld->subproc); + mi_assert_internal(_mi_is_aligned(page, MI_PAGE_ALIGN)); + mi_assert_internal(_mi_ptr_page(page)==page); From 961e5fc1323e68957fb35cb0fb02b7f7dca09bb0 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 18 Sep 2025 15:44:00 +0200 Subject: [PATCH 4/7] Install GNU patch --- ci/conda_env_cpp.txt | 1 + ci/docker/debian-12-cpp.dockerfile | 1 + ci/docker/debian-13-cpp.dockerfile | 1 + ci/docker/debian-experimental-cpp.dockerfile | 1 + ci/docker/fedora-42-cpp.dockerfile | 1 + ci/docker/ubuntu-22.04-cpp-minimal.dockerfile | 1 + ci/docker/ubuntu-22.04-cpp.dockerfile | 1 + ci/docker/ubuntu-24.04-cpp-minimal.dockerfile | 1 + ci/docker/ubuntu-24.04-cpp.dockerfile | 1 + ci/scripts/msys2_setup.sh | 1 + 10 files changed, 10 insertions(+) diff --git a/ci/conda_env_cpp.txt b/ci/conda_env_cpp.txt index 6e23e920a40..52b4cdbba81 100644 --- a/ci/conda_env_cpp.txt +++ b/ci/conda_env_cpp.txt @@ -41,6 +41,7 @@ meson ninja nodejs orc<2.1.0 +patch pkg-config python rapidjson diff --git a/ci/docker/debian-12-cpp.dockerfile b/ci/docker/debian-12-cpp.dockerfile index 15716151fce..44c845bb17e 100644 --- a/ci/docker/debian-12-cpp.dockerfile +++ b/ci/docker/debian-12-cpp.dockerfile @@ -85,6 +85,7 @@ RUN apt-get update -y -q && \ ninja-build \ nlohmann-json3-dev \ npm \ + patch \ pkg-config \ protobuf-compiler-grpc \ python3-dev \ diff --git a/ci/docker/debian-13-cpp.dockerfile b/ci/docker/debian-13-cpp.dockerfile index 3e5c645c81a..ca96b4177ff 100644 --- a/ci/docker/debian-13-cpp.dockerfile +++ b/ci/docker/debian-13-cpp.dockerfile @@ -87,6 +87,7 @@ RUN apt-get update -y -q && \ nlohmann-json3-dev \ npm \ opentelemetry-cpp-dev \ + patch \ pkg-config \ protobuf-compiler-grpc \ python3-dev \ diff --git a/ci/docker/debian-experimental-cpp.dockerfile b/ci/docker/debian-experimental-cpp.dockerfile index 2721b1d5f20..743f5ddd3be 100644 --- a/ci/docker/debian-experimental-cpp.dockerfile +++ b/ci/docker/debian-experimental-cpp.dockerfile @@ -79,6 +79,7 @@ RUN if [ -n "${gcc}" ]; then \ nlohmann-json3-dev \ npm \ opentelemetry-cpp-dev \ + patch \ pkg-config \ protobuf-compiler-grpc \ python3-dev \ diff --git a/ci/docker/fedora-42-cpp.dockerfile b/ci/docker/fedora-42-cpp.dockerfile index 82e3fa9f7aa..cabb066fec3 100644 --- a/ci/docker/fedora-42-cpp.dockerfile +++ b/ci/docker/fedora-42-cpp.dockerfile @@ -53,6 +53,7 @@ RUN dnf update -y && \ make \ ninja-build \ openssl-devel \ + patch \ protobuf-devel \ python \ python-devel \ diff --git a/ci/docker/ubuntu-22.04-cpp-minimal.dockerfile b/ci/docker/ubuntu-22.04-cpp-minimal.dockerfile index 2a90a5637d4..d38dd418e29 100644 --- a/ci/docker/ubuntu-22.04-cpp-minimal.dockerfile +++ b/ci/docker/ubuntu-22.04-cpp-minimal.dockerfile @@ -33,6 +33,7 @@ RUN apt-get update -y -q && \ git \ libssl-dev \ libcurl4-openssl-dev \ + patch \ python3-pip \ python3-venv \ tzdata \ diff --git a/ci/docker/ubuntu-22.04-cpp.dockerfile b/ci/docker/ubuntu-22.04-cpp.dockerfile index 44c1a452c17..88a27efe335 100644 --- a/ci/docker/ubuntu-22.04-cpp.dockerfile +++ b/ci/docker/ubuntu-22.04-cpp.dockerfile @@ -107,6 +107,7 @@ RUN apt-get update -y -q && \ ninja-build \ nlohmann-json3-dev \ npm \ + patch \ pkg-config \ protobuf-compiler \ protobuf-compiler-grpc \ diff --git a/ci/docker/ubuntu-24.04-cpp-minimal.dockerfile b/ci/docker/ubuntu-24.04-cpp-minimal.dockerfile index a1fd178a2c7..5e114d5dcd9 100644 --- a/ci/docker/ubuntu-24.04-cpp-minimal.dockerfile +++ b/ci/docker/ubuntu-24.04-cpp-minimal.dockerfile @@ -33,6 +33,7 @@ RUN apt-get update -y -q && \ git \ libssl-dev \ libcurl4-openssl-dev \ + patch \ python3-pip \ python3-venv \ tzdata \ diff --git a/ci/docker/ubuntu-24.04-cpp.dockerfile b/ci/docker/ubuntu-24.04-cpp.dockerfile index 6bc49a4c842..0347d452d7b 100644 --- a/ci/docker/ubuntu-24.04-cpp.dockerfile +++ b/ci/docker/ubuntu-24.04-cpp.dockerfile @@ -108,6 +108,7 @@ RUN apt-get update -y -q && \ ninja-build \ nlohmann-json3-dev \ npm \ + patch \ pkg-config \ protobuf-compiler \ protobuf-compiler-grpc \ diff --git a/ci/scripts/msys2_setup.sh b/ci/scripts/msys2_setup.sh index 0ce9343a7f7..66c56457fa8 100755 --- a/ci/scripts/msys2_setup.sh +++ b/ci/scripts/msys2_setup.sh @@ -42,6 +42,7 @@ case "${target}" in packages+=("${MINGW_PACKAGE_PREFIX}-lz4") packages+=("${MINGW_PACKAGE_PREFIX}-ninja") packages+=("${MINGW_PACKAGE_PREFIX}-nlohmann-json") + packages+=("${MINGW_PACKAGE_PREFIX}-patch") packages+=("${MINGW_PACKAGE_PREFIX}-protobuf") packages+=("${MINGW_PACKAGE_PREFIX}-rapidjson") packages+=("${MINGW_PACKAGE_PREFIX}-re2") From 30c620f437a12c779fa7f00345db7036235add81 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 7 Oct 2025 11:45:23 +0200 Subject: [PATCH 5/7] try fix for msys2 --- ci/scripts/msys2_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/scripts/msys2_setup.sh b/ci/scripts/msys2_setup.sh index 66c56457fa8..b4634070a87 100755 --- a/ci/scripts/msys2_setup.sh +++ b/ci/scripts/msys2_setup.sh @@ -42,7 +42,6 @@ case "${target}" in packages+=("${MINGW_PACKAGE_PREFIX}-lz4") packages+=("${MINGW_PACKAGE_PREFIX}-ninja") packages+=("${MINGW_PACKAGE_PREFIX}-nlohmann-json") - packages+=("${MINGW_PACKAGE_PREFIX}-patch") packages+=("${MINGW_PACKAGE_PREFIX}-protobuf") packages+=("${MINGW_PACKAGE_PREFIX}-rapidjson") packages+=("${MINGW_PACKAGE_PREFIX}-re2") @@ -52,6 +51,7 @@ case "${target}" in packages+=("${MINGW_PACKAGE_PREFIX}-xsimd") packages+=("${MINGW_PACKAGE_PREFIX}-uriparser") packages+=("${MINGW_PACKAGE_PREFIX}-zstd") + packages+=("patch") if [ "${target}" != "ruby" ]; then # We don't update the exiting packages for Ruby because From 711b7946ab6e0ceaa20dba11d7ed06e8e987e1c1 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 8 Oct 2025 08:50:09 +0200 Subject: [PATCH 6/7] Only require patch for debug builds --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 432ed756374..4ced2a66bf5 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -2287,9 +2287,12 @@ if(ARROW_MIMALLOC) set(MIMALLOC_C_FLAGS "${MIMALLOC_C_FLAGS} -DERROR_COMMITMENT_MINIMUM=635") endif() - find_program(PATCH patch REQUIRED) - set(MIMALLOC_PATCH_COMMAND ${PATCH} -p1 -i - ${CMAKE_CURRENT_LIST_DIR}/mimalloc-1138.patch) + set(MIMALLOC_PATCH_COMMAND "") + if(${UPPERCASE_BUILD_TYPE} STREQUAL "DEBUG") + find_program(PATCH patch REQUIRED) + set(MIMALLOC_PATCH_COMMAND ${PATCH} -p1 -i + ${CMAKE_CURRENT_LIST_DIR}/mimalloc-1138.patch) + endif() set(MIMALLOC_CMAKE_ARGS ${EP_COMMON_CMAKE_ARGS} From 4294e343bec17a6112f436dce3b835325b7ea9da Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 8 Oct 2025 09:43:04 +0200 Subject: [PATCH 7/7] Install patch on Alpine --- ci/docker/alpine-linux-3.22-cpp.dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/docker/alpine-linux-3.22-cpp.dockerfile b/ci/docker/alpine-linux-3.22-cpp.dockerfile index f03e1913e27..48907e61a4a 100644 --- a/ci/docker/alpine-linux-3.22-cpp.dockerfile +++ b/ci/docker/alpine-linux-3.22-cpp.dockerfile @@ -48,6 +48,7 @@ RUN apk add \ musl-locales \ nlohmann-json \ openssl-dev \ + patch \ perl \ pkgconfig \ protobuf-dev \