Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new utility to name a region #569

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 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,20 @@ 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
#endif
return (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)p, size, (unsigned long)name) == 0);
#else
MI_UNUSED(p);
MI_UNUSED(size);
MI_UNUSED(name);
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