From 95afe453f41e3bb7a317b8f51bf9ac89d4ab17eb Mon Sep 17 00:00:00 2001 From: daan Date: Tue, 9 Jul 2019 23:49:12 -0700 Subject: [PATCH 01/12] fix compilation warning on windows, issue #94 --- src/os.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os.c b/src/os.c index 0678b524..ad666592 100644 --- a/src/os.c +++ b/src/os.c @@ -93,7 +93,7 @@ void _mi_os_init(void) { if (si.dwAllocationGranularity > 0) os_alloc_granularity = si.dwAllocationGranularity; // get the VirtualAlloc2 function HINSTANCE hDll; - hDll = LoadLibrary("kernelbase.dll"); + hDll = LoadLibrary(TEXT("kernelbase.dll")); if (hDll != NULL) { // use VirtualAlloc2FromApp as it is available to Windows store apps pVirtualAlloc2 = (VirtualAlloc2Ptr)GetProcAddress(hDll, "VirtualAlloc2FromApp"); @@ -110,7 +110,7 @@ void _mi_os_init(void) { ok = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token); if (ok) { TOKEN_PRIVILEGES tp; - ok = LookupPrivilegeValue(NULL, "SeLockMemoryPrivilege", &tp.Privileges[0].Luid); + ok = LookupPrivilegeValue(NULL, TEXT("SeLockMemoryPrivilege"), &tp.Privileges[0].Luid); if (ok) { tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; From ef4359b27260e654837c703644d80b57dc2448ba Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 16:33:49 -0700 Subject: [PATCH 02/12] fix abondoned segment counter, and free list adding --- src/segment.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/segment.c b/src/segment.c index 3bf777d4..685f57ee 100644 --- a/src/segment.c +++ b/src/segment.c @@ -584,7 +584,7 @@ static void mi_segment_abandon(mi_segment_t* segment, mi_segments_tld_t* tld) { } while (!mi_atomic_compare_exchange_ptr((volatile void**)&abandoned, segment, segment->abandoned_next)); mi_atomic_increment(&abandoned_count); _mi_stat_increase(&tld->stats->segments_abandoned,1); - mi_segments_track_size((long)segment->segment_size, tld); + mi_segments_track_size(-((long)segment->segment_size), tld); } void _mi_segment_page_abandon(mi_page_t* page, mi_segments_tld_t* tld) { @@ -628,10 +628,7 @@ bool _mi_segment_try_reclaim_abandoned( mi_heap_t* heap, bool try_all, mi_segmen mi_assert_internal(segment->next == NULL && segment->prev == NULL); mi_assert_expensive(mi_segment_is_valid(segment)); _mi_stat_decrease(&tld->stats->segments_abandoned,1); - // add its free pages to the the current thread - if (segment->page_kind == MI_PAGE_SMALL && mi_segment_has_free(segment)) { - mi_segment_enqueue(&tld->small_free, segment); - } + // add its abandoned pages to the current thread mi_assert(segment->abandoned == segment->used); for (size_t i = 0; i < segment->capacity; i++) { @@ -656,6 +653,10 @@ bool _mi_segment_try_reclaim_abandoned( mi_heap_t* heap, bool try_all, mi_segmen } else { reclaimed++; + // add its free pages to the the current thread free small segment queue + if (segment->page_kind == MI_PAGE_SMALL && mi_segment_has_free(segment)) { + mi_segment_enqueue(&tld->small_free, segment); + } } } return (reclaimed>0); From 6deea16d2dc40592b6cc2f7087b931bb8707748a Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 19:54:46 -0700 Subject: [PATCH 03/12] add segment count to internal statistics --- ide/vs2017/mimalloc.vcxproj | 8 +++---- include/mimalloc-types.h | 2 ++ src/init.c | 2 +- src/segment.c | 45 +++++++++++++++++++++++-------------- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/ide/vs2017/mimalloc.vcxproj b/ide/vs2017/mimalloc.vcxproj index 4a831722..752cc82a 100644 --- a/ide/vs2017/mimalloc.vcxproj +++ b/ide/vs2017/mimalloc.vcxproj @@ -93,7 +93,7 @@ true true ../../include - MI_DEBUG=3;_MBCS;%(PreprocessorDefinitions); + MI_DEBUG=3;%(PreprocessorDefinitions); Default @@ -110,7 +110,7 @@ true true ../../include - MI_DEBUG=3;_MBCS;%(PreprocessorDefinitions); + MI_DEBUG=3;%(PreprocessorDefinitions); Default @@ -137,7 +137,7 @@ true true ../../include - _MBCS;%(PreprocessorDefinitions);NDEBUG + %(PreprocessorDefinitions);NDEBUG AssemblyAndSourceCode $(IntDir) true @@ -168,7 +168,7 @@ true true ../../include - _MBCS;%(PreprocessorDefinitions);NDEBUG + %(PreprocessorDefinitions);NDEBUG AssemblyAndSourceCode $(IntDir) true diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index 1d48dbda..27333105 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -373,6 +373,8 @@ typedef struct mi_segment_queue_s { // Segments thread local data typedef struct mi_segments_tld_s { mi_segment_queue_t small_free; // queue of segments with free small pages + size_t count; // current number of segments; + size_t peak_count; // peak number of segments size_t current_size; // current size of all segments size_t peak_size; // peak size of all segments size_t cache_count; // number of segments in the cache diff --git a/src/init.c b/src/init.c index 1b925e89..a62e8a59 100644 --- a/src/init.c +++ b/src/init.c @@ -91,7 +91,7 @@ mi_decl_thread mi_heap_t* _mi_heap_default = (mi_heap_t*)&_mi_heap_empty; static mi_tld_t tld_main = { 0, &_mi_heap_main, - { { NULL, NULL }, 0, 0, 0, 0, {NULL,NULL}, tld_main_stats }, // segments + { { NULL, NULL }, 0, 0, 0, 0, 0, 0, {NULL,NULL}, tld_main_stats }, // segments { 0, NULL, NULL, 0, tld_main_stats }, // os { MI_STATS_NULL } // stats }; diff --git a/src/segment.c b/src/segment.c index 685f57ee..eae33bba 100644 --- a/src/segment.c +++ b/src/segment.c @@ -35,22 +35,6 @@ terms of the MIT license. A copy of the license can be found in the file ----------------------------------------------------------- */ -#if (MI_DEBUG > 1) -static bool mi_segment_is_valid(mi_segment_t* segment) { - mi_assert_internal(segment != NULL); - mi_assert_internal(_mi_ptr_cookie(segment) == segment->cookie); - mi_assert_internal(segment->used <= segment->capacity); - mi_assert_internal(segment->abandoned <= segment->used); - size_t nfree = 0; - for (size_t i = 0; i < segment->capacity; i++) { - if (!segment->pages[i].segment_in_use) nfree++; - } - mi_assert_internal(nfree + segment->used == segment->capacity); - mi_assert_internal(segment->thread_id == _mi_thread_id()); // or 0 - return true; -} -#endif - /* ----------------------------------------------------------- Queue of segments containing free pages ----------------------------------------------------------- */ @@ -121,6 +105,31 @@ static void mi_segment_queue_insert_before(mi_segment_queue_t* queue, mi_segment } +#if (MI_DEBUG > 1) +static size_t mi_segment_pagesize(mi_segment_t* segment) { + return ((size_t)1 << segment->page_shift); +} +static bool mi_segment_is_valid(mi_segment_t* segment) { + mi_assert_internal(segment != NULL); + mi_assert_internal(_mi_ptr_cookie(segment) == segment->cookie); + mi_assert_internal(segment->used <= segment->capacity); + mi_assert_internal(segment->abandoned <= segment->used); + size_t nfree = 0; + for (size_t i = 0; i < segment->capacity; i++) { + if (!segment->pages[i].segment_in_use) nfree++; + } + mi_assert_internal(nfree + segment->used == segment->capacity); + mi_assert_internal(segment->thread_id == _mi_thread_id()); // or 0 + mi_assert_internal(segment->page_kind == MI_PAGE_HUGE || + (mi_segment_pagesize(segment) * segment->capacity == segment->segment_size)); + return true; +} +#endif + +/* ----------------------------------------------------------- + Segment size calculations +----------------------------------------------------------- */ + // Start of the page available memory; can be used on uninitialized pages (only `segment_idx` must be set) uint8_t* _mi_segment_page_start(const mi_segment_t* segment, const mi_page_t* page, size_t block_size, size_t* page_size) { @@ -196,6 +205,8 @@ proves to be too small for certain workloads). static void mi_segments_track_size(long segment_size, mi_segments_tld_t* tld) { if (segment_size>=0) _mi_stat_increase(&tld->stats->segments,1); else _mi_stat_decrease(&tld->stats->segments,1); + tld->count += (segment_size >= 0 ? 1 : -1); + if (tld->count > tld->peak_count) tld->peak_count = tld->count; tld->current_size += segment_size; if (tld->current_size > tld->peak_size) tld->peak_size = tld->current_size; } @@ -725,7 +736,7 @@ static mi_page_t* mi_segment_huge_page_alloc(size_t size, mi_segments_tld_t* tld mi_page_t* _mi_segment_page_alloc(size_t block_size, mi_segments_tld_t* tld, mi_os_tld_t* os_tld) { mi_page_t* page; - if (block_size < MI_SMALL_PAGE_SIZE / 8) + if (block_size <= (MI_SMALL_PAGE_SIZE / 8)) // smaller blocks than 8kb (assuming MI_SMALL_PAGE_SIZE == 64kb) page = mi_segment_small_page_alloc(tld,os_tld); else if (block_size < (MI_LARGE_SIZE_MAX - sizeof(mi_segment_t))) From 12d3297db53b19072c50ed89f635d56f0e732c1a Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 21:52:28 -0700 Subject: [PATCH 04/12] add allocator stress test to the test targets --- CMakeLists.txt | 21 +++--- test/test-stress.c | 166 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 test/test-stress.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d6216384..c6f7abb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,15 +172,21 @@ install(FILES $ # ----------------------------------------------------------------------------- # API surface testing # ----------------------------------------------------------------------------- -add_executable(mimalloc-test test/test-api.c) -target_compile_definitions(mimalloc-test PRIVATE ${mi_defines}) -target_compile_options(mimalloc-test PRIVATE ${mi_cflags}) -target_include_directories(mimalloc-test PRIVATE include) -target_link_libraries(mimalloc-test PRIVATE mimalloc-static) +add_executable(mimalloc-test-api test/test-api.c) +target_compile_definitions(mimalloc-test-api PRIVATE ${mi_defines}) +target_compile_options(mimalloc-test-api PRIVATE ${mi_cflags}) +target_include_directories(mimalloc-test-api PRIVATE include) +target_link_libraries(mimalloc-test-api PRIVATE mimalloc-static) + +add_executable(mimalloc-test-stress test/test-stress.c) +target_compile_definitions(mimalloc-test-stress PRIVATE ${mi_defines}) +target_compile_options(mimalloc-test-stress PRIVATE ${mi_cflags}) +target_include_directories(mimalloc-test-stress PRIVATE include) +target_link_libraries(mimalloc-test-stress PRIVATE mimalloc-static) enable_testing() -add_test(test_api, mimalloc-test) - +add_test(test_api, mimalloc-test-api) +add_test(test_stress, mimalloc-test-stress) # ----------------------------------------------------------------------------- # Set override properties @@ -191,6 +197,5 @@ if (MI_OVERRIDE MATCHES "ON") # It is only possible to override malloc on Windows when building as a DLL. (src/alloc-override.c) target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE) target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE) - target_compile_definitions(mimalloc-test PRIVATE MI_MALLOC_OVERRIDE) endif() endif() diff --git a/test/test-stress.c b/test/test-stress.c new file mode 100644 index 00000000..11a66a82 --- /dev/null +++ b/test/test-stress.c @@ -0,0 +1,166 @@ +/* ---------------------------------------------------------------------------- +Copyright (c) 2018,2019 Microsoft Research, Daan Leijen +This is free software; you can redistribute it and/or modify it under the +terms of the MIT license. A copy of the license can be found in the file +"LICENSE" at the root of this distribution. +-----------------------------------------------------------------------------*/ + +/* This is a stress test for the allocator, using multiple threads and + transferring objects between threads. This is not a typical workload + but uses a random size distribution. Do not use this test as a benchmark! + Note: pthreads uses mimalloc to allocate stacks and thus not all + memory is freed at the end. (usually the 320 byte chunks). +*/ + +#include +#include +#include +#include "mimalloc.h" +#include "mimalloc-internal.h" +#include "mimalloc-atomic.h" + +const size_t N = 10; // scaling factor +const size_t THREADS = 32; + +#define transfer_size (1000) +static volatile void* transfer[transfer_size]; + +#if (MI_INTPTR_SIZE==8) +const uintptr_t cookie = 0xbf58476d1ce4e5b9UL; +#else +const uintptr_t cookie = 0x1ce4e5b9UL; +#endif + + +static void* alloc_items(size_t items) { + if ((rand()%100) == 0) items *= 100; // 1% huge objects; + if (items==40) items++; // pthreads uses that size for stack increases + uintptr_t* p = mi_mallocn_tp(uintptr_t,items); + for (uintptr_t i = 0; i < items; i++) p[i] = (items - i) ^ cookie; + return p; +} + +static void free_items(void* p) { + if (p != NULL) { + uintptr_t* q = (uintptr_t*)p; + uintptr_t items = (q[0] ^ cookie); + for (uintptr_t i = 0; i < items; i++) { + if ((q[i]^cookie) != items - i) { + fprintf(stderr,"memory corruption at block %p at %zu\n", p, i); + abort(); + } + } + } + mi_free(p); +} + + +static void stress(intptr_t tid) { + const size_t max_item = 128; // in words + const size_t max_item_retained = 10*max_item; + size_t allocs = 80*N*(tid%8 + 1); // some threads do more + size_t retain = allocs/2; + void** data = NULL; + size_t data_size = 0; + size_t data_top = 0; + void** retained = mi_mallocn_tp(void*,retain); + size_t retain_top = 0; + + while (allocs>0 || retain>0) { + if (retain == 0 || ((rand()%4 == 0) && allocs > 0)) { + // 75% alloc + allocs--; + if (data_top >= data_size) { + data_size += 100000; + data = mi_reallocn_tp(data, void*, data_size); + } + data[data_top++] = alloc_items((rand() % max_item) + 1); + } + else { + // 25% retain + retained[retain_top++] = alloc_items( 10*((rand() % max_item_retained) + 1) ); + retain--; + } + if ((rand()%3)!=0 && data_top > 0) { + // 66% free previous alloc + size_t idx = rand() % data_top; + free_items(data[idx]); + data[idx]=NULL; + } + if ((tid%2)==0 && (rand()%4)==0 && data_top > 0) { + // 25% transfer-swap of half the threads + size_t data_idx = rand() % data_top; + size_t transfer_idx = rand() % transfer_size; + void* p = data[data_idx]; + void* q = mi_atomic_exchange_ptr(&transfer[transfer_idx],p); + data[data_idx] = q; + } + } + // free everything that is left + for (size_t i = 0; i < retain_top; i++) { + free_items(retained[i]); + } + for (size_t i = 0; i < data_top; i++) { + free_items(data[i]); + } + mi_free(retained); + mi_free(data); +} + +static void run_os_threads(); + +int main() { + srand(42); + memset(transfer,0,transfer_size*sizeof(void*)); + run_os_threads(); + for (int i = 0; i < transfer_size; i++) { + free_items((void*)transfer[i]); + } + mi_collect(false); + mi_stats_print(NULL); + return 0; +} + + +#ifdef _WIN32 + +#include + +static DWORD WINAPI thread_entry(LPVOID param) { + stress((intptr_t)param); + return 0; +} + +static void run_os_threads() { + DWORD tids[THREADS]; + HANDLE thandles[THREADS]; + for(intptr_t i = 0; i < THREADS; i++) { + thandles[i] = CreateThread(0,4096,&thread_entry,(void*)(i),0,&tids[i]); + } + for (int i = 0; i < THREADS; i++) { + WaitForSingleObject(thandles[i], INFINITE); + } +} + +#else + +#include + +static void* thread_entry( void* param ) { + stress((uintptr_t)param); + return NULL; +} + +static void run_os_threads() { + pthread_t threads[THREADS]; + memset(threads,0,sizeof(pthread_t)*THREADS); + //pthread_setconcurrency(THREADS); + for(uintptr_t i = 0; i < THREADS; i++) { + pthread_create(&threads[i], NULL, &thread_entry, (void*)i); + } + for (size_t i = 0; i < THREADS; i++) { + pthread_join(threads[i], NULL); + } +} + +#endif From 34a4de01b117e63a783c5b958110593ea595ad9f Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 21:59:44 -0700 Subject: [PATCH 05/12] add Visual Studio support for new stress target --- ide/vs2017/mimalloc-test-stress.vcxproj | 155 ++++++++++++++++++ .../mimalloc-test-stress.vcxproj.filters | 22 +++ ide/vs2017/mimalloc.sln | 10 ++ test/test-stress.c | 14 +- 4 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 ide/vs2017/mimalloc-test-stress.vcxproj create mode 100644 ide/vs2017/mimalloc-test-stress.vcxproj.filters diff --git a/ide/vs2017/mimalloc-test-stress.vcxproj b/ide/vs2017/mimalloc-test-stress.vcxproj new file mode 100644 index 00000000..5ef92d86 --- /dev/null +++ b/ide/vs2017/mimalloc-test-stress.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FEF7958F-750E-4C21-A04D-22707CC66878} + mimalloc-test-stress + 10.0.17134.0 + mimalloc-test-stress + + + + Application + true + v141 + + + Application + false + v141 + true + + + Application + true + v141 + + + Application + false + v141 + true + + + + + + + + + + + + + + + + + + + + + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + + + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + + + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + + + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + $(ProjectDir)..\..\out\msvc-$(Platform)\$(ProjectName)\$(Configuration)\ + + + + Level3 + Disabled + true + true + ..\..\include + + + Console + + + + + Level3 + Disabled + true + true + ..\..\include + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + ..\..\include + %(PreprocessorDefinitions);NDEBUG + + + true + true + Console + + + + + Level3 + MaxSpeed + true + true + true + true + ..\..\include + %(PreprocessorDefinitions);NDEBUG + + + true + true + Console + + + + + + + + + {abb5eae7-b3e6-432e-b636-333449892ea6} + + + + + + diff --git a/ide/vs2017/mimalloc-test-stress.vcxproj.filters b/ide/vs2017/mimalloc-test-stress.vcxproj.filters new file mode 100644 index 00000000..b857ea52 --- /dev/null +++ b/ide/vs2017/mimalloc-test-stress.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + diff --git a/ide/vs2017/mimalloc.sln b/ide/vs2017/mimalloc.sln index f4860d93..aeab6b88 100644 --- a/ide/vs2017/mimalloc.sln +++ b/ide/vs2017/mimalloc.sln @@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mimalloc-override", "mimall EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mimalloc-override-test", "mimalloc-override-test.vcxproj", "{FEF7868F-750E-4C21-A04D-22707CC66879}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mimalloc-test-stress", "mimalloc-test-stress.vcxproj", "{FEF7958F-750E-4C21-A04D-22707CC66878}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -51,6 +53,14 @@ Global {FEF7868F-750E-4C21-A04D-22707CC66879}.Release|x64.Build.0 = Release|x64 {FEF7868F-750E-4C21-A04D-22707CC66879}.Release|x86.ActiveCfg = Release|Win32 {FEF7868F-750E-4C21-A04D-22707CC66879}.Release|x86.Build.0 = Release|Win32 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Debug|x64.ActiveCfg = Debug|x64 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Debug|x64.Build.0 = Debug|x64 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Debug|x86.ActiveCfg = Debug|Win32 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Debug|x86.Build.0 = Debug|Win32 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Release|x64.ActiveCfg = Release|x64 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Release|x64.Build.0 = Release|x64 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Release|x86.ActiveCfg = Release|Win32 + {FEF7958F-750E-4C21-A04D-22707CC66878}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/test-stress.c b/test/test-stress.c index 11a66a82..6afde306 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -19,11 +19,11 @@ terms of the MIT license. A copy of the license can be found in the file #include "mimalloc-internal.h" #include "mimalloc-atomic.h" -const size_t N = 10; // scaling factor -const size_t THREADS = 32; +#define N (10) // scaling factor +#define THREADS (32) +#define TRANSFERS (1000) -#define transfer_size (1000) -static volatile void* transfer[transfer_size]; +static volatile void* transfer[TRANSFERS]; #if (MI_INTPTR_SIZE==8) const uintptr_t cookie = 0xbf58476d1ce4e5b9UL; @@ -90,7 +90,7 @@ static void stress(intptr_t tid) { if ((tid%2)==0 && (rand()%4)==0 && data_top > 0) { // 25% transfer-swap of half the threads size_t data_idx = rand() % data_top; - size_t transfer_idx = rand() % transfer_size; + size_t transfer_idx = rand() % TRANSFERS; void* p = data[data_idx]; void* q = mi_atomic_exchange_ptr(&transfer[transfer_idx],p); data[data_idx] = q; @@ -111,9 +111,9 @@ static void run_os_threads(); int main() { srand(42); - memset(transfer,0,transfer_size*sizeof(void*)); + memset((void*)transfer,0,TRANSFERS*sizeof(void*)); run_os_threads(); - for (int i = 0; i < transfer_size; i++) { + for (int i = 0; i < TRANSFERS; i++) { free_items((void*)transfer[i]); } mi_collect(false); From df8f9fc59c0fe322e8cd07cf9384fac1898c86e0 Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:13:34 -0700 Subject: [PATCH 06/12] Add test to build pipeline --- azure-pipelines.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a73ac1a0..9542e869 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,19 +23,31 @@ jobs: solution: build/libmimalloc.sln - upload: $(Build.SourcesDirectory)/build artifact: windows + - job: displayName: Linux pool: vmImage: ubuntu-16.04 + strategy: + matrix: + Debug: + CC: gcc + BuildType: Debug + Release: + CC: gcc + BuildType: Release + steps: - task: CMake@1 inputs: - workingDirectory: 'build' + workingDirectory: $(BuildType) cmakeArgs: .. - - script: make -j$(nproc) -C build - - upload: $(Build.SourcesDirectory)/build + - script: make -j$(nproc) -C $(BuildType) + - script: ctest -C $(BuildType) + - upload: $(Build.SourcesDirectory)/$(BuildType) artifact: ubuntu + - job: displayName: macOS pool: From a5179d1125e407aa3bd93ceae49cfae73d1a223c Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:21:08 -0700 Subject: [PATCH 07/12] fix azure pipeline script --- azure-pipelines.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9542e869..0da585b7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,20 +33,28 @@ jobs: matrix: Debug: CC: gcc - BuildType: Debug + BuildType: debug + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_CHECK_FULL=ON Release: CC: gcc - BuildType: Release + BuildType: release + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug steps: - task: CMake@1 inputs: workingDirectory: $(BuildType) - cmakeArgs: .. - - script: make -j$(nproc) -C $(BuildType) - - script: ctest -C $(BuildType) + cmakeArgs: .. $(cmakeExtraArgs) + + - script: make -j$(nproc) + workingDirectory: $(BuildType) + + - script: ctest + failOnStderr: true + workingDirectory: $(BuildType) + - upload: $(Build.SourcesDirectory)/$(BuildType) - artifact: ubuntu + artifact: ubuntu-$(BuildType) - job: displayName: macOS From 9fabd1ea01185e579b3627eb8d02196d648e6fde Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:22:44 -0700 Subject: [PATCH 08/12] fix azure pipeline script --- azure-pipelines.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0da585b7..d31acc2d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,12 +46,10 @@ jobs: workingDirectory: $(BuildType) cmakeArgs: .. $(cmakeExtraArgs) - - script: make -j$(nproc) - workingDirectory: $(BuildType) + - script: make -j$(nproc) -C $(BuildType) - - script: ctest + - script: make test -C $(BuildType) failOnStderr: true - workingDirectory: $(BuildType) - upload: $(Build.SourcesDirectory)/$(BuildType) artifact: ubuntu-$(BuildType) From 67bed283aa07303101a8828ea08e0cfe0b2c27da Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:23:18 -0700 Subject: [PATCH 09/12] fix azure pipeline script; remove mapping value --- azure-pipelines.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d31acc2d..4f21b8da 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -49,7 +49,6 @@ jobs: - script: make -j$(nproc) -C $(BuildType) - script: make test -C $(BuildType) - failOnStderr: true - upload: $(Build.SourcesDirectory)/$(BuildType) artifact: ubuntu-$(BuildType) From 6577e0e9fd18ca1873fbeb4fe982e4fe43d81894 Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:35:39 -0700 Subject: [PATCH 10/12] add test results task to azure pipeline --- azure-pipelines.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4f21b8da..80967084 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -53,6 +53,11 @@ jobs: - upload: $(Build.SourcesDirectory)/$(BuildType) artifact: ubuntu-$(BuildType) + - task: PublishTestResults@2 + inputs: + testResultsFormat: cTest + testResultsFiles: '$(BuildType)/Testing/Temporary/LastTest.log' + - job: displayName: macOS pool: From 3bef93698bbd89d62925274cb64e9d9af6fe9f1f Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:41:53 -0700 Subject: [PATCH 11/12] remove publish test, add clang config --- azure-pipelines.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 80967084..e6d2f5ef 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -38,7 +38,15 @@ jobs: Release: CC: gcc BuildType: release - cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release + Debug Clang: + CC: clang + BuildType: debug-clang + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_CHECK_FULL=ON + Release Clang: + CC: clang + BuildType: release-clang + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release steps: - task: CMake@1 @@ -53,11 +61,6 @@ jobs: - upload: $(Build.SourcesDirectory)/$(BuildType) artifact: ubuntu-$(BuildType) - - task: PublishTestResults@2 - inputs: - testResultsFormat: cTest - testResultsFiles: '$(BuildType)/Testing/Temporary/LastTest.log' - - job: displayName: macOS pool: From 4e6249fd1217c33345fe2b1c764fcbacbfdb0127 Mon Sep 17 00:00:00 2001 From: daan Date: Wed, 10 Jul 2019 22:44:36 -0700 Subject: [PATCH 12/12] azure pipelines better display name, fix c++ compiler --- azure-pipelines.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e6d2f5ef..79228c41 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,18 +33,22 @@ jobs: matrix: Debug: CC: gcc + CXX: g++ BuildType: debug cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_CHECK_FULL=ON Release: CC: gcc + CXX: g++ BuildType: release cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release Debug Clang: CC: clang + CXX: clang++ BuildType: debug-clang cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_CHECK_FULL=ON Release Clang: CC: clang + CXX: clang++ BuildType: release-clang cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release @@ -55,8 +59,10 @@ jobs: cmakeArgs: .. $(cmakeExtraArgs) - script: make -j$(nproc) -C $(BuildType) + displayName: Make - script: make test -C $(BuildType) + displayName: Ctest - upload: $(Build.SourcesDirectory)/$(BuildType) artifact: ubuntu-$(BuildType)