Skip to content

Commit 5ea5d71

Browse files
committed
Merge remote-tracking branch 'upstream/dev3' into dev3
2 parents 5ccfbe1 + 8630419 commit 5ea5d71

26 files changed

+978
-497
lines changed

CMakeLists.txt

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.18)
2-
project(libmimalloc C CXX)
2+
project(libmimalloc C)
33

44
set(CMAKE_C_STANDARD 11)
55
set(CMAKE_CXX_STANDARD 17)
@@ -147,21 +147,43 @@ message(STATUS "Architecture: ${MI_ARCH}") # (${CMAKE_SYSTEM_PROCESSOR}, ${CMAKE
147147
if(MI_NO_USE_CXX)
148148
set(MI_USE_CXX "OFF")
149149
endif()
150+
150151
if(MI_NO_OPT_ARCH)
151152
set(MI_OPT_ARCH "OFF")
152153
elseif(MI_ARCH STREQUAL "arm64")
153154
set(MI_OPT_ARCH "ON") # enable armv8.1-a by default on arm64 unless MI_NO_OPT_ARCH is set
154155
endif()
155156

156-
157157
# -----------------------------------------------------------------------------
158-
# Process options
158+
# Enable the C++ compiler early on if needed
159159
# -----------------------------------------------------------------------------
160160

161-
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
161+
# clang-cl detection on windows
162+
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
162163
set(MI_CLANG_CL "ON")
163164
endif()
164165

166+
# force C++ compilation with msvc or clang-cl to use modern C++ atomics
167+
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR MI_CLANG_CL)
168+
set(MI_USE_CXX "ON")
169+
elseif(MI_DEBUG_UBSAN AND CMAKE_BUILD_TYPE MATCHES "Debug") # ubsan needs C++
170+
set(MI_USE_CXX "ON")
171+
endif()
172+
173+
# enable C++ ?
174+
if(MI_USE_CXX)
175+
enable_language(CXX)
176+
message(STATUS "Use the C++ compiler to compile (MI_USE_CXX=ON)")
177+
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
178+
list(APPEND mi_cflags -Kc++)
179+
endif()
180+
endif()
181+
182+
183+
# -----------------------------------------------------------------------------
184+
# Process options
185+
# -----------------------------------------------------------------------------
186+
165187
# put -Wall early so other warnings can be disabled selectively
166188
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
167189
if (MI_CLANG_CL)
@@ -177,9 +199,8 @@ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
177199
list(APPEND mi_cflags -Wall)
178200
endif()
179201

180-
# force C++ compilation with msvc or clang-cl to use modern C++ atomics
181-
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR MI_CLANG_CL)
182-
set(MI_USE_CXX "ON")
202+
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
203+
list(APPEND mi_cflags -Wno-deprecated)
183204
endif()
184205

185206
if(MI_OVERRIDE)
@@ -188,7 +209,7 @@ if(MI_OVERRIDE)
188209
if(MI_OSX_ZONE)
189210
# use zone's on macOS
190211
message(STATUS " Use malloc zone to override malloc (MI_OSX_ZONE=ON)")
191-
list(APPEND mi_sources src/prim/osx/alloc-override-zone.c)
212+
list(APPEND mi_sources src/prim/osx/alloc-override-zone.c)
192213
list(APPEND mi_defines MI_OSX_ZONE=1)
193214
if (NOT MI_OSX_INTERPOSE)
194215
message(STATUS " WARNING: zone overriding usually also needs interpose (use -DMI_OSX_INTERPOSE=ON)")
@@ -199,7 +220,7 @@ if(MI_OVERRIDE)
199220
message(STATUS " Use interpose to override malloc (MI_OSX_INTERPOSE=ON)")
200221
list(APPEND mi_defines MI_OSX_INTERPOSE=1)
201222
if (NOT MI_OSX_ZONE)
202-
message(STATUS " WARNING: interpose usually also needs zone overriding (use -DMI_OSX_INTERPOSE=ON)")
223+
message(STATUS " WARNING: interpose usually also needs zone overriding (use -DMI_OSX_ZONE=ON)")
203224
endif()
204225
endif()
205226
if(MI_USE_CXX AND MI_OSX_INTERPOSE)
@@ -336,36 +357,24 @@ if(MI_DEBUG_TSAN)
336357
endif()
337358

338359
if(MI_DEBUG_UBSAN)
339-
if(CMAKE_BUILD_TYPE MATCHES "Debug")
340-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
341-
message(STATUS "Build with undefined-behavior sanitizer (MI_DEBUG_UBSAN=ON)")
342-
list(APPEND mi_defines MI_UBSAN=1)
343-
list(APPEND mi_cflags -fsanitize=undefined -g -fno-sanitize-recover=undefined)
344-
list(APPEND mi_libraries -fsanitize=undefined)
345-
if (NOT MI_USE_CXX)
346-
message(STATUS "(switch to use C++ due to MI_DEBUG_UBSAN)")
347-
set(MI_USE_CXX "ON")
360+
if(CMAKE_BUILD_TYPE MATCHES "Debug")
361+
if(MI_USE_CXX)
362+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
363+
message(STATUS "Build with undefined-behavior sanitizer (MI_DEBUG_UBSAN=ON)")
364+
list(APPEND mi_defines MI_UBSAN=1)
365+
list(APPEND mi_cflags -fsanitize=undefined -g -fno-sanitize-recover=undefined)
366+
list(APPEND mi_libraries -fsanitize=undefined)
367+
else()
368+
message(WARNING "Can only use undefined-behavior sanitizer with clang++ (MI_DEBUG_UBSAN=ON but ignored)")
348369
endif()
349370
else()
350-
message(WARNING "Can only use undefined-behavior sanitizer with clang++ (MI_DEBUG_UBSAN=ON but ignored)")
371+
message(WARNING "Can only use undefined-behavior sanitizer with a C++ build (MI_USE_CXX=ON)")
351372
endif()
352373
else()
353374
message(WARNING "Can only use undefined-behavior sanitizer with a debug build (CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})")
354375
endif()
355376
endif()
356377

357-
if(MI_USE_CXX)
358-
message(STATUS "Use the C++ compiler to compile (MI_USE_CXX=ON)")
359-
set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX )
360-
set_source_files_properties(src/static.c test/test-api.c test/test-api-fill test/test-stress PROPERTIES LANGUAGE CXX )
361-
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
362-
list(APPEND mi_cflags -Wno-deprecated)
363-
endif()
364-
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
365-
list(APPEND mi_cflags -Kc++)
366-
endif()
367-
endif()
368-
369378
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
370379
if(MI_NO_THP)
371380
message(STATUS "Disable transparent huge pages support (MI_NO_THP=ON)")
@@ -522,6 +531,12 @@ else()
522531
endif()
523532
endif()
524533

534+
# set language for source files now
535+
if(MI_USE_CXX)
536+
set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX )
537+
set_source_files_properties(src/static.c test/test-api.c test/test-api-fill test/test-stress PROPERTIES LANGUAGE CXX )
538+
endif()
539+
525540

526541
# -----------------------------------------------------------------------------
527542
# Install and output names
@@ -755,6 +770,7 @@ if (MI_BUILD_TESTS)
755770
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # link mi_version
756771
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
757772
else()
773+
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE ${mi_libraries}) # pthreads, issue 1158
758774
if(APPLE)
759775
set(LD_PRELOAD "DYLD_INSERT_LIBRARIES")
760776
else()

azure-pipelines.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,3 @@ jobs:
260260
- script: ctest --verbose --timeout 240
261261
workingDirectory: $(BuildType)
262262
displayName: CTest
263-
264-
- job:
265-
displayName: macOS 13 (Ventura)
266-
pool:
267-
vmImage:
268-
macOS-13
269-
strategy:
270-
matrix:
271-
Debug:
272-
BuildType: debug
273-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
274-
Release:
275-
BuildType: release
276-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
277-
steps:
278-
- task: CMake@1
279-
inputs:
280-
workingDirectory: $(BuildType)
281-
cmakeArgs: .. $(cmakeExtraArgs)
282-
- script: make -j$(sysctl -n hw.ncpu) -C $(BuildType)
283-
displayName: Make
284-
- script: ctest --verbose --timeout 180
285-
workingDirectory: $(BuildType)
286-
displayName: CTest
287-

ide/vs2022/mimalloc-override-test.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@
256256
<AdditionalIncludeDirectories>..\..\include</AdditionalIncludeDirectories>
257257
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
258258
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
259+
<LanguageStandard>Default</LanguageStandard>
259260
</ClCompile>
260261
<Link>
261262
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -279,6 +280,7 @@
279280
<AdditionalIncludeDirectories>..\..\include</AdditionalIncludeDirectories>
280281
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
281282
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
283+
<LanguageStandard>Default</LanguageStandard>
282284
</ClCompile>
283285
<Link>
284286
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -304,6 +306,7 @@
304306
<AdditionalIncludeDirectories>..\..\include</AdditionalIncludeDirectories>
305307
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
306308
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
309+
<LanguageStandard>Default</LanguageStandard>
307310
</ClCompile>
308311
<Link>
309312
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -329,6 +332,7 @@
329332
<AdditionalIncludeDirectories>..\..\include</AdditionalIncludeDirectories>
330333
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);NDEBUG</PreprocessorDefinitions>
331334
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
335+
<LanguageStandard>Default</LanguageStandard>
332336
</ClCompile>
333337
<Link>
334338
<EnableCOMDATFolding>true</EnableCOMDATFolding>

include/mimalloc-stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef enum mi_chunkbin_e {
7171
MI_CBIN_OTHER, // slice_count: any other from the other bins, and 1 <= slice_count <= MI_BCHUNK_BITS
7272
MI_CBIN_MEDIUM, // slice_count == 8
7373
MI_CBIN_LARGE, // slice_count == MI_SIZE_BITS (only used if MI_ENABLE_LARGE_PAGES is 1)
74+
MI_CBIN_HUGE, // slice_count > MI_BCHUNK_BITS
7475
MI_CBIN_NONE, // no bin assigned yet (the chunk is completely free)
7576
MI_CBIN_COUNT
7677
} mi_chunkbin_t;

include/mimalloc.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ mi_decl_nodiscard mi_decl_export void* mi_realloc_aligned(void* p, size_t newsiz
184184
mi_decl_nodiscard mi_decl_export void* mi_realloc_aligned_at(void* p, size_t newsize, size_t alignment, size_t offset) mi_attr_noexcept mi_attr_alloc_size(2);
185185

186186

187+
// -----------------------------------------------------------------
188+
// Return allocated block size (if the return value is not NULL)
189+
// -----------------------------------------------------------------
190+
191+
mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_umalloc(size_t size, size_t* block_size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(1);
192+
mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_ucalloc(size_t count, size_t size, size_t* block_size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size2(1,2);
193+
mi_decl_nodiscard mi_decl_export void* mi_urealloc(void* p, size_t newsize, size_t* block_size_pre, size_t* block_size_post) mi_attr_noexcept mi_attr_alloc_size(2);
194+
mi_decl_export void mi_ufree(void* p, size_t* block_size) mi_attr_noexcept;
195+
196+
mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_umalloc_aligned(size_t size, size_t alignment, size_t* block_size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(1) mi_attr_alloc_align(2);
197+
mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_uzalloc_aligned(size_t size, size_t alignment, size_t* block_size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(1) mi_attr_alloc_align(2);
198+
199+
mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_umalloc_small(size_t size, size_t* block_size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(1);
200+
mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_uzalloc_small(size_t size, size_t* block_size) mi_attr_noexcept mi_attr_malloc mi_attr_alloc_size(1);
201+
202+
187203
// -------------------------------------------------------------------------------------
188204
// Heaps: first-class, but can only allocate from the same thread that created it.
189205
// -------------------------------------------------------------------------------------
@@ -380,7 +396,7 @@ typedef enum mi_option_e {
380396
mi_option_eager_commit, // eager commit segments? (after `eager_commit_delay` segments) (=1)
381397
mi_option_arena_eager_commit, // eager commit arenas? Use 2 to enable just on overcommit systems (=2)
382398
mi_option_purge_decommits, // should a memory purge decommit? (=1). Set to 0 to use memory reset on a purge (instead of decommit)
383-
mi_option_allow_large_os_pages, // allow large (2 or 4 MiB) OS pages, implies eager commit. If false, also disables THP for the process.
399+
mi_option_allow_large_os_pages, // allow use of large (2 or 4 MiB) OS pages, implies eager commit.
384400
mi_option_reserve_huge_os_pages, // reserve N huge OS pages (1GiB pages) at startup
385401
mi_option_reserve_huge_os_pages_at, // reserve huge OS pages at a specific NUMA node
386402
mi_option_reserve_os_memory, // reserve specified amount of OS memory in an arena at startup (internally, this value is in KiB; use `mi_option_get_size`)
@@ -417,6 +433,8 @@ typedef enum mi_option_e {
417433
mi_option_page_commit_on_demand, // commit page memory on-demand
418434
mi_option_page_max_reclaim, // don't reclaim pages of the same originating heap if we already own N pages (in that size class) (=-1 (unlimited))
419435
mi_option_page_cross_thread_max_reclaim, // don't reclaim pages across threads if we already own N pages (in that size class) (=16)
436+
mi_option_allow_thp, // allow transparent huge pages? (=1) (on Android =0 by default). Set to 0 to disable THP for the process.
437+
mi_option_minimal_purge_size, // set minimal purge size (in KiB) (=0). By default set to either 64 or 2048 if THP is enabled.
420438
_mi_option_last,
421439
// legacy option names
422440
mi_option_large_os_pages = mi_option_allow_large_os_pages,

include/mimalloc/internal.h

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void _mi_strlcpy(char* dest, const char* src, size_t dest_size);
126126
void _mi_strlcat(char* dest, const char* src, size_t dest_size);
127127
size_t _mi_strlen(const char* s);
128128
size_t _mi_strnlen(const char* s, size_t max_len);
129+
char* _mi_strnstr(char* s, size_t max_len, const char* pat);
129130
bool _mi_getenv(const char* name, char* result, size_t result_size);
130131

131132
// "options.c"
@@ -184,6 +185,7 @@ size_t _mi_os_good_alloc_size(size_t size);
184185
bool _mi_os_has_overcommit(void);
185186
bool _mi_os_has_virtual_reserve(void);
186187
size_t _mi_os_virtual_address_bits(void);
188+
size_t _mi_os_minimal_purge_size(void);
187189

188190
bool _mi_os_reset(void* addr, size_t size);
189191
bool _mi_os_decommit(void* addr, size_t size);
@@ -208,7 +210,7 @@ void* _mi_os_alloc_aligned(size_t size, size_t alignment, bool commit, b
208210
void* _mi_os_alloc_aligned_at_offset(size_t size, size_t alignment, size_t align_offset, bool commit, bool allow_large, mi_memid_t* memid);
209211

210212
void* _mi_os_get_aligned_hint(size_t try_alignment, size_t size);
211-
bool _mi_os_use_large_page(size_t size, size_t alignment);
213+
bool _mi_os_canuse_large_page(size_t size, size_t alignment);
212214
size_t _mi_os_large_page_size(void);
213215
void* _mi_os_alloc_huge_os_pages(size_t pages, int numa_node, mi_msecs_t max_secs, size_t* pages_reserved, size_t* psize, mi_memid_t* memid);
214216

@@ -245,7 +247,7 @@ mi_page_t* _mi_safe_ptr_page(const void* p);
245247
void _mi_page_map_unsafe_destroy(mi_subproc_t* subproc);
246248

247249
// "page.c"
248-
void* _mi_malloc_generic(mi_heap_t* heap, size_t size, bool zero, size_t huge_alignment) mi_attr_noexcept mi_attr_malloc;
250+
void* _mi_malloc_generic(mi_heap_t* heap, size_t size, bool zero, size_t huge_alignment, size_t* usable) mi_attr_noexcept mi_attr_malloc;
249251

250252
void _mi_page_retire(mi_page_t* page) mi_attr_noexcept; // free the page if there are no other pages with many free blocks
251253
void _mi_page_unfull(mi_page_t* page);
@@ -289,12 +291,12 @@ mi_msecs_t _mi_clock_end(mi_msecs_t start);
289291
mi_msecs_t _mi_clock_start(void);
290292

291293
// "alloc.c"
292-
void* _mi_page_malloc_zero(mi_heap_t* heap, mi_page_t* page, size_t size, bool zero) mi_attr_noexcept; // called from `_mi_malloc_generic`
294+
void* _mi_page_malloc_zero(mi_heap_t* heap, mi_page_t* page, size_t size, bool zero, size_t* usable) mi_attr_noexcept; // called from `_mi_malloc_generic`
293295
void* _mi_page_malloc(mi_heap_t* heap, mi_page_t* page, size_t size) mi_attr_noexcept; // called from `_mi_heap_malloc_aligned`
294296
void* _mi_page_malloc_zeroed(mi_heap_t* heap, mi_page_t* page, size_t size) mi_attr_noexcept; // called from `_mi_heap_malloc_aligned`
295297
void* _mi_heap_malloc_zero(mi_heap_t* heap, size_t size, bool zero) mi_attr_noexcept;
296-
void* _mi_heap_malloc_zero_ex(mi_heap_t* heap, size_t size, bool zero, size_t huge_alignment) mi_attr_noexcept; // called from `_mi_heap_malloc_aligned`
297-
void* _mi_heap_realloc_zero(mi_heap_t* heap, void* p, size_t newsize, bool zero) mi_attr_noexcept;
298+
void* _mi_heap_malloc_zero_ex(mi_heap_t* heap, size_t size, bool zero, size_t huge_alignment, size_t* usable) mi_attr_noexcept; // called from `_mi_heap_malloc_aligned`
299+
void* _mi_heap_realloc_zero(mi_heap_t* heap, void* p, size_t newsize, bool zero, size_t* usable_pre, size_t* usable_post) mi_attr_noexcept;
298300
mi_block_t* _mi_page_ptr_unalign(const mi_page_t* page, const void* p);
299301
void _mi_padding_shrink(const mi_page_t* page, const mi_block_t* block, const size_t min_size);
300302

@@ -814,7 +816,7 @@ static inline void mi_page_set_heap(mi_page_t* page, mi_heap_t* heap) {
814816
}
815817
const mi_threadid_t tid = (heap == NULL ? MI_THREADID_ABANDONED : heap->tld->thread_id);
816818
mi_assert_internal((tid & MI_PAGE_FLAG_MASK) == 0);
817-
819+
818820
// we need to use an atomic cas since a concurrent thread may still set the MI_PAGE_HAS_INTERIOR_POINTERS flag (see `alloc_aligned.c`).
819821
mi_threadid_t xtid_old = mi_page_xthread_id(page);
820822
mi_threadid_t xtid;
@@ -868,50 +870,17 @@ static inline bool mi_page_has_any_available(const mi_page_t* page) {
868870
return (page->used < page->reserved || (mi_page_thread_free(page) != NULL));
869871
}
870872

871-
872873
// Owned?
873874
static inline bool mi_page_is_owned(const mi_page_t* page) {
874875
return mi_tf_is_owned(mi_atomic_load_relaxed(&((mi_page_t*)page)->xthread_free));
875876
}
876877

877-
// Unown a page that is currently owned
878-
static inline void _mi_page_unown_unconditional(mi_page_t* page) {
879-
mi_assert_internal(mi_page_is_owned(page));
880-
mi_assert_internal(mi_page_thread_id(page)==0);
881-
const uintptr_t old = mi_atomic_and_acq_rel(&page->xthread_free, ~((uintptr_t)1));
882-
mi_assert_internal((old&1)==1); MI_UNUSED(old);
883-
}
884-
885878
// get ownership if it is not yet owned
886879
static inline bool mi_page_try_claim_ownership(mi_page_t* page) {
887880
const uintptr_t old = mi_atomic_or_acq_rel(&page->xthread_free, 1);
888881
return ((old&1)==0);
889882
}
890883

891-
// release ownership of a page. This may free the page if all blocks were concurrently
892-
// freed in the meantime. Returns true if the page was freed.
893-
static inline bool _mi_page_unown(mi_page_t* page) {
894-
mi_assert_internal(mi_page_is_owned(page));
895-
mi_assert_internal(mi_page_is_abandoned(page));
896-
mi_thread_free_t tf_new;
897-
mi_thread_free_t tf_old = mi_atomic_load_relaxed(&page->xthread_free);
898-
do {
899-
mi_assert_internal(mi_tf_is_owned(tf_old));
900-
while mi_unlikely(mi_tf_block(tf_old) != NULL) {
901-
_mi_page_free_collect(page, false); // update used
902-
if (mi_page_all_free(page)) { // it may become free just before unowning it
903-
_mi_arenas_page_unabandon(page);
904-
_mi_arenas_page_free(page,NULL);
905-
return true;
906-
}
907-
tf_old = mi_atomic_load_relaxed(&page->xthread_free);
908-
}
909-
mi_assert_internal(mi_tf_block(tf_old)==NULL);
910-
tf_new = mi_tf_create(NULL, false);
911-
} while (!mi_atomic_cas_weak_acq_rel(&page->xthread_free, &tf_old, tf_new));
912-
return false;
913-
}
914-
915884

916885
/* -------------------------------------------------------------------
917886
Guarded objects

include/mimalloc/prim.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ terms of the MIT license. A copy of the license can be found in the file
55
"LICENSE" at the root of this distribution.
66
-----------------------------------------------------------------------------*/
77
#pragma once
8-
#ifndef MI_PRIM_H
9-
#define MI_PRIM_H
10-
8+
#ifndef MIMALLOC_PRIM_H
9+
#define MIMALLOC_PRIM_H
10+
#include "internal.h" // mi_decl_hidden
1111

1212
// --------------------------------------------------------------------------
1313
// This file specifies the primitive portability API.
@@ -30,6 +30,7 @@ typedef struct mi_os_mem_config_s {
3030
bool has_overcommit; // can we reserve more memory than can be actually committed?
3131
bool has_partial_free; // can allocated blocks be freed partially? (true for mmap, false for VirtualAlloc)
3232
bool has_virtual_reserve; // supports virtual address space reservation? (if true we can reserve virtual address space without using commit or physical memory)
33+
bool has_transparent_huge_pages; // true if transparent huge pages are enabled (on Linux)
3334
} mi_os_mem_config_t;
3435

3536
// Initialize

0 commit comments

Comments
 (0)