Skip to content

Commit 790ce3f

Browse files
committed
Downgrade mimalloc to 2.2.2
mimalloc 3.0.1 cannot be compiled on Windows, so we don't want to stick with the 2.x series for the time being.
1 parent cbd7f74 commit 790ce3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+7017
-7090
lines changed

third-party/mimalloc/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
build
12
ide/vs20??/*.db
23
ide/vs20??/*.opendb
34
ide/vs20??/*.user
@@ -8,3 +9,5 @@ docs/
89
*.zip
910
*.tar
1011
*.gz
12+
.vscode
13+
.DS_STore

third-party/mimalloc/CMakeLists.txt

+157-105
Large diffs are not rendered by default.

third-party/mimalloc/azure-pipelines.yml

+1-68
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ jobs:
161161
- script: ctest --verbose --timeout 240
162162
workingDirectory: $(BuildType)
163163
displayName: CTest
164+
164165
# - upload: $(Build.SourcesDirectory)/$(BuildType)
165166
# artifact: mimalloc-macos-$(BuildType)
166167

@@ -240,49 +241,6 @@ jobs:
240241
workingDirectory: $(BuildType)
241242
displayName: CTest
242243

243-
- job:
244-
displayName: Ubuntu 20.04
245-
pool:
246-
vmImage:
247-
ubuntu-20.04
248-
strategy:
249-
matrix:
250-
Debug:
251-
CC: gcc
252-
CXX: g++
253-
BuildType: debug
254-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
255-
Debug++:
256-
CC: gcc
257-
CXX: g++
258-
BuildType: debug-cxx
259-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
260-
Debug Clang:
261-
CC: clang
262-
CXX: clang++
263-
BuildType: debug-clang
264-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
265-
Debug++ Clang:
266-
CC: clang
267-
CXX: clang++
268-
BuildType: debug-clang-cxx
269-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
270-
Release Clang:
271-
CC: clang
272-
CXX: clang++
273-
BuildType: release-clang
274-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
275-
steps:
276-
- task: CMake@1
277-
inputs:
278-
workingDirectory: $(BuildType)
279-
cmakeArgs: .. $(cmakeExtraArgs)
280-
- script: make -j$(nproc) -C $(BuildType)
281-
displayName: Make
282-
- script: ctest --verbose --timeout 240
283-
workingDirectory: $(BuildType)
284-
displayName: CTest
285-
286244
- job:
287245
displayName: macOS 15 (Sequoia)
288246
pool:
@@ -306,28 +264,3 @@ jobs:
306264
- script: ctest --verbose --timeout 240
307265
workingDirectory: $(BuildType)
308266
displayName: CTest
309-
310-
- job:
311-
displayName: macOS 13 (Ventura)
312-
pool:
313-
vmImage:
314-
macOS-13
315-
strategy:
316-
matrix:
317-
Debug:
318-
BuildType: debug
319-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
320-
Release:
321-
BuildType: release
322-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
323-
steps:
324-
- task: CMake@1
325-
inputs:
326-
workingDirectory: $(BuildType)
327-
cmakeArgs: .. $(cmakeExtraArgs)
328-
- script: make -j$(sysctl -n hw.ncpu) -C $(BuildType)
329-
displayName: Make
330-
- script: ctest --verbose --timeout 180
331-
workingDirectory: $(BuildType)
332-
displayName: CTest
333-
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
2 KB
Binary file not shown.

third-party/mimalloc/bin/minject.exe

2 KB
Binary file not shown.
1.5 KB
Binary file not shown.

third-party/mimalloc/bin/readme.md

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# Windows Override
22

3-
<span id="override_on_windows">Dynamically overriding on mimalloc on Windows</span>
4-
is robust and has the particular advantage to be able to redirect all malloc/free calls
5-
that go through the (dynamic) C runtime allocator, including those from other DLL's or
6-
libraries. As it intercepts all allocation calls on a low level, it can be used reliably
7-
on large programs that include other 3rd party components.
3+
<span id="override_on_windows">We use a separate redirection DLL to override mimalloc on Windows</span>
4+
such that we redirect all malloc/free calls that go through the (dynamic) C runtime allocator,
5+
including those from other DLL's or libraries. As it intercepts all allocation calls on a low level,
6+
it can be used on large programs that include other 3rd party components.
87
There are four requirements to make the overriding work well:
98

109
1. Use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch).
1110

12-
2. Link your program explicitly with the `mimalloc.lib` export library for
11+
2. Link your program explicitly with the `mimalloc.dll.lib` export library for
1312
the `mimalloc.dll` -- which contains all mimalloc functionality.
1413
To ensure the `mimalloc.dll` is actually loaded at run-time it is easiest
1514
to insert some call to the mimalloc API in the `main` function, like `mi_version()`
@@ -26,6 +25,23 @@ There are four requirements to make the overriding work well:
2625
list of the final executable (so it can intercept all potential allocations).
2726
You can use `minject -l <exe>` to check this if needed.
2827

28+
```csharp
29+
┌──────────────┐
30+
Your Program
31+
└────┬─────────┘
32+
33+
mi_version() ┌───────────────┐ ┌───────────────────────┐
34+
├──────────────►│ mimalloc.dll ├────►│ mimalloc-redirect.dll
35+
│ └──────┬────────┘ └───────────────────────┘
36+
│ ▼
37+
malloc() etc. ┌──────────────┐
38+
├──────────────►│ ucrtbase.dll
39+
│ └──────────────┘
40+
41+
42+
└──────────────► ...
43+
```
44+
2945
For best performance on Windows with C++, it
3046
is also recommended to also override the `new`/`delete` operations (by including
3147
[`mimalloc-new-delete.h`](../include/mimalloc-new-delete.h)

third-party/mimalloc/cmake/mimalloc-config-version.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
set(mi_version_major 3)
2-
set(mi_version_minor 0)
3-
set(mi_version_patch 1)
1+
set(mi_version_major 2)
2+
set(mi_version_minor 2)
3+
set(mi_version_patch 2)
44
set(mi_version ${mi_version_major}.${mi_version_minor})
55

66
set(PACKAGE_VERSION ${mi_version})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
vcpkg_from_github(
2+
OUT_SOURCE_PATH SOURCE_PATH
3+
REPO microsoft/mimalloc
4+
HEAD_REF master
5+
6+
# The "REF" can be a commit hash, branch name (dev2), or a version (v2.2.1).
7+
# REF "v${VERSION}"
8+
REF e2db21e9ba9fb9172b7b0aa0fe9b8742525e8774
9+
10+
# The sha512 is the hash of the tar.gz bundle.
11+
# (To get the sha512, run `vcpkg install mimalloc[override] --overlay-ports=<dir of this file>` and copy the sha from the error message.)
12+
SHA512 8cbb601fdf8b46dd6a9c0d314d6da9d4960699853829e96d2470753867f90689fb4caeaf30d628943fd388670dc11902dbecc9cc7c329b99a510524a09bdb612
13+
)
14+
15+
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
16+
FEATURES
17+
c MI_NO_USE_CXX
18+
guarded MI_GUARDED
19+
secure MI_SECURE
20+
override MI_OVERRIDE
21+
optarch MI_OPT_ARCH
22+
optsimd MI_OPT_SIMD
23+
xmalloc MI_XMALLOC
24+
asm MI_SEE_ASM
25+
)
26+
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" MI_BUILD_STATIC)
27+
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" MI_BUILD_SHARED)
28+
29+
vcpkg_cmake_configure(
30+
SOURCE_PATH "${SOURCE_PATH}"
31+
OPTIONS
32+
-DMI_USE_CXX=ON
33+
-DMI_BUILD_TESTS=OFF
34+
-DMI_BUILD_OBJECT=ON
35+
-DMI_BUILD_STATIC=${MI_BUILD_STATIC}
36+
-DMI_BUILD_SHARED=${MI_BUILD_SHARED}
37+
-DMI_INSTALL_TOPLEVEL=ON
38+
${FEATURE_OPTIONS}
39+
)
40+
41+
vcpkg_cmake_install()
42+
vcpkg_copy_pdbs()
43+
44+
file(COPY
45+
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake"
46+
"${CMAKE_CURRENT_LIST_DIR}/usage"
47+
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
48+
)
49+
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/mimalloc)
50+
51+
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
52+
# todo: why is this needed?
53+
vcpkg_replace_string(
54+
"${CURRENT_PACKAGES_DIR}/include/mimalloc.h"
55+
"!defined(MI_SHARED_LIB)"
56+
"0 // !defined(MI_SHARED_LIB)"
57+
)
58+
endif()
59+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
60+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
61+
62+
vcpkg_fixup_pkgconfig()
63+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Vcpkg support
2+
3+
This directory is meant to provide the sources for the official [vcpkg port]
4+
of mimalloc, but can also be used to override the official port with
5+
your own variant.
6+
7+
For example, you can edit the [`portfile.cmake`](portfile.cmake)
8+
to check out a specific commit, version, or branch of mimalloc, or set further options.
9+
You can install such custom port as:
10+
11+
```sh
12+
$ vcpkg install "mimalloc[override]" --recurse --overlay-ports=./contrib/vcpkg
13+
```
14+
15+
This will also show the correct sha512 hash if you use a custom version.
16+
Another way is to refer to the overlay from the [vcpkg-configuration.json](https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-configuration-json) file.
17+
See also the vcpkg [documentation](https://learn.microsoft.com/en-us/vcpkg/produce/update-package-version) for more information.
18+
19+
20+
# Using mimalloc from vcpkg
21+
22+
When using [cmake with vcpkg](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-powershell),
23+
you can use mimalloc from the `CMakeLists.txt` as:
24+
25+
```cmake
26+
find_package(mimalloc CONFIG REQUIRED)
27+
target_link_libraries(main PRIVATE mimalloc)
28+
```
29+
30+
See [`test/CMakeLists.txt](../../test/CMakeLists.txt) for more examples.
31+
32+
33+
# Acknowledgements
34+
35+
The original port for vckpg was contributed by many people, including: @vicroms, @myd7349, @PhoubeHui, @LilyWangL,
36+
@JonLiu1993, @RT2Code, Remy Tassoux, @wangao, @BillyONeal, @jiayuehua, @dg0yt, @gerar-ryan-immersaview, @nickdademo,
37+
and @jimwang118 -- Thank you so much!
38+
39+
40+
[vcpkg port]: https://github.com/microsoft/vcpkg/tree/master/ports/mimalloc
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Use the following CMake targets to import mimalloc:
2+
3+
find_package(mimalloc CONFIG REQUIRED)
4+
target_link_libraries(main PRIVATE mimalloc)
5+
6+
And use mimalloc in your sources as:
7+
8+
#include <mimalloc.h>
9+
#include <stdio.h>
10+
int main(int argc, char** argv) {
11+
int* p = mi_malloc_tp(int);
12+
*p = mi_version();
13+
printf("mimalloc version: %d\n", *p);
14+
mi_free(p);
15+
return 0;
16+
}
17+
18+
When dynamically overriding on Windows, ensure `mimalloc.dll` is linked through some call to
19+
mimalloc (e.g. `mi_version()`), and that the `mimalloc-redirect.dll` is in the same directory.
20+
See https://github.com/microsoft/mimalloc/blob/dev/bin/readme.md for detailed information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
_find_package(${ARGS})
2+
3+
if(CMAKE_CURRENT_LIST_DIR STREQUAL "${MIMALLOC_CMAKE_DIR}/${MIMALLOC_VERSION_DIR}")
4+
set(MIMALLOC_INCLUDE_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
5+
# As in vcpkg.cmake
6+
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$")
7+
set(MIMALLOC_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib")
8+
else()
9+
set(MIMALLOC_LIBRARY_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib")
10+
endif()
11+
set(MIMALLOC_OBJECT_DIR "${MIMALLOC_LIBRARY_DIR}")
12+
set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}")
13+
endif()
14+
15+
# vcpkg always configures either a static or dynamic library.
16+
# ensure to always expose the mimalloc target as either the static or dynamic build.
17+
if(TARGET mimalloc-static AND NOT TARGET mimalloc)
18+
add_library(mimalloc INTERFACE IMPORTED)
19+
set_target_properties(mimalloc PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc-static)
20+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "mimalloc",
3+
"version": "2.2.2",
4+
"port-version": 1,
5+
"description": "Compact general purpose allocator with excellent performance",
6+
"homepage": "https://github.com/microsoft/mimalloc",
7+
"license": "MIT",
8+
"supports": "!uwp",
9+
"dependencies": [
10+
{
11+
"name": "vcpkg-cmake",
12+
"host": true
13+
},
14+
{
15+
"name": "vcpkg-cmake-config",
16+
"host": true
17+
}
18+
],
19+
"features": {
20+
"c": {
21+
"description": "Use C11 compilation (this can still override new/delete)"
22+
},
23+
"override": {
24+
"description": "Override the standard malloc/free interface"
25+
},
26+
"secure": {
27+
"description": "Use full security mitigations (like guard pages and randomization)"
28+
},
29+
"guarded": {
30+
"description": "Use build that support guard pages after objects controlled with MIMALLOC_GUARDED_SAMPLE_RATE"
31+
},
32+
"xmalloc": {
33+
"description": "If out-of-memory, call abort() instead of returning NULL"
34+
},
35+
"optarch": {
36+
"description": "Use architecture specific optimizations (on x64: '-march=haswell;-mavx2', on arm64: '-march=armv8.1-a')"
37+
},
38+
"optsimd": {
39+
"description": "Allow use of SIMD instructions (avx2 or neon) (requires 'optarch' to be enabled)"
40+
},
41+
"asm": {
42+
"description": "Generate assembly files"
43+
}
44+
}
45+
}

third-party/mimalloc/doc/mimalloc-doc.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,12 @@ int mi_reserve_os_memory(size_t size, bool commit, bool allow_large);
431431
/// @param start Start of the memory area
432432
/// @param size The size of the memory area.
433433
/// @param is_committed Is the area already committed?
434-
/// @param is_pinned Can the memory not be decommitted or reset? (usually the case for large OS pages)
434+
/// @param is_large Does it consist of large OS pages? Set this to \a true as well for memory
435+
/// that should not be decommitted or protected (like rdma etc.)
435436
/// @param is_zero Does the area consists of zero's?
436437
/// @param numa_node Possible associated numa node or `-1`.
437438
/// @return \a true if successful, and \a false on error.
438-
bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node);
439+
bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node);
439440

440441
/// Reserve \a pages of huge OS pages (1GiB) evenly divided over \a numa_nodes nodes,
441442
/// but stops after at most `timeout_msecs` seconds.

0 commit comments

Comments
 (0)