Skip to content

Commit

Permalink
new utility to name a region
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Apr 2, 2022
1 parent ccf117c commit 27bddd5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/mimalloc-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void* _mi_os_alloc(size_t size, mi_stats_t* stats); // to allocat
void _mi_os_free(void* p, size_t size, mi_stats_t* stats); // to free thread local data
size_t _mi_os_good_alloc_size(size_t size);
bool _mi_os_has_overcommit(void);
bool _mi_os_alloc_named(void* p, size_t size, const char *name);

// memory.c
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);
Expand Down
2 changes: 2 additions & 0 deletions include/mimalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ mi_decl_nodiscard mi_decl_export mi_decl_restrict void* mi_new_n(size_t count, s
mi_decl_nodiscard mi_decl_export void* mi_new_realloc(void* p, size_t newsize) mi_attr_alloc_size(2);
mi_decl_nodiscard mi_decl_export void* mi_new_reallocn(void* p, size_t newcount, size_t size) mi_attr_alloc_size2(2, 3);

mi_decl_export bool mi_alloc_named(void* p, size_t size, const char *name);

#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 15 additions & 0 deletions src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ terms of the MIT license. A copy of the license can be found in the file
#else
#include <sys/mman.h>
#endif
#include <sys/prctl.h>
#endif
#if defined(__APPLE__)
#include <TargetConditionals.h>
Expand Down Expand Up @@ -1437,3 +1438,17 @@ int _mi_os_numa_node_get(mi_os_tld_t* tld) {
if (numa_node >= numa_count) { numa_node = numa_node % numa_count; }
return (int)numa_node;
}

bool _mi_os_alloc_named(void* p, size_t size, const char *name) {
mi_assert_internal(p != NULL);
mi_assert_internal(name != NULL);
#if defined(__linux__)
#if !defined(PR_SET_VMA)
#define PR_SET_VMA 0x53564d41
#define PR_SET_VMA_ANON_NAME 0
return (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p, size, name) == 0);
#endif
#else
return false;
#endif
}
4 changes: 4 additions & 0 deletions src/page.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,7 @@ void* _mi_malloc_generic(mi_heap_t* heap, size_t size) mi_attr_noexcept
// and try again, this time succeeding! (i.e. this should never recurse)
return _mi_page_malloc(heap, page, size);
}

bool mi_alloc_named(void* p, size_t size, const char *name) {
return _mi_os_alloc_named(p, size, name);
}
1 change: 0 additions & 1 deletion src/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ static bool mi_memid_is_arena(size_t id, mem_region_t** region, mi_bitmap_index_
}
}


/* ----------------------------------------------------------------------------
Allocate a region is allocated from the OS (or an arena)
-----------------------------------------------------------------------------*/
Expand Down

0 comments on commit 27bddd5

Please sign in to comment.