Skip to content

Commit dcbe772

Browse files
committed
new utility to name a region
1 parent ccf117c commit dcbe772

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

include/mimalloc-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void* _mi_os_alloc(size_t size, mi_stats_t* stats); // to allocat
7878
void _mi_os_free(void* p, size_t size, mi_stats_t* stats); // to free thread local data
7979
size_t _mi_os_good_alloc_size(size_t size);
8080
bool _mi_os_has_overcommit(void);
81+
bool _mi_os_alloc_named(void* p, size_t size, const char *name);
8182

8283
// memory.c
8384
void* _mi_mem_alloc_aligned(size_t size, size_t alignment, bool* commit, bool* large, bool* is_pinned, bool* is_zero, size_t* id, mi_os_tld_t* tld);

include/mimalloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_new_n(size_t count, s
380380
mi_decl_nodiscard mi_decl_export void* mi_new_realloc(void* p, size_t newsize) mi_attr_alloc_size(2);
381381
mi_decl_nodiscard mi_decl_export void* mi_new_reallocn(void* p, size_t newcount, size_t size) mi_attr_alloc_size2(2, 3);
382382

383+
mi_decl_export bool mi_alloc_named(void* p, size_t size, const char *name);
384+
383385
#ifdef __cplusplus
384386
}
385387
#endif

src/os.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ terms of the MIT license. A copy of the license can be found in the file
4545
#else
4646
#include <sys/mman.h>
4747
#endif
48+
#include <sys/prctl.h>
4849
#endif
4950
#if defined(__APPLE__)
5051
#include <TargetConditionals.h>
@@ -1437,3 +1438,20 @@ int _mi_os_numa_node_get(mi_os_tld_t* tld) {
14371438
if (numa_node >= numa_count) { numa_node = numa_node % numa_count; }
14381439
return (int)numa_node;
14391440
}
1441+
1442+
bool _mi_os_alloc_named(void* p, size_t size, const char *name) {
1443+
mi_assert_internal(p != NULL);
1444+
mi_assert_internal(name != NULL);
1445+
#if defined(__linux__)
1446+
#if !defined(PR_SET_VMA)
1447+
#define PR_SET_VMA 0x53564d41
1448+
#define PR_SET_VMA_ANON_NAME 0
1449+
#endif
1450+
return (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)p, size, (unsigned long)name) == 0);
1451+
#else
1452+
MI_UNUSED(p);
1453+
MI_UNUSED(size);
1454+
MI_UNUSED(name);
1455+
return false;
1456+
#endif
1457+
}

src/page.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,7 @@ void* _mi_malloc_generic(mi_heap_t* heap, size_t size) mi_attr_noexcept
852852
// and try again, this time succeeding! (i.e. this should never recurse)
853853
return _mi_page_malloc(heap, page, size);
854854
}
855+
856+
bool mi_alloc_named(void* p, size_t size, const char *name) {
857+
return _mi_os_alloc_named(p, size, name);
858+
}

src/region.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ static bool mi_memid_is_arena(size_t id, mem_region_t** region, mi_bitmap_index_
164164
}
165165
}
166166

167-
168167
/* ----------------------------------------------------------------------------
169168
Allocate a region is allocated from the OS (or an arena)
170169
-----------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)