mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-01 17:24:38 +03:00
improve handling of commit failure in arena allocation
This commit is contained in:
parent
d8b7456a1f
commit
6cfc8ad9d0
1 changed files with 14 additions and 13 deletions
27
src/arena.c
27
src/arena.c
|
@ -200,20 +200,21 @@ static mi_decl_noinline void* mi_arena_try_alloc_at(
|
||||||
// now actually commit
|
// now actually commit
|
||||||
bool commit_zero = false;
|
bool commit_zero = false;
|
||||||
if (!mi_arena_commit(arena, p, mi_size_of_slices(slice_count), &commit_zero, mi_size_of_slices(slice_count - already_committed_count))) {
|
if (!mi_arena_commit(arena, p, mi_size_of_slices(slice_count), &commit_zero, mi_size_of_slices(slice_count - already_committed_count))) {
|
||||||
memid->initially_committed = false;
|
// if the commit fails, we roll back
|
||||||
|
_mi_arenas_free( p, mi_size_of_slices(slice_count), *memid); // this will uncommit as well
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// committed
|
// committed
|
||||||
if (commit_zero) { memid->initially_zero = true; }
|
if (commit_zero) { memid->initially_zero = true; }
|
||||||
#if MI_DEBUG > 1
|
#if MI_DEBUG > 1
|
||||||
if (memid->initially_zero) {
|
if (memid->initially_zero) {
|
||||||
if (!mi_mem_is_zero(p, mi_size_of_slices(slice_count))) {
|
if (!mi_mem_is_zero(p, mi_size_of_slices(slice_count))) {
|
||||||
_mi_error_message(EFAULT, "interal error: arena allocation was not zero-initialized!\n");
|
_mi_error_message(EFAULT, "interal error: arena allocation was not zero-initialized!\n");
|
||||||
memid->initially_zero = false;
|
memid->initially_zero = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// already fully committed.
|
// already fully committed.
|
||||||
|
@ -233,8 +234,7 @@ static mi_decl_noinline void* mi_arena_try_alloc_at(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// no need to commit, but check if already fully committed
|
// no need to commit, but check if it is already fully committed
|
||||||
// commit requested, but the range may not be committed as a whole: ensure it is committed now
|
|
||||||
memid->initially_committed = mi_bitmap_is_setN(arena->slices_committed, slice_index, slice_count);
|
memid->initially_committed = mi_bitmap_is_setN(arena->slices_committed, slice_index, slice_count);
|
||||||
if (!memid->initially_committed) {
|
if (!memid->initially_committed) {
|
||||||
// partly committed.. adjust stats
|
// partly committed.. adjust stats
|
||||||
|
@ -247,6 +247,7 @@ static mi_decl_noinline void* mi_arena_try_alloc_at(
|
||||||
|
|
||||||
mi_assert_internal(mi_bbitmap_is_clearN(arena->slices_free, slice_index, slice_count));
|
mi_assert_internal(mi_bbitmap_is_clearN(arena->slices_free, slice_index, slice_count));
|
||||||
if (commit) { mi_assert_internal(mi_bitmap_is_setN(arena->slices_committed, slice_index, slice_count)); }
|
if (commit) { mi_assert_internal(mi_bitmap_is_setN(arena->slices_committed, slice_index, slice_count)); }
|
||||||
|
if (commit) { mi_assert_internal(memid->initially_committed); }
|
||||||
mi_assert_internal(mi_bitmap_is_setN(arena->slices_dirty, slice_index, slice_count));
|
mi_assert_internal(mi_bitmap_is_setN(arena->slices_dirty, slice_index, slice_count));
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|
Loading…
Add table
Reference in a new issue