From b19da8e362acae8944c60a40cf5c40c8f5ebeb44 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 6 Apr 2021 11:05:43 -0700 Subject: [PATCH 1/9] update readme for 1.7.1 and 2.0.1 --- readme.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 00c6fbd1..e3662368 100644 --- a/readme.md +++ b/readme.md @@ -12,8 +12,8 @@ is a general purpose allocator with excellent [performance](#performance) charac Initially developed by Daan Leijen for the run-time systems of the [Koka](https://koka-lang.github.io) and [Lean](https://github.com/leanprover/lean) languages. -Latest release tag: `v2.0.0` (beta, 2021-01-31). -Latest stable tag: `v1.7.0` (2021-01-31). +Latest release tag: `v2.0.1` (beta, 2021-04-06). +Latest stable tag: `v1.7.1` (2021-04-06). mimalloc is a drop-in replacement for `malloc` and can be used in other programs without code changes, for example, on dynamically linked ELF-based systems (Linux, BSD, etc.) you can use it as: @@ -71,8 +71,10 @@ Enjoy! * `dev`: development branch for mimalloc v1. * `dev-slice`: development branch for mimalloc v2 with a new algorithm for managing internal mimalloc pages. -### Release +### Releases +* 2021-04-06, `v1.7.1`, `v2.0.1` (beta): fix bug in arena allocation for huge pages, improved aslr on large allocations, improved M1 support (still experimental). + * 2021-01-31, `v2.0.0`: beta release 2.0: new algorithm for managing internal mimalloc pages that tends to use reduce memory usage and fragmentation compared to mimalloc v1 (especially for large workloads). Should otherwise have similar performance (see [below](#performance)); please report if you observe any significant performance regression. From ad2fa2bf6f737ba5b8d86716dc96375e8aa56db7 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Wed, 7 Apr 2021 01:32:19 -0700 Subject: [PATCH 2/9] Fix thread ID getter on Android ARM/AArch64 Android's Bionic libc stores the thread ID in TLS slot 1 instead of 0 on 32-bit ARM and AArch64. Slot 0 contains a pointer to the ELF DTV (Dynamic Thread Vector) instead, which is constant for each loaded DSO. Because mimalloc uses the thread ID to determine whether operations are thread-local or cross-thread (atomic), all threads having the same ID causes internal data structures to get corrupted quickly when multiple threads are using the allocator: mimalloc: assertion failed: at "external/mimalloc/src/page.c":563, mi_page_extend_free assertion: "page->local_free == NULL" mimalloc: assertion failed: at "external/mimalloc/src/page.c":74, mi_page_is_valid_init assertion: "page->used <= page->capacity" mimalloc: assertion failed: at "external/mimalloc/src/page.c":100, mi_page_is_valid_init assertion: "page->used + free_count == page->capacity" mimalloc: assertion failed: at "external/mimalloc/src/page.c":74, mi_page_is_valid_init assertion: "page->used <= page->capacity" Add support for Android's alternate TLS layout to fix the crashes in multi-threaded use cases. Fixes #376. --- include/mimalloc-internal.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 7160bc47..d1b8f107 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -751,6 +751,9 @@ static inline uintptr_t _mi_thread_id(void) mi_attr_noexcept { #if defined(__aarch64__) && defined(__APPLE__) // M1 // on macOS on the M1, slot 0 does not seem to work, so we fall back to portable C for now. See issue #354 return (uintptr_t)&_mi_heap_default; +#elif defined(__BIONIC__) && (defined(__arm__) || defined(__aarch64__)) + // on Android, slot 1 is the thread ID (pointer to pthread internal struct) + return (uintptr_t)mi_tls_slot(1); #else // in all our other targets, slot 0 is the pointer to the thread control block return (uintptr_t)mi_tls_slot(0); From ad44f76598c2f86c266a7bcafbd4a8381d9c4de5 Mon Sep 17 00:00:00 2001 From: elbaro Date: Sun, 11 Apr 2021 03:09:23 +0900 Subject: [PATCH 3/9] commit --- src/alloc-override.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/alloc-override.c b/src/alloc-override.c index 5906bd20..ed0dbb39 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -187,11 +187,14 @@ void* memalign(size_t alignment, size_t size) { return mi_memali int posix_memalign(void** p, size_t alignment, size_t size) { return mi_posix_memalign(p, alignment, size); } void* _aligned_malloc(size_t alignment, size_t size) { return mi_aligned_alloc(alignment, size); } -// on some glibc `aligned_alloc` is declared `static inline` so we cannot override it (e.g. Conda). This happens -// when _GLIBCXX_HAVE_ALIGNED_ALLOC is not defined. However, in those cases it will use `memalign`, `posix_memalign`, -// or `_aligned_malloc` and we can avoid overriding it ourselves. -// We should always override if using C compilation. (issue #276) -#if _GLIBCXX_HAVE_ALIGNED_ALLOC || !defined(__cplusplus) +// aligned_alloc is available when __USE_ISOC11 is defined. +// if aligned_alloc is not available, we will use `memalign`, `posix_memalign`, or `_aligned_malloc` +// and avoid overriding it ourselves. +// +// For example, Conda has a custom glibc where `aligned_alloc` is declared `static inline`. +// Both _ISOC11_SOURCE and __USE_ISOC11 are undefined in Conda GCC7 or GCC9. +// When compiling C codes, _ISOC11_SOURCE is undefined but __USE_ISOC11 is 1. +#if __USE_ISOC11 void* aligned_alloc(size_t alignment, size_t size) { return mi_aligned_alloc(alignment, size); } #endif From 8311cef0d11a343068a713900a879ff0cdc0d036 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 17 Apr 2021 15:08:25 -0300 Subject: [PATCH 4/9] Fix typo in comment it -> if in mimalloc-types.h --- include/mimalloc-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index 99024679..ddb0511d 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -270,7 +270,7 @@ typedef struct mi_segment_s { struct mi_segment_s* prev; size_t abandoned; // abandoned pages (i.e. the original owning thread stopped) (`abandoned <= used`) - size_t abandoned_visits; // count how often this segment is visited in the abandoned list (to force reclaim it it is too long) + size_t abandoned_visits; // count how often this segment is visited in the abandoned list (to force reclaim if it is too long) size_t used; // count of pages in use (`used <= capacity`) size_t capacity; // count of available pages (`#free + used`) From 3402c6cc3f439e8be04ff99afea2c810f27af035 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 19 Apr 2021 01:02:13 +0800 Subject: [PATCH 5/9] Revise the use of macOS predefined macro Quoted from "Porting UNIX/Linux Applications to OS X,"[1] * macro __MACH__ is defined if Mach system calls are supported; * macro __APPLE__ is defined in any Apple computer. __MACH__ is not specific to macOS since GNU/Hurd runs on a Mach-based microkernel (gnumach) [2]. __MACH__ is defined by the compiler, leading to potential confusions. The solution is just changing the checked identifier (i.e. __APPLE__), so it is really used only on macOS. [1] https://developer.apple.com/library/archive/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html [2] https://www.gnu.org/software/hurd/microkernel/mach/gnumach.html --- include/mimalloc-internal.h | 6 +++--- src/alloc-override.c | 8 ++++---- src/options.c | 4 ++-- src/stats.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 7160bc47..5655cd48 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -293,7 +293,7 @@ extern bool _mi_process_is_initialized; mi_heap_t* _mi_heap_main_get(void); // statically allocated main backing heap #if defined(MI_MALLOC_OVERRIDE) -#if defined(__MACH__) // OSX +#if defined(__APPLE__) // macOS #define MI_TLS_SLOT 89 // seems unused? // other possible unused ones are 9, 29, __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 (94), __PTK_FRAMEWORK_GC_KEY9 (112) and __PTK_FRAMEWORK_OLDGC_KEY9 (89) // see @@ -699,7 +699,7 @@ static inline void* mi_tls_slot(size_t slot) mi_attr_noexcept { const size_t ofs = (slot*sizeof(void*)); #if defined(__i386__) __asm__("movl %%gs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // 32-bit always uses GS -#elif defined(__MACH__) && defined(__x86_64__) +#elif defined(__APPLE__) && defined(__x86_64__) __asm__("movq %%gs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // x86_64 macOSX uses GS #elif defined(__x86_64__) && (MI_INTPTR_SIZE==4) __asm__("movl %%fs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // x32 ABI @@ -726,7 +726,7 @@ static inline void mi_tls_slot_set(size_t slot, void* value) mi_attr_noexcept { const size_t ofs = (slot*sizeof(void*)); #if defined(__i386__) __asm__("movl %1,%%gs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // 32-bit always uses GS -#elif defined(__MACH__) && defined(__x86_64__) +#elif defined(__APPLE__) && defined(__x86_64__) __asm__("movq %1,%%gs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x86_64 macOSX uses GS #elif defined(__x86_64__) && (MI_INTPTR_SIZE==4) __asm__("movl %1,%%fs:%1" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x32 ABI diff --git a/src/alloc-override.c b/src/alloc-override.c index 5906bd20..b4a661b8 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -13,13 +13,13 @@ terms of the MIT license. A copy of the license can be found in the file #error "It is only possible to override "malloc" on Windows when building as a DLL (and linking the C runtime as a DLL)" #endif -#if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32)) // || (defined(__MACH__) && !defined(MI_INTERPOSE))) +#if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32)) // || (defined(__APPLE__) && !defined(MI_INTERPOSE))) // ------------------------------------------------------ // Override system malloc // ------------------------------------------------------ -#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MACH__) +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__) // use aliasing to alias the exported function to one of our `mi_` functions #if (defined(__GNUC__) && __GNUC__ >= 9) #define MI_FORWARD(fun) __attribute__((alias(#fun), used, visibility("default"), copy(fun))) @@ -81,7 +81,7 @@ terms of the MIT license. A copy of the license can be found in the file void free(void* p) MI_FORWARD0(mi_free, p); #endif -#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MACH__) +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__) #pragma GCC visibility push(default) #endif @@ -214,7 +214,7 @@ void* aligned_alloc(size_t alignment, size_t size) { return mi_aligned_alloc(a } #endif -#if (defined(__GNUC__) || defined(__clang__)) && !defined(__MACH__) +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__APPLE__) #pragma GCC visibility pop #endif diff --git a/src/options.c b/src/options.c index 6e229f9f..14df8fba 100644 --- a/src/options.c +++ b/src/options.c @@ -259,7 +259,7 @@ static _Atomic(uintptr_t) warning_count; // = 0; // when >= max_warning_count s static mi_decl_thread bool recurse = false; static bool mi_recurse_enter(void) { - #if defined(__MACH__) || defined(MI_TLS_RECURSE_GUARD) + #if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD) if (_mi_preloading()) return true; #endif if (recurse) return false; @@ -268,7 +268,7 @@ static bool mi_recurse_enter(void) { } static void mi_recurse_exit(void) { - #if defined(__MACH__) || defined(MI_TLS_RECURSE_GUARD) + #if defined(__APPLE__) || defined(MI_TLS_RECURSE_GUARD) if (_mi_preloading()) return; #endif recurse = false; diff --git a/src/stats.c b/src/stats.c index 8cd74e41..a82eeb8a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -479,12 +479,12 @@ static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msec *page_faults = (size_t)info.PageFaultCount; } -#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) || defined(__HAIKU__) +#elif defined(__unix__) || defined(__unix) || defined(unix) || defined(__APPLE__) || defined(__HAIKU__) #include #include #include -#if defined(__APPLE__) && defined(__MACH__) +#if defined(__APPLE__) #include #endif @@ -520,7 +520,7 @@ static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msec while (get_next_area_info(tid.team, &c, &mem) == B_OK) { *peak_rss += mem.ram_size; } -#elif defined(__APPLE__) && defined(__MACH__) +#elif defined(__APPLE__) *peak_rss = rusage.ru_maxrss; // BSD reports in bytes struct mach_task_basic_info info; mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; From 52943917ad0b154fe21d40496e32db15a23d6efb Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Wed, 21 Apr 2021 13:14:53 +0000 Subject: [PATCH 6/9] Rewrite align_down with bitwise operations mi_align_down_ptr was implemented with multiplication and division, which can be converted to equivalent and deterministic bit operations. --- src/os.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os.c b/src/os.c index 18105596..fc971a44 100644 --- a/src/os.c +++ b/src/os.c @@ -65,7 +65,11 @@ static void* mi_align_up_ptr(void* p, size_t alignment) { return (void*)_mi_align_up((uintptr_t)p, alignment); } -static uintptr_t _mi_align_down(uintptr_t sz, size_t alignment) { +static inline uintptr_t _mi_align_down(uintptr_t sz, size_t alignment) { + mi_assert_internal(alignment != 0); + uintptr_t mask = alignment - 1; + if ((alignment & mask) == 0) // power of two? + return sz & ~mask; return (sz / alignment) * alignment; } From 5940d3bcce18e0247774f430502788cce265cea5 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Sat, 24 Apr 2021 16:35:11 +0000 Subject: [PATCH 7/9] Bump copyright date Each source file has been changed according to relevant Git activities. --- LICENSE | 2 +- doc/mimalloc-doc.h | 2 +- include/mimalloc-atomic.h | 2 +- include/mimalloc-internal.h | 2 +- include/mimalloc-new-delete.h | 2 +- include/mimalloc-override.h | 2 +- include/mimalloc-types.h | 2 +- include/mimalloc.h | 2 +- src/alloc-aligned.c | 2 +- src/alloc-override-osx.c | 4 ++-- src/alloc-override.c | 2 +- src/alloc-posix.c | 2 +- src/alloc.c | 2 +- src/arena.c | 2 +- src/bitmap.c | 2 +- src/bitmap.h | 2 +- src/heap.c | 2 +- src/init.c | 2 +- src/options.c | 2 +- src/os.c | 2 +- src/page-queue.c | 2 +- src/page.c | 2 +- src/random.c | 2 +- src/region.c | 2 +- src/segment.c | 2 +- src/static.c | 2 +- src/stats.c | 2 +- test/test-api.c | 2 +- test/test-stress.c | 2 +- 29 files changed, 30 insertions(+), 30 deletions(-) diff --git a/LICENSE b/LICENSE index 4151dbe4..670b668a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Microsoft Corporation, Daan Leijen +Copyright (c) 2018-2021 Microsoft Corporation, Daan Leijen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/doc/mimalloc-doc.h b/doc/mimalloc-doc.h index 59113402..b448f14a 100644 --- a/doc/mimalloc-doc.h +++ b/doc/mimalloc-doc.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/include/mimalloc-atomic.h b/include/mimalloc-atomic.h index db885319..d82bcfce 100644 --- a/include/mimalloc-atomic.h +++ b/include/mimalloc-atomic.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018,2020 Microsoft Research, Daan Leijen +Copyright (c) 2018-2021 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. diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index d8e293b4..449893b7 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/include/mimalloc-new-delete.h b/include/mimalloc-new-delete.h index fded0c04..ba208f05 100644 --- a/include/mimalloc-new-delete.h +++ b/include/mimalloc-new-delete.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018,2019 Microsoft Research, Daan Leijen +Copyright (c) 2018-2020 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. diff --git a/include/mimalloc-override.h b/include/mimalloc-override.h index 2362bfbc..7d9f3e7d 100644 --- a/include/mimalloc-override.h +++ b/include/mimalloc-override.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018,2019 Microsoft Research, Daan Leijen +Copyright (c) 2018-2020 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. diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index ddb0511d..18f1623c 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/include/mimalloc.h b/include/mimalloc.h index a7849f86..fe5aa8f3 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018-2020, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/alloc-aligned.c b/src/alloc-aligned.c index 4be651d4..724c0a1b 100644 --- a/src/alloc-aligned.c +++ b/src/alloc-aligned.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/alloc-override-osx.c b/src/alloc-override-osx.c index 4b77f631..3a46ecd9 100644 --- a/src/alloc-override-osx.c +++ b/src/alloc-override-osx.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2020, 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. @@ -278,4 +278,4 @@ static void __attribute__((constructor(0))) _mi_macos_override_malloc() { } -#endif // MI_MALLOC_OVERRIDE \ No newline at end of file +#endif // MI_MALLOC_OVERRIDE diff --git a/src/alloc-override.c b/src/alloc-override.c index b4a661b8..5ceab651 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/alloc-posix.c b/src/alloc-posix.c index eef70ab5..43931e56 100644 --- a/src/alloc-posix.c +++ b/src/alloc-posix.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018,2019, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/alloc.c b/src/alloc.c index 7fcd6a49..25cc04ef 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/arena.c b/src/arena.c index f697622f..0e6615a4 100644 --- a/src/arena.c +++ b/src/arena.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2019, Microsoft Research, Daan Leijen +Copyright (c) 2019-2021, 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. diff --git a/src/bitmap.c b/src/bitmap.c index 75da19df..3b5c8199 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2019,2020 Microsoft Research, Daan Leijen +Copyright (c) 2019-2021 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. diff --git a/src/bitmap.h b/src/bitmap.h index f7819803..21fd4e13 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2019,2020 Microsoft Research, Daan Leijen +Copyright (c) 2019-2020 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. diff --git a/src/heap.c b/src/heap.c index 275af755..bda10699 100644 --- a/src/heap.c +++ b/src/heap.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/init.c b/src/init.c index df5efd03..c0f09b5e 100644 --- a/src/init.c +++ b/src/init.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/options.c b/src/options.c index 14df8fba..30025db2 100644 --- a/src/options.c +++ b/src/options.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/os.c b/src/os.c index 18105596..814622fc 100644 --- a/src/os.c +++ b/src/os.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/src/page-queue.c b/src/page-queue.c index 57e3d6a5..365257e7 100644 --- a/src/page-queue.c +++ b/src/page-queue.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2020, 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. diff --git a/src/page.c b/src/page.c index 4b7e9ffb..c08be9c0 100644 --- a/src/page.c +++ b/src/page.c @@ -1,5 +1,5 @@ /*---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2020, 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. diff --git a/src/random.c b/src/random.c index 113ba0fd..255bede4 100644 --- a/src/random.c +++ b/src/random.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2019, Microsoft Research, Daan Leijen +Copyright (c) 2019-2021, 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. diff --git a/src/region.c b/src/region.c index 663859c8..79540730 100644 --- a/src/region.c +++ b/src/region.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2019, Microsoft Research, Daan Leijen +Copyright (c) 2019-2020, 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. diff --git a/src/segment.c b/src/segment.c index fb8e0fe1..1d59be9d 100644 --- a/src/segment.c +++ b/src/segment.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2020, 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. diff --git a/src/static.c b/src/static.c index 346aced1..4b3abc28 100644 --- a/src/static.c +++ b/src/static.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2020, 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. diff --git a/src/stats.c b/src/stats.c index a82eeb8a..c94fbde9 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2021, 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. diff --git a/test/test-api.c b/test/test-api.c index e5827a93..d3344928 100644 --- a/test/test-api.c +++ b/test/test-api.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018, Microsoft Research, Daan Leijen +Copyright (c) 2018-2020, 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. diff --git a/test/test-stress.c b/test/test-stress.c index c4247abe..9b64d243 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -1,5 +1,5 @@ /* ---------------------------------------------------------------------------- -Copyright (c) 2018,2019 Microsoft Research, Daan Leijen +Copyright (c) 2018-2020 Microsoft Research, Daan Leijen This is free software; you can redistribute it and/or modify it under the terms of the MIT license. -----------------------------------------------------------------------------*/ From aca46242abbe61be9d1bb7df4adb9b3f044684da Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 28 Apr 2021 12:47:14 -0700 Subject: [PATCH 8/9] update comment for aligned_alloc --- src/alloc-override.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/alloc-override.c b/src/alloc-override.c index a5fea3ca..798af77b 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -187,14 +187,12 @@ void* memalign(size_t alignment, size_t size) { return mi_memali int posix_memalign(void** p, size_t alignment, size_t size) { return mi_posix_memalign(p, alignment, size); } void* _aligned_malloc(size_t alignment, size_t size) { return mi_aligned_alloc(alignment, size); } -// aligned_alloc is available when __USE_ISOC11 is defined. -// if aligned_alloc is not available, we will use `memalign`, `posix_memalign`, or `_aligned_malloc` -// and avoid overriding it ourselves. -// -// For example, Conda has a custom glibc where `aligned_alloc` is declared `static inline`. -// Both _ISOC11_SOURCE and __USE_ISOC11 are undefined in Conda GCC7 or GCC9. -// When compiling C codes, _ISOC11_SOURCE is undefined but __USE_ISOC11 is 1. -#if __USE_ISOC11 +// `aligned_alloc` is only available when __USE_ISOC11 is defined. +// Note: Conda has a custom glibc where `aligned_alloc` is declared `static inline` and we cannot +// override it, but both _ISOC11_SOURCE and __USE_ISOC11 are undefined in Conda GCC7 or GCC9. +// Fortunately, in the case where `aligned_alloc` is declared as `static inline` it +// uses internally `memalign`, `posix_memalign`, or `_aligned_malloc` so we can avoid overriding it ourselves. +#if __USE_ISOC11 void* aligned_alloc(size_t alignment, size_t size) { return mi_aligned_alloc(alignment, size); } #endif From 29ea7a89ab9c40ec7a2672cfb7d555b5e5057f06 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Wed, 28 Apr 2021 13:08:59 -0700 Subject: [PATCH 9/9] add braces --- src/os.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/os.c b/src/os.c index fc971a44..e01d9d97 100644 --- a/src/os.c +++ b/src/os.c @@ -68,9 +68,12 @@ static void* mi_align_up_ptr(void* p, size_t alignment) { static inline uintptr_t _mi_align_down(uintptr_t sz, size_t alignment) { mi_assert_internal(alignment != 0); uintptr_t mask = alignment - 1; - if ((alignment & mask) == 0) // power of two? - return sz & ~mask; - return (sz / alignment) * alignment; + if ((alignment & mask) == 0) { // power of two? + return (sz & ~mask); + } + else { + return ((sz / alignment) * alignment); + } } static void* mi_align_down_ptr(void* p, size_t alignment) {