Commit Graph

7 Commits

Author SHA1 Message Date
Johannes Schindelin
187d1cbfef mimalloc: make MIMALLOC_SHOW_STATS work with redirected stderr
Setting `MIMALLOC_SHOW_STATS` to ask mimalloc to print out something
after the process is done is the easiest way to verify that a
mimalloc-enabled Git is running.

So it better work and not try to write to a Win32 Console when it got a
regular file handle instead or, as is the case in Git for Windows'
regular Git Bash window, an emulated pseudo terminal.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:54 +01:00
Johannes Schindelin
1bd2cc2785 mimalloc: avoid having to link to bcrypt just for mimalloc
Instead, load the `BCryptGenRandom()` function dynamically. When
needed. If needed.

This is necessary because the start-up cost of Git processes spent on
loading dynamic libraries is non-negligible.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:54 +01:00
Johannes Schindelin
2df4366cfb mimalloc: avoid having to link to psapi just for mimalloc
Instead, load the `GetProcessMemoryInfo()` function dynamically. When
needed. If needed.

This is necessary because the start-up cost of Git processes spent on
loading dynamic libraries is non-negligible.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:54 +01:00
Johannes Schindelin
b8ec1289dd mimalloc: avoid %z format
This format is not supported by MSVC runtimes targeted by the MINGW
toolchain.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:54 +01:00
Johannes Schindelin
4f9c99a115 mimalloc: adjust for building inside Git
We want to compile mimalloc's source code as part of Git, rather than
requiring the code to be built as an external library: mimalloc uses a
CMake-based build, which is not necessarily easy to integrate into the
flavors of Git for Windows (which will be the main benefitting port).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:53 +01:00
Johannes Schindelin
87278df177 mimalloc: allow running in Windows Nano Server containers
The `GetNumaProcessorNode()` symbol is not defined in Nano Server's DLLs
(because that function is long deprecated). This caused Git no longer to
work on Nano Server.

Instead of importing it statically, try to import it dynamically, and
fall back gracefully if it cannot be loaded.

This fixes https://github.com/git-for-windows/git/issues/4052

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:53 +01:00
Johannes Schindelin
36d159f5c0 Import the source code of mimalloc
This commit imports mimalloc's source code as per v2.0.6, fetched from
the tag at https://github.com/microsoft/mimalloc.

The .c files are from the src/ subdirectory, and the .h files from the
include/ subdirectory. We will subsequently modify the source code to
accommodate building within Git's context.

Since we plan on using the `mi_*()` family of functions, we skip the
C++-specific source code, some POSIX compliant functions to interact
with mimalloc, and the code that wants to support auto-magic overriding
of the `malloc()` function (mimalloc-new-delete.h, alloc-posix.c,
mimalloc-override.h, alloc-override.c, alloc-override-osx.c,
alloc-override-win.c and static.c).

To appease the `check-whitespace` job of Git's Continuous Integration,
this commit was washed one time via `git rebase --whitespace=fix`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2023-02-07 08:51:53 +01:00