mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-08 00:09:31 +03:00
rename MI_ALIGNMENT_MAX to MI_BLOCK_ALIGNMENT_MAX for clarity
This commit is contained in:
parent
f141ca12a4
commit
6688b45fbd
7 changed files with 43 additions and 43 deletions
|
@ -499,11 +499,11 @@ void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_m
|
||||||
/// \{
|
/// \{
|
||||||
|
|
||||||
/// The maximum supported alignment size (currently 1MiB).
|
/// The maximum supported alignment size (currently 1MiB).
|
||||||
#define MI_ALIGNMENT_MAX (1024*1024UL)
|
#define MI_BLOCK_ALIGNMENT_MAX (1024*1024UL)
|
||||||
|
|
||||||
/// Allocate \a size bytes aligned by \a alignment.
|
/// Allocate \a size bytes aligned by \a alignment.
|
||||||
/// @param size number of bytes to allocate.
|
/// @param size number of bytes to allocate.
|
||||||
/// @param alignment the minimal alignment of the allocated memory. Must be less than #MI_ALIGNMENT_MAX.
|
/// @param alignment the minimal alignment of the allocated memory. Must be less than #MI_BLOCK_ALIGNMENT_MAX.
|
||||||
/// @returns pointer to the allocated memory or \a NULL if out of memory.
|
/// @returns pointer to the allocated memory or \a NULL if out of memory.
|
||||||
/// The returned pointer is aligned by \a alignment, i.e.
|
/// The returned pointer is aligned by \a alignment, i.e.
|
||||||
/// `(uintptr_t)p % alignment == 0`.
|
/// `(uintptr_t)p % alignment == 0`.
|
||||||
|
|
|
@ -193,8 +193,8 @@ typedef int32_t mi_ssize_t;
|
||||||
// Used as a special value to encode block sizes in 32 bits.
|
// Used as a special value to encode block sizes in 32 bits.
|
||||||
#define MI_HUGE_BLOCK_SIZE ((uint32_t)MI_HUGE_OBJ_SIZE_MAX)
|
#define MI_HUGE_BLOCK_SIZE ((uint32_t)MI_HUGE_OBJ_SIZE_MAX)
|
||||||
|
|
||||||
// Alignments over MI_ALIGNMENT_MAX are allocated in dedicated huge page segments
|
// Alignments over MI_BLOCK_ALIGNMENT_MAX are allocated in dedicated huge page segments
|
||||||
#define MI_ALIGNMENT_MAX (MI_SEGMENT_SIZE >> 1)
|
#define MI_BLOCK_ALIGNMENT_MAX (MI_SEGMENT_SIZE >> 1)
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
|
|
|
@ -33,7 +33,7 @@ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_fallback(mi_heap_t*
|
||||||
|
|
||||||
void* p;
|
void* p;
|
||||||
size_t oversize;
|
size_t oversize;
|
||||||
if mi_unlikely(alignment > MI_ALIGNMENT_MAX) {
|
if mi_unlikely(alignment > MI_BLOCK_ALIGNMENT_MAX) {
|
||||||
// use OS allocation for very large alignment and allocate inside a huge page (dedicated segment with 1 page)
|
// use OS allocation for very large alignment and allocate inside a huge page (dedicated segment with 1 page)
|
||||||
// This can support alignments >= MI_SEGMENT_SIZE by ensuring the object can be aligned at a point in the
|
// This can support alignments >= MI_SEGMENT_SIZE by ensuring the object can be aligned at a point in the
|
||||||
// first (and single) page such that the segment info is `MI_SEGMENT_SIZE` bytes before it (so it can be found by aligning the pointer down)
|
// first (and single) page such that the segment info is `MI_SEGMENT_SIZE` bytes before it (so it can be found by aligning the pointer down)
|
||||||
|
@ -75,7 +75,7 @@ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_fallback(mi_heap_t*
|
||||||
mi_assert_internal(mi_usable_size(p) == mi_usable_size(aligned_p)+adjust);
|
mi_assert_internal(mi_usable_size(p) == mi_usable_size(aligned_p)+adjust);
|
||||||
|
|
||||||
// now zero the block if needed
|
// now zero the block if needed
|
||||||
if (alignment > MI_ALIGNMENT_MAX) {
|
if (alignment > MI_BLOCK_ALIGNMENT_MAX) {
|
||||||
// for the tracker, on huge aligned allocations only from the start of the large block is defined
|
// for the tracker, on huge aligned allocations only from the start of the large block is defined
|
||||||
mi_track_mem_undefined(aligned_p, size);
|
mi_track_mem_undefined(aligned_p, size);
|
||||||
if (zero) {
|
if (zero) {
|
||||||
|
|
2
src/os.c
2
src/os.c
|
@ -333,7 +333,7 @@ void* _mi_os_alloc_aligned(size_t size, size_t alignment, bool commit, bool allo
|
||||||
|
|
||||||
/* -----------------------------------------------------------
|
/* -----------------------------------------------------------
|
||||||
OS aligned allocation with an offset. This is used
|
OS aligned allocation with an offset. This is used
|
||||||
for large alignments > MI_ALIGNMENT_MAX. We use a large mimalloc
|
for large alignments > MI_BLOCK_ALIGNMENT_MAX. We use a large mimalloc
|
||||||
page where the object can be aligned at an offset from the start of the segment.
|
page where the object can be aligned at an offset from the start of the segment.
|
||||||
As we may need to overallocate, we need to free such pointers using `mi_free_aligned`
|
As we may need to overallocate, we need to free such pointers using `mi_free_aligned`
|
||||||
to use the actual start of the memory region.
|
to use the actual start of the memory region.
|
||||||
|
|
|
@ -831,7 +831,7 @@ void mi_register_deferred_free(mi_deferred_free_fun* fn, void* arg) mi_attr_noex
|
||||||
// Because huge pages contain just one block, and the segment contains
|
// Because huge pages contain just one block, and the segment contains
|
||||||
// just that page, we always treat them as abandoned and any thread
|
// just that page, we always treat them as abandoned and any thread
|
||||||
// that frees the block can free the whole page and segment directly.
|
// that frees the block can free the whole page and segment directly.
|
||||||
// Huge pages are also use if the requested alignment is very large (> MI_ALIGNMENT_MAX).
|
// Huge pages are also use if the requested alignment is very large (> MI_BLOCK_ALIGNMENT_MAX).
|
||||||
static mi_page_t* mi_huge_page_alloc(mi_heap_t* heap, size_t size, size_t page_alignment) {
|
static mi_page_t* mi_huge_page_alloc(mi_heap_t* heap, size_t size, size_t page_alignment) {
|
||||||
size_t block_size = _mi_os_good_alloc_size(size);
|
size_t block_size = _mi_os_good_alloc_size(size);
|
||||||
mi_assert_internal(mi_bin(block_size) == MI_BIN_HUGE || page_alignment > 0);
|
mi_assert_internal(mi_bin(block_size) == MI_BIN_HUGE || page_alignment > 0);
|
||||||
|
|
|
@ -1189,7 +1189,7 @@ void _mi_segment_huge_page_reset(mi_segment_t* segment, mi_page_t* page, mi_bloc
|
||||||
|
|
||||||
mi_page_t* _mi_segment_page_alloc(mi_heap_t* heap, size_t block_size, size_t page_alignment, mi_segments_tld_t* tld, mi_os_tld_t* os_tld) {
|
mi_page_t* _mi_segment_page_alloc(mi_heap_t* heap, size_t block_size, size_t page_alignment, mi_segments_tld_t* tld, mi_os_tld_t* os_tld) {
|
||||||
mi_page_t* page;
|
mi_page_t* page;
|
||||||
if mi_unlikely(page_alignment > MI_ALIGNMENT_MAX) {
|
if mi_unlikely(page_alignment > MI_BLOCK_ALIGNMENT_MAX) {
|
||||||
mi_assert_internal(_mi_is_power_of_two(page_alignment));
|
mi_assert_internal(_mi_is_power_of_two(page_alignment));
|
||||||
mi_assert_internal(page_alignment >= MI_SEGMENT_SIZE);
|
mi_assert_internal(page_alignment >= MI_SEGMENT_SIZE);
|
||||||
//mi_assert_internal((MI_SEGMENT_SIZE % page_alignment) == 0);
|
//mi_assert_internal((MI_SEGMENT_SIZE % page_alignment) == 0);
|
||||||
|
|
|
@ -34,7 +34,7 @@ we therefore test the API over various inputs. Please add more tests :-)
|
||||||
|
|
||||||
#include "mimalloc.h"
|
#include "mimalloc.h"
|
||||||
// #include "mimalloc/internal.h"
|
// #include "mimalloc/internal.h"
|
||||||
#include "mimalloc/types.h" // for MI_DEBUG and MI_ALIGNMENT_MAX
|
#include "mimalloc/types.h" // for MI_DEBUG and MI_BLOCK_ALIGNMENT_MAX
|
||||||
|
|
||||||
#include "testhelper.h"
|
#include "testhelper.h"
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ int main(void) {
|
||||||
};
|
};
|
||||||
CHECK_BODY("malloc-aligned6") {
|
CHECK_BODY("malloc-aligned6") {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for (size_t align = 1; align <= MI_ALIGNMENT_MAX && ok; align *= 2) {
|
for (size_t align = 1; align <= MI_BLOCK_ALIGNMENT_MAX && ok; align *= 2) {
|
||||||
void* ps[8];
|
void* ps[8];
|
||||||
for (int i = 0; i < 8 && ok; i++) {
|
for (int i = 0; i < 8 && ok; i++) {
|
||||||
ps[i] = mi_malloc_aligned(align*13 // size
|
ps[i] = mi_malloc_aligned(align*13 // size
|
||||||
|
@ -170,16 +170,16 @@ int main(void) {
|
||||||
result = ok;
|
result = ok;
|
||||||
};
|
};
|
||||||
CHECK_BODY("malloc-aligned7") {
|
CHECK_BODY("malloc-aligned7") {
|
||||||
void* p = mi_malloc_aligned(1024,MI_ALIGNMENT_MAX);
|
void* p = mi_malloc_aligned(1024,MI_BLOCK_ALIGNMENT_MAX);
|
||||||
mi_free(p);
|
mi_free(p);
|
||||||
result = ((uintptr_t)p % MI_ALIGNMENT_MAX) == 0;
|
result = ((uintptr_t)p % MI_BLOCK_ALIGNMENT_MAX) == 0;
|
||||||
};
|
};
|
||||||
CHECK_BODY("malloc-aligned8") {
|
CHECK_BODY("malloc-aligned8") {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for (int i = 0; i < 5 && ok; i++) {
|
for (int i = 0; i < 5 && ok; i++) {
|
||||||
int n = (1 << i);
|
int n = (1 << i);
|
||||||
void* p = mi_malloc_aligned(1024, n * MI_ALIGNMENT_MAX);
|
void* p = mi_malloc_aligned(1024, n * MI_BLOCK_ALIGNMENT_MAX);
|
||||||
ok = ((uintptr_t)p % (n*MI_ALIGNMENT_MAX)) == 0;
|
ok = ((uintptr_t)p % (n*MI_BLOCK_ALIGNMENT_MAX)) == 0;
|
||||||
mi_free(p);
|
mi_free(p);
|
||||||
}
|
}
|
||||||
result = ok;
|
result = ok;
|
||||||
|
@ -187,7 +187,7 @@ int main(void) {
|
||||||
CHECK_BODY("malloc-aligned9") {
|
CHECK_BODY("malloc-aligned9") {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
void* p[8];
|
void* p[8];
|
||||||
size_t sizes[8] = { 8, 512, 1024 * 1024, MI_ALIGNMENT_MAX, MI_ALIGNMENT_MAX + 1, 2 * MI_ALIGNMENT_MAX, 8 * MI_ALIGNMENT_MAX, 0 };
|
size_t sizes[8] = { 8, 512, 1024 * 1024, MI_BLOCK_ALIGNMENT_MAX, MI_BLOCK_ALIGNMENT_MAX + 1, 2 * MI_BLOCK_ALIGNMENT_MAX, 8 * MI_BLOCK_ALIGNMENT_MAX, 0 };
|
||||||
for (int i = 0; i < 28 && ok; i++) {
|
for (int i = 0; i < 28 && ok; i++) {
|
||||||
int align = (1 << i);
|
int align = (1 << i);
|
||||||
for (int j = 0; j < 8 && ok; j++) {
|
for (int j = 0; j < 8 && ok; j++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue