Skip to content

Commit 3e32b4c

Browse files
committed
fix OS allocation size tracking in the memid
1 parent 44e370b commit 3e32b4c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

include/mimalloc/internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,10 @@ static inline mi_memid_t _mi_memid_none(void) {
784784
return _mi_memid_create(MI_MEM_NONE);
785785
}
786786

787-
static inline mi_memid_t _mi_memid_create_os(bool committed, bool is_zero, bool is_large) {
787+
static inline mi_memid_t _mi_memid_create_os(void* base, size_t size, bool committed, bool is_zero, bool is_large) {
788788
mi_memid_t memid = _mi_memid_create(MI_MEM_OS);
789+
memid.mem.os.base = base;
790+
memid.mem.os.size = size;
789791
memid.initially_committed = committed;
790792
memid.initially_zero = is_zero;
791793
memid.is_pinned = is_large;

src/os.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void* _mi_os_alloc(size_t size, mi_memid_t* memid) {
339339
bool os_is_zero = false;
340340
void* p = mi_os_prim_alloc(size, 0, true, false, &os_is_large, &os_is_zero);
341341
if (p != NULL) {
342-
*memid = _mi_memid_create_os(true, os_is_zero, os_is_large);
342+
*memid = _mi_memid_create_os(p, size, true, os_is_zero, os_is_large);
343343
}
344344
return p;
345345
}
@@ -357,10 +357,9 @@ void* _mi_os_alloc_aligned(size_t size, size_t alignment, bool commit, bool allo
357357
void* os_base = NULL;
358358
void* p = mi_os_prim_alloc_aligned(size, alignment, commit, allow_large, &os_is_large, &os_is_zero, &os_base );
359359
if (p != NULL) {
360-
*memid = _mi_memid_create_os(commit, os_is_zero, os_is_large);
360+
*memid = _mi_memid_create_os(p, size, commit, os_is_zero, os_is_large);
361361
memid->mem.os.base = os_base;
362-
// memid->mem.os.alignment = alignment;
363-
memid->mem.os.size += ((uint8_t*)p - (uint8_t*)os_base); // todo: return from prim_alloc_aligned
362+
memid->mem.os.size += ((uint8_t*)p - (uint8_t*)os_base); // todo: return from prim_alloc_aligned?
364363
}
365364
return p;
366365
}
@@ -618,7 +617,7 @@ void* _mi_os_alloc_huge_os_pages(size_t pages, int numa_node, mi_msecs_t max_mse
618617
if (psize != NULL) *psize = 0;
619618
if (pages_reserved != NULL) *pages_reserved = 0;
620619
size_t size = 0;
621-
uint8_t* start = mi_os_claim_huge_pages(pages, &size);
620+
uint8_t* const start = mi_os_claim_huge_pages(pages, &size);
622621
if (start == NULL) return NULL; // or 32-bit systems
623622

624623
// Allocate one page at the time but try to place them contiguously
@@ -674,7 +673,7 @@ void* _mi_os_alloc_huge_os_pages(size_t pages, int numa_node, mi_msecs_t max_mse
674673
if (psize != NULL) { *psize = page * MI_HUGE_OS_PAGE_SIZE; }
675674
if (page != 0) {
676675
mi_assert(start != NULL);
677-
*memid = _mi_memid_create_os(true /* is committed */, all_zero, true /* is_large */);
676+
*memid = _mi_memid_create_os(start, size, true /* is committed */, all_zero, true /* is_large */);
678677
memid->memkind = MI_MEM_OS_HUGE;
679678
mi_assert(memid->is_pinned);
680679
#ifdef MI_TRACK_ASAN

0 commit comments

Comments
 (0)