From cbccbbe9a4614ee25407a6b4a50cda5df6a2461e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 18 Mar 2023 11:11:49 +0000 Subject: [PATCH 1/8] c++ override test new placement operator --- test/main-override.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/main-override.cpp b/test/main-override.cpp index db96efb1..5e4eed6a 100644 --- a/test/main-override.cpp +++ b/test/main-override.cpp @@ -95,6 +95,10 @@ static void various_tests() { delete t; t = new (std::nothrow) Test(42); delete t; + auto tbuf = new unsigned char[sizeof(Test)]; + t = new (tbuf) Test(42); + t->~Test(); + delete tbuf; } class Static { @@ -298,4 +302,4 @@ static void tsan_numa_test() { auto t1 = std::thread(dummy_worker); dummy_worker(); t1.join(); -} \ No newline at end of file +} From f20d22a3e42e14258dc33f7653bfd20bc9c990e1 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 29 Mar 2023 15:53:05 -0700 Subject: [PATCH 2/8] fix arm compilation (PR 694) --- src/prim/unix/prim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index 189631f0..a9fc9134 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -759,7 +759,7 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) { ssize_t ret = syscall(SYS_getrandom, buf, buf_len, GRND_NONBLOCK); if (ret >= 0) return (buf_len == (size_t)ret); if (errno != ENOSYS) return false; - mi_atomic_store_release(&no_getrandom, 1UL); // don't call again, and fall back to /dev/urandom + mi_atomic_store_release(&no_getrandom, (uintptr_t)1); // don't call again, and fall back to /dev/urandom } #endif int flags = O_RDONLY; From 61a32e62b827182f5c3b2bb694e82fb0328a7c88 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 29 Mar 2023 15:56:31 -0700 Subject: [PATCH 3/8] support cygwin compilation (pr #712) --- src/prim/unix/prim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index a9fc9134..608e96ce 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -50,7 +50,7 @@ terms of the MIT license. A copy of the license can be found in the file #include #endif -#if !defined(__HAIKU__) && !defined(__APPLE__) +#if !defined(__HAIKU__) && !defined(__APPLE__) && !defined(__CYGWIN__) #define MI_HAS_SYSCALL_H #include #endif @@ -410,7 +410,7 @@ int _mi_prim_protect(void* start, size_t size, bool protect) { // Huge page allocation //--------------------------------------------- -#if (MI_INTPTR_SIZE >= 8) && !defined(__HAIKU__) +#if (MI_INTPTR_SIZE >= 8) && !defined(__HAIKU__) && !defined(__CYGWIN__) #ifndef MPOL_PREFERRED #define MPOL_PREFERRED 1 From c2a2533fba6fa08449d2831cef818accd7c15256 Mon Sep 17 00:00:00 2001 From: Daan Date: Wed, 29 Mar 2023 16:02:46 -0700 Subject: [PATCH 4/8] fix haiku compilation (pr #679) --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7ea6efa..4957ee7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,6 +262,11 @@ if(MI_USE_CXX) endif() endif() +if(CMAKE_SYSTEM_NAME MATCHES "Haiku") + SET(CMAKE_INSTALL_LIBDIR ~/config/non-packaged/lib) + SET(CMAKE_INSTALL_INCLUDEDIR ~/config/non-packaged/headers) + endif() + # Compiler flags if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU") list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden) From dd7b99d477c4a92c8e27f86cbfe660849995f242 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 29 Mar 2023 16:10:01 -0700 Subject: [PATCH 5/8] apply some spelling fixes from PR #710 --- doc/mimalloc-doc.h | 2 +- docs/build.html | 2 +- src/init.c | 2 +- src/prim/unix/prim.c | 2 +- test/test-stress.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/mimalloc-doc.h b/doc/mimalloc-doc.h index 9525c9ea..4c23a5fa 100644 --- a/doc/mimalloc-doc.h +++ b/doc/mimalloc-doc.h @@ -927,7 +927,7 @@ template struct mi_stl_allocator { } /*! \page build Building -Checkout the sources from Github: +Checkout the sources from GitHub: ``` git clone https://github.com/microsoft/mimalloc ``` diff --git a/docs/build.html b/docs/build.html index eac5392b..41e0199f 100644 --- a/docs/build.html +++ b/docs/build.html @@ -98,7 +98,7 @@ $(document).ready(function(){initNavTree('build.html',''); initResizable(); });
Building
-

Checkout the sources from Github:

git clone https://github.com/microsoft/mimalloc
+

Checkout the sources from GitHub:

git clone https://github.com/microsoft/mimalloc

Windows

Open ide/vs2019/mimalloc.sln in Visual Studio 2019 and build (or ide/vs2017/mimalloc.sln). The mimalloc project builds a static library (in out/msvc-x64), while the mimalloc-override project builds a DLL for overriding malloc in the entire program.

macOS, Linux, BSD, etc.

diff --git a/src/init.c b/src/init.c index 565cffd9..38f62f65 100644 --- a/src/init.c +++ b/src/init.c @@ -507,7 +507,7 @@ static void mi_detect_cpu_features(void) { // FSRM for fast rep movsb support (AMD Zen3+ (~2020) or Intel Ice Lake+ (~2017)) int32_t cpu_info[4]; __cpuid(cpu_info, 7); - _mi_cpu_has_fsrm = ((cpu_info[3] & (1 << 4)) != 0); // bit 4 of EDX : see + _mi_cpu_has_fsrm = ((cpu_info[3] & (1 << 4)) != 0); // bit 4 of EDX : see } #else static void mi_detect_cpu_features(void) { diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index 608e96ce..c12e4c0d 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -652,7 +652,7 @@ void _mi_prim_out_stderr( const char* msg ) { //---------------------------------------------------------------- #if !defined(MI_USE_ENVIRON) || (MI_USE_ENVIRON!=0) -// On Posix systemsr use `environ` to acces environment variables +// On Posix systemsr use `environ` to access environment variables // even before the C runtime is initialized. #if defined(__APPLE__) && defined(__has_include) && __has_include() #include diff --git a/test/test-stress.c b/test/test-stress.c index 87e41736..f253000f 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -7,7 +7,7 @@ terms of the MIT license. /* This is a stress test for the allocator, using multiple threads and transferring objects between threads. It tries to reflect real-world workloads: - allocation size is distributed linearly in powers of two - - with some fraction extra large (and some extra extra large) + - with some fraction extra large (and some very large) - the allocations are initialized and read again at free - pointers transfer between threads - threads are terminated and recreated with some objects surviving in between From f806eb84984b4a64de5ffaba4b931b0dcb2b72a6 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 29 Mar 2023 16:15:20 -0700 Subject: [PATCH 6/8] remove redundant OR in mmap flags (pr #675) --- src/prim/unix/prim.c | 1 - src/segment.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index c12e4c0d..077bf820 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -166,7 +166,6 @@ static void* unix_mmap_prim(void* addr, size_t size, size_t try_alignment, int p if (addr == NULL && try_alignment > 1 && (try_alignment % _mi_os_page_size()) == 0) { size_t n = mi_bsr(try_alignment); if (((size_t)1 << n) == try_alignment && n >= 12 && n <= 30) { // alignment is a power of 2 and 4096 <= alignment <= 1GiB - flags |= MAP_ALIGNED(n); p = mmap(addr, size, protect_flags, flags | MAP_ALIGNED(n), fd, 0); if (p==MAP_FAILED || !_mi_is_aligned(p,try_alignment)) { int err = errno; diff --git a/src/segment.c b/src/segment.c index 8a9c8fe1..ae15847c 100644 --- a/src/segment.c +++ b/src/segment.c @@ -771,7 +771,7 @@ We maintain a global list of abandoned segments that are reclaimed on demand. Since this is shared among threads the implementation needs to avoid the A-B-A problem on popping abandoned segments: -We use tagged pointers to avoid accidentially identifying +We use tagged pointers to avoid accidentally identifying reused segments, much like stamped references in Java. Secondly, we maintain a reader counter to avoid resetting or decommitting segments that have a pending read operation. From accdc4de708b724a8fad414f4b9a6e3a1c7ed19d Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 29 Mar 2023 16:17:10 -0700 Subject: [PATCH 7/8] fix MI_SKIP_COLLECT_ON_EXIT syntax (pr #671 by @Unsttopabull) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4957ee7b..9550f77f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ option(MI_BUILD_OBJECT "Build object library" ON) option(MI_BUILD_TESTS "Build test executables" ON) option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF) option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF) -option(MI_SKIP_COLLECT_ON_EXIT, "Skip collecting memory on program exit" OFF) +option(MI_SKIP_COLLECT_ON_EXIT "Skip collecting memory on program exit" OFF) option(MI_NO_PADDING "Force no use of padding even in DEBUG mode etc." OFF) # deprecated options From 06b94fc5e6cb8a01facc4cf0d917b1a8b0b5db89 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 29 Mar 2023 16:19:07 -0700 Subject: [PATCH 8/8] remove redundant code (pr #674 by @rganesan) --- src/heap.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/heap.c b/src/heap.c index 0c372c5b..84b0ec4f 100644 --- a/src/heap.c +++ b/src/heap.c @@ -226,9 +226,6 @@ static void mi_heap_reset_pages(mi_heap_t* heap) { mi_assert_internal(mi_heap_is_initialized(heap)); // TODO: copy full empty heap instead? memset(&heap->pages_free_direct, 0, sizeof(heap->pages_free_direct)); -#ifdef MI_MEDIUM_DIRECT - memset(&heap->pages_free_medium, 0, sizeof(heap->pages_free_medium)); -#endif _mi_memcpy_aligned(&heap->pages, &_mi_heap_empty.pages, sizeof(heap->pages)); heap->thread_delayed_free = NULL; heap->page_count = 0;