Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ if (MI_BUILD_TESTS)
enable_testing()

# static link tests
foreach(TEST_NAME api api-fill stress)
foreach(TEST_NAME api api-fill stress large-arena-alloc)
add_executable(mimalloc-test-${TEST_NAME} test/test-${TEST_NAME}.c)
target_compile_definitions(mimalloc-test-${TEST_NAME} PRIVATE ${mi_defines})
target_compile_options(mimalloc-test-${TEST_NAME} PRIVATE ${mi_cflags})
Expand Down
2 changes: 0 additions & 2 deletions src/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,11 @@ bool _mi_bitmap_try_find_from_claim_across(mi_bitmap_t bitmap, const size_t bitm
for (size_t visited = 0; visited < bitmap_fields; visited++, idx++) {
if (idx >= bitmap_fields) { idx = 0; } // wrap
// first try to claim inside a field
/*
if (count <= MI_BITMAP_FIELD_BITS) {
if (_mi_bitmap_try_find_claim_field(bitmap, idx, count, bitmap_idx)) {
return true;
}
}
*/
// if that fails, then try to claim across fields
if (mi_bitmap_try_find_claim_field_across(bitmap, bitmap_fields, idx, count, 0, bitmap_idx)) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ target_link_libraries(static-override-cxx PUBLIC mimalloc-static)
## test memory errors
add_executable(test-wrong test-wrong.c)
target_link_libraries(test-wrong PUBLIC mimalloc)

## test large memory allocations in a preallocated arena
add_executable(test-large-arena-alloc test-large-arena-alloc.c)
target_link_libraries(test-large-arena-alloc PUBLIC mimalloc)
30 changes: 30 additions & 0 deletions test/test-large-arena-alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Issue #1142: Test that allocating large amounts of memory (3+ bits in the bitmap)
// uses the preallocated arena when a large enough arena is provided.
#include <stdio.h>
#include <mimalloc.h>

#define ARENA_SIZE (256 * 1024 * 1024)
#define ALLOC_SIZE (64 * 1024 * 1024)

char memory[ARENA_SIZE] = {0};

int main(void) {
mi_option_set_enabled(mi_option_disallow_os_alloc, true);
mi_option_set_enabled(mi_option_verbose, true);

mi_manage_os_memory(
memory,
sizeof(memory),
1 /* committed */,
0 /* large */,
0 /* zero */,
-1 /* numa_node */
);

void * ptr = mi_malloc(ALLOC_SIZE);

fprintf(stderr, "ptr = %p\n", ptr);

mi_option_set_enabled(mi_option_verbose, false);
return ptr ? 0 : 1;
}