FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Mimallocv3 upstream fixes by DinoV · Pull Request #159863 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (2) .md  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
update to the latest mimalloc
  • Loading branch information
daanx authored and DinoV committed Oct 19, 2026
commit 4b6ebde7f2026805fcae811add58b71126958f96
2 changes: 1 addition & 1 deletion Include/internal/mimalloc/mimalloc.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
#ifndef MIMALLOC_H
#define MIMALLOC_H

#define MI_MALLOC_VERSION 30504 // major + 2 digits minor + 2 digits patch
#define MI_MALLOC_VERSION 30600 // major + 2 digits minor + 2 digits patch

// ------------------------------------------------------
// Compiler specific attributes
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/mimalloc/mimalloc/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and configuration options.
- [`atomic.h`](atomic.h): Portable atomic operations and locks.
- [`prim.h`](prim.h): Primitive and minimal portability API needed from a host system.
- [`track.h`](track.h): Memory-tracking integration for Valgrind, AddressSanitizer, and Windows event tracing.
- [`qsbr.h`](qsbr.h): Quiescent state-based reclamation primitives (for runtime systems like CPython).
- [`qsbr.h`](qsbr.h): Quiescent-state based reclamation primitives (for runtime systems like CPython).
- [`internal.h`](internal.h): Deprecated: umbrella header for internal allocator declarations and utilities.

# Source Headers
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/mimalloc/mimalloc/types.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ typedef struct mi_page_s {
#endif
#define MI_PAGE_CACHE_OFFSET_UNIT (128) // offset granularity (power of 2 between 16 and 4KiB)
#define MI_PAGE_CACHE_OFFSET_MAX (MI_PAGE_OSPAGE_BLOCK_ALIGN2 - MI_PAGE_CACHE_OFFSET_UNIT) // maximal offset (32 possible offsets)
// Offset the first block in pages with small blocks (< 512)
#define MI_PAGE_SMALL_CACHE_OFFSET_UNIT (64)
#define MI_PAGE_SMALL_CACHE_OFFSET_MAX (7*MI_PAGE_SMALL_CACHE_OFFSET_UNIT)

// The max object sizes are intended to not waste more than ~ 12.5% internally over the page sizes.
#define MI_SMALL_MAX_OBJ_SIZE ((MI_SMALL_PAGE_SIZE-MI_PAGE_OSPAGE_BLOCK_ALIGN2)/6) // = 10 KiB
Expand Down
37 changes: 20 additions & 17 deletions Objects/mimalloc/arena/arena-page.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ static size_t mi_page_meta_in_front_block_start(size_t block_size, bool os_align
else if (block_size != 0 && mi_is_power_of_two(block_size) && block_size <= MI_PAGE_MAX_START_BLOCK_ALIGN2) {
// naturally align power-of-2 blocks up to MI_PAGE_MAX_START_BLOCK_ALIGN2 size (4KiB)
offset = mi_align_up(mi_page_info_size(), block_size);
if (block_size < 64) { offset += 3*block_size; }
}
else if (block_size != 0 && block_size <= MI_SMALL_SIZE_MAX) {
// align small blocks to their size
Expand Down Expand Up @@ -302,24 +301,36 @@ static bool mi_page_block_can_cache_offset(size_t block_size, bool os_align) {
return true;
}

static size_t mi_page_cache_offset_index(uint8_t* slice_start, size_t slice_count, size_t noffsets) {
// Fibonacci hash of the page index: the top bits spread consecutive pages evenly over the offsets
const size_t page_index = (size_t)((uintptr_t)slice_start / MI_ARENA_SLICE_SIZE) / slice_count;
#if MI_SIZE_BITS >= 64
const size_t hash = page_index * MI_ZU(0x9E3779B97F4A7C15);
#else
const size_t hash = page_index * MI_ZU(0x9E3779B9);
#endif
return (((hash >> (MI_SIZE_BITS - 16)) * noffsets) >> 16);
}

static size_t mi_page_small_block_cache_offset(uint8_t* slice_start, size_t slice_count, size_t block_size) {
const size_t unit = mi_max(MI_PAGE_SMALL_CACHE_OFFSET_UNIT, mi_natural_alignment_of_size(block_size));
if (unit > MI_PAGE_SMALL_CACHE_OFFSET_MAX) return 0;
return mi_page_cache_offset_index(slice_start, slice_count, 1 + MI_PAGE_SMALL_CACHE_OFFSET_MAX/unit) * unit;
}

// Cache offset for the first block to spread the blocks of different pages over the cache sets (issue #1121).
// The offset fits in the unused space at the end of the page; if there is none, we skip the last block
// if that wastes less than 12.5% of the page (e.g. 64 KiB blocks in a 4 MiB page, but not 512 KiB blocks).
static size_t mi_page_block_cache_offset(uint8_t* slice_start, size_t slice_count, size_t block_size, size_t block_start, bool os_align) {
if (MI_PAGE_CACHE_OFFSET == 0 || os_align) return 0;
if (!mi_block_size_has_cache_offset(block_size)) return mi_page_small_block_cache_offset(slice_start, slice_count, block_size);
if (!mi_page_block_can_cache_offset(block_size, os_align)) return 0;
const size_t page_noguard_size = mi_arenas_page_noguard_size(_mi_size_of_slices(slice_count));
mi_assert_internal(block_start + block_size <= page_noguard_size);
size_t slack = (page_noguard_size - block_start) % block_size;
if (slack < MI_PAGE_CACHE_OFFSET_UNIT && block_size < page_noguard_size/8) { slack += block_size; }
const size_t noffsets = 1 + (slack < MI_PAGE_CACHE_OFFSET_MAX ? slack : MI_PAGE_CACHE_OFFSET_MAX) / MI_PAGE_CACHE_OFFSET_UNIT;
// Fibonacci hash of the page index: the top bits spread consecutive pages evenly over the offsets
const size_t page_index = (size_t)((uintptr_t)slice_start / MI_ARENA_SLICE_SIZE) / slice_count;
#if MI_SIZE_BITS >= 64
const size_t hash = page_index * MI_ZU(0x9E3779B97F4A7C15);
#else
const size_t hash = page_index * MI_ZU(0x9E3779B9);
#endif
return (((hash >> (MI_SIZE_BITS - 16)) * noffsets) >> 16) * MI_PAGE_CACHE_OFFSET_UNIT;
return mi_page_cache_offset_index(slice_start, slice_count, noffsets) * MI_PAGE_CACHE_OFFSET_UNIT;
}

// Use the separate (zero initialized) `page_meta` if available and not preferring in front of the slices,
Expand All @@ -343,15 +354,7 @@ static mi_page_t* mi_page_meta_select(uint8_t* slice_start, size_t slice_count,
else {
// use the separate page meta data
mi_memzero_aligned(page_meta, sizeof(*page_meta));
#if !defined(MI_PAGE_BLOCK_START_MAX_OFFSET)
#define MI_PAGE_BLOCK_START_MAX_OFFSET (8*MI_INTPTR_BITS) /* 512 */
#endif
offset = 0;
if (block_size >= MI_SIZE_SIZE && block_size <= MI_PAGE_BLOCK_START_MAX_OFFSET && mi_is_power_of_two(block_size)) {
// use the same offset as if the page meta data was in front
offset = mi_align_up(mi_page_info_size(), block_size); // to maintain natural alignment
if (block_size < 64) { offset += 3*block_size; }
}
page = page_meta;
}
offset += mi_page_block_cache_offset(slice_start, slice_count, block_size, offset, os_align);
Expand Down

Back | FazBrowse Home | New Git URL