Skip to content

Commit 46915ec

Browse files
authored
Update mimalloc to v2.2.7 (#6048)
After releasing v2.2.6, they followed up really quickly with a v2.2.7, which indicates some urgency in taking this update. The diff of this PR is pretty informative, too. This closes #6046
2 parents 402505f + 52287e6 commit 46915ec

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

compat/mimalloc/alloc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ extern inline void* _mi_page_malloc_zero(mi_heap_t* heap, mi_page_t* page, size_
5959
// zero the block? note: we need to zero the full block size (issue #63)
6060
if mi_unlikely(zero) {
6161
mi_assert_internal(page->block_size != 0); // do not call with zero'ing for huge blocks (see _mi_malloc_generic)
62-
mi_assert_internal(!mi_page_is_huge(page));
6362
#if MI_PADDING
6463
mi_assert_internal(page->block_size >= MI_PADDING_SIZE);
6564
#endif
@@ -528,7 +527,7 @@ static std_new_handler_t mi_get_new_handler(void) {
528527
}
529528
#else
530529
// note: on windows we could dynamically link to `?get_new_handler@std@@YAP6AXXZXZ`.
531-
static std_new_handler_t mi_get_new_handler() {
530+
static std_new_handler_t mi_get_new_handler(void) {
532531
return NULL;
533532
}
534533
#endif

compat/mimalloc/mimalloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
88
#ifndef MIMALLOC_H
99
#define MIMALLOC_H
1010

11-
#define MI_MALLOC_VERSION 226 // major + 2 digits minor
11+
#define MI_MALLOC_VERSION 227 // major + 2 digits minor
1212

1313
// ------------------------------------------------------
1414
// Compiler specific attributes

compat/mimalloc/mimalloc/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,15 +1093,15 @@ static inline size_t mi_popcount(size_t x) {
10931093
extern mi_decl_hidden bool _mi_cpu_has_fsrm;
10941094
extern mi_decl_hidden bool _mi_cpu_has_erms;
10951095
static inline void _mi_memcpy(void* dst, const void* src, size_t n) {
1096-
if ((_mi_cpu_has_fsrm && n <= 128) || (_mi_cpu_has_erms && n > 128)) {
1096+
if (_mi_cpu_has_fsrm && n <= 127) { // || (_mi_cpu_has_erms && n > 128)) {
10971097
__movsb((unsigned char*)dst, (const unsigned char*)src, n);
10981098
}
10991099
else {
11001100
memcpy(dst, src, n);
11011101
}
11021102
}
11031103
static inline void _mi_memzero(void* dst, size_t n) {
1104-
if ((_mi_cpu_has_fsrm && n <= 128) || (_mi_cpu_has_erms && n > 128)) {
1104+
if (_mi_cpu_has_fsrm && n <= 127) { // || (_mi_cpu_has_erms && n > 128)) {
11051105
__stosb((unsigned char*)dst, 0, n);
11061106
}
11071107
else {

compat/mimalloc/mimalloc/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ typedef struct mi_segment_s {
480480
struct mi_segment_s* next; // the list of freed segments in the cache (must be first field, see `segment.c:mi_segment_init`)
481481
bool was_reclaimed; // true if it was reclaimed (used to limit on-free reclamation)
482482
bool dont_free; // can be temporarily true to ensure the segment is not freed
483+
bool free_is_zero; // if free spans are zero
483484

484485
size_t abandoned; // abandoned pages (i.e. the original owning thread stopped) (`abandoned <= used`)
485486
size_t abandoned_visits; // count how often this segment is visited during abondoned reclamation (to force reclaim if it takes too long)

compat/mimalloc/page.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,17 +1031,9 @@ void* _mi_malloc_generic(mi_heap_t* heap, size_t size, bool zero, size_t huge_al
10311031
mi_assert_internal(mi_page_block_size(page) >= size);
10321032

10331033
// and try again, this time succeeding! (i.e. this should never recurse through _mi_page_malloc)
1034-
void* p;
1035-
if mi_unlikely(zero && mi_page_is_huge(page)) {
1036-
// note: we cannot call _mi_page_malloc with zeroing for huge blocks; we zero it afterwards in that case.
1037-
p = _mi_page_malloc_zero(heap, page, size, false, usable);
1038-
mi_assert_internal(p != NULL);
1039-
_mi_memzero_aligned(p, mi_page_usable_block_size(page));
1040-
}
1041-
else {
1042-
p = _mi_page_malloc_zero(heap, page, size, zero, usable);
1043-
mi_assert_internal(p != NULL);
1044-
}
1034+
void* const p = _mi_page_malloc_zero(heap, page, size, zero, usable);
1035+
mi_assert_internal(p != NULL);
1036+
10451037
// move singleton pages to the full queue
10461038
if (page->reserved == page->used) {
10471039
mi_page_to_full(page, mi_page_queue_of(page));

compat/mimalloc/segment.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ static mi_page_t* mi_segment_span_allocate(mi_segment_t* segment, size_t slice_i
773773

774774
// and initialize the page
775775
page->is_committed = true;
776+
page->is_zero_init = segment->free_is_zero;
776777
page->is_huge = (segment->kind == MI_SEGMENT_HUGE);
777778
segment->used++;
778779
return page;
@@ -882,6 +883,7 @@ static mi_segment_t* mi_segment_os_alloc( size_t required, size_t page_alignment
882883
segment->subproc = tld->subproc;
883884
segment->commit_mask = commit_mask;
884885
segment->purge_expire = 0;
886+
segment->free_is_zero = memid.initially_zero;
885887
mi_commit_mask_create_empty(&segment->purge_mask);
886888

887889
mi_segments_track_size((long)(segment_size), tld);
@@ -1024,7 +1026,7 @@ static mi_slice_t* mi_segment_page_clear(mi_page_t* page, mi_segments_tld_t* tld
10241026
_mi_stat_decrease(&tld->stats->page_committed, inuse);
10251027
_mi_stat_decrease(&tld->stats->pages, 1);
10261028
_mi_stat_decrease(&tld->stats->page_bins[_mi_page_stats_bin(page)], 1);
1027-
1029+
10281030
// reset the page memory to reduce memory pressure?
10291031
if (segment->allow_decommit && mi_option_is_enabled(mi_option_deprecated_page_reset)) {
10301032
size_t psize;
@@ -1043,6 +1045,8 @@ static mi_slice_t* mi_segment_page_clear(mi_page_t* page, mi_segments_tld_t* tld
10431045
// and free it
10441046
mi_slice_t* slice = mi_segment_span_free_coalesce(mi_page_to_slice(page), tld);
10451047
segment->used--;
1048+
segment->free_is_zero = false;
1049+
10461050
// cannot assert segment valid as it is called during reclaim
10471051
// mi_assert_expensive(mi_segment_is_valid(segment, tld));
10481052
return slice;

0 commit comments

Comments
 (0)