summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arena.c6
-rw-r--r--src/init.c4
-rw-r--r--src/stats.c4
-rw-r--r--test/test-api.c1
4 files changed, 10 insertions, 5 deletions
diff --git a/src/arena.c b/src/arena.c
index 57ef5f6..ccf64ba 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -297,12 +297,14 @@ static bool mi_arena_add(mi_arena_t* arena) {
bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node) mi_attr_noexcept
{
+ if (size < MI_ARENA_BLOCK_SIZE) return false;
+
if (is_large) {
mi_assert_internal(is_committed);
is_committed = true;
}
- const size_t bcount = mi_block_count_of_size(size);
+ const size_t bcount = size / MI_ARENA_BLOCK_SIZE;
const size_t fields = _mi_divide_up(bcount, MI_BITMAP_FIELD_BITS);
const size_t bitmaps = (is_committed ? 2 : 3);
const size_t asize = sizeof(mi_arena_t) + (bitmaps*fields*sizeof(mi_bitmap_field_t));
@@ -340,7 +342,7 @@ bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_la
// Reserve a range of regular OS memory
int mi_reserve_os_memory(size_t size, bool commit, bool allow_large) mi_attr_noexcept
{
- size = _mi_os_good_alloc_size(size);
+ size = _mi_align_up(size, MI_ARENA_BLOCK_SIZE); // at least one block
bool large = allow_large;
void* start = _mi_os_alloc_aligned(size, MI_SEGMENT_ALIGN, commit, &large, &_mi_stats_main);
if (start==NULL) return ENOMEM;
diff --git a/src/init.c b/src/init.c
index e957559..d1fe35f 100644
--- a/src/init.c
+++ b/src/init.c
@@ -526,7 +526,9 @@ void mi_process_init(void) mi_attr_noexcept {
}
if (mi_option_is_enabled(mi_option_reserve_os_memory)) {
long ksize = mi_option_get(mi_option_reserve_os_memory);
- if (ksize > 0) mi_reserve_os_memory((size_t)ksize*KiB, true /* commit? */, true /* allow large pages? */);
+ if (ksize > 0) {
+ mi_reserve_os_memory((size_t)ksize*KiB, true /* commit? */, true /* allow large pages? */);
+ }
}
}
diff --git a/src/stats.c b/src/stats.c
index e5e26f7..468d5bd 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -153,8 +153,8 @@ static void mi_printf_amount(int64_t n, int64_t unit, mi_output_fun* out, void*
const int64_t tens = (n / (divider/10));
const long whole = (long)(tens/10);
const long frac1 = (long)(tens%10);
- char unitdesc[16];
- snprintf(unitdesc, 16, "%s%s%s", magnitude, (base==1024 ? "i" : ""), suffix);
+ char unitdesc[8];
+ snprintf(unitdesc, 8, "%s%s%s", magnitude, (base==1024 ? "i" : ""), suffix);
snprintf(buf, len, "%ld.%ld %-3s", whole, (frac1 < 0 ? -frac1 : frac1), unitdesc);
}
_mi_fprintf(out, arg, (fmt==NULL ? "%11s" : fmt), buf);
diff --git a/test/test-api.c b/test/test-api.c
index 55c8043..f72cfaf 100644
--- a/test/test-api.c
+++ b/test/test-api.c
@@ -4,6 +4,7 @@ This is free software; you can redistribute it and/or modify it under the
terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/
+#pragma GCC diagnostic ignored "-Walloc-size-larger-than="
/*
Testing allocators is difficult as bugs may only surface after particular