mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
remove is_large member (and use is_pinned for this)
This commit is contained in:
parent
657135de36
commit
88d8ee964f
4 changed files with 17 additions and 21 deletions
|
@ -431,12 +431,11 @@ int mi_reserve_os_memory(size_t size, bool commit, bool allow_large);
|
||||||
/// @param start Start of the memory area
|
/// @param start Start of the memory area
|
||||||
/// @param size The size of the memory area.
|
/// @param size The size of the memory area.
|
||||||
/// @param is_committed Is the area already committed?
|
/// @param is_committed Is the area already committed?
|
||||||
/// @param is_large Does it consist of large OS pages? Set this to \a true as well for memory
|
/// @param is_pinned Can the memory not be decommitted or reset? (usually the case for large OS pages)
|
||||||
/// that should not be decommitted or protected (like rdma etc.)
|
|
||||||
/// @param is_zero Does the area consists of zero's?
|
/// @param is_zero Does the area consists of zero's?
|
||||||
/// @param numa_node Possible associated numa node or `-1`.
|
/// @param numa_node Possible associated numa node or `-1`.
|
||||||
/// @return \a true if successful, and \a false on error.
|
/// @return \a true if successful, and \a false on error.
|
||||||
bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node);
|
bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node);
|
||||||
|
|
||||||
/// Reserve \a pages of huge OS pages (1GiB) evenly divided over \a numa_nodes nodes,
|
/// Reserve \a pages of huge OS pages (1GiB) evenly divided over \a numa_nodes nodes,
|
||||||
/// but stops after at most `timeout_msecs` seconds.
|
/// but stops after at most `timeout_msecs` seconds.
|
||||||
|
|
|
@ -274,7 +274,7 @@ mi_decl_export int mi_reserve_huge_os_pages_interleave(size_t pages, size_t numa
|
||||||
mi_decl_export int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs) mi_attr_noexcept;
|
mi_decl_export int mi_reserve_huge_os_pages_at(size_t pages, int numa_node, size_t timeout_msecs) mi_attr_noexcept;
|
||||||
|
|
||||||
mi_decl_export int mi_reserve_os_memory(size_t size, bool commit, bool allow_large) mi_attr_noexcept;
|
mi_decl_export int mi_reserve_os_memory(size_t size, bool commit, bool allow_large) mi_attr_noexcept;
|
||||||
mi_decl_export 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;
|
mi_decl_export bool mi_manage_os_memory(void* start, size_t size, bool is_committed, bool is_pinned /* cannot decommit/reset? */, bool is_zero, int numa_node) mi_attr_noexcept;
|
||||||
|
|
||||||
mi_decl_export void mi_debug_show_arenas(bool show_pages, bool show_inuse, bool show_committed) mi_attr_noexcept;
|
mi_decl_export void mi_debug_show_arenas(bool show_pages, bool show_inuse, bool show_committed) mi_attr_noexcept;
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ typedef void* mi_arena_id_t;
|
||||||
mi_decl_export void* mi_arena_area(mi_arena_id_t arena_id, size_t* size);
|
mi_decl_export void* mi_arena_area(mi_arena_id_t arena_id, size_t* size);
|
||||||
mi_decl_export int mi_reserve_huge_os_pages_at_ex(size_t pages, int numa_node, size_t timeout_msecs, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept;
|
mi_decl_export int mi_reserve_huge_os_pages_at_ex(size_t pages, int numa_node, size_t timeout_msecs, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept;
|
||||||
mi_decl_export int mi_reserve_os_memory_ex(size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept;
|
mi_decl_export int mi_reserve_os_memory_ex(size_t size, bool commit, bool allow_large, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept;
|
||||||
mi_decl_export bool mi_manage_os_memory_ex(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept;
|
mi_decl_export bool mi_manage_os_memory_ex(void* start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept;
|
||||||
|
|
||||||
#if MI_MALLOC_VERSION >= 182
|
#if MI_MALLOC_VERSION >= 182
|
||||||
// Create a heap that only allocates in the specified arena
|
// Create a heap that only allocates in the specified arena
|
||||||
|
|
|
@ -143,8 +143,8 @@ mi_arena_id_t _mi_arena_id_none(void);
|
||||||
mi_arena_t* _mi_arena_from_id(mi_arena_id_t id);
|
mi_arena_t* _mi_arena_from_id(mi_arena_id_t id);
|
||||||
bool _mi_arena_memid_is_suitable(mi_memid_t memid, mi_arena_t* request_arena);
|
bool _mi_arena_memid_is_suitable(mi_memid_t memid, mi_arena_t* request_arena);
|
||||||
|
|
||||||
void* _mi_arenas_alloc(mi_subproc_t* subproc, size_t size, bool commit, bool allow_large, mi_arena_t* req_arena, size_t tseq, mi_memid_t* memid);
|
void* _mi_arenas_alloc(mi_subproc_t* subproc, size_t size, bool commit, bool allow_pinned, mi_arena_t* req_arena, size_t tseq, mi_memid_t* memid);
|
||||||
void* _mi_arenas_alloc_aligned(mi_subproc_t* subproc, size_t size, size_t alignment, size_t align_offset, bool commit, bool allow_large, mi_arena_t* req_arena, size_t tseq, mi_memid_t* memid);
|
void* _mi_arenas_alloc_aligned(mi_subproc_t* subproc, size_t size, size_t alignment, size_t align_offset, bool commit, bool allow_pinned, mi_arena_t* req_arena, size_t tseq, mi_memid_t* memid);
|
||||||
void _mi_arenas_free(void* p, size_t size, mi_memid_t memid);
|
void _mi_arenas_free(void* p, size_t size, mi_memid_t memid);
|
||||||
bool _mi_arenas_contain(const void* p);
|
bool _mi_arenas_contain(const void* p);
|
||||||
void _mi_arenas_collect(bool force_purge, mi_tld_t* tld);
|
void _mi_arenas_collect(bool force_purge, mi_tld_t* tld);
|
||||||
|
|
21
src/arena.c
21
src/arena.c
|
@ -41,7 +41,6 @@ typedef struct mi_arena_s {
|
||||||
size_t info_slices; // initial slices reserved for the arena bitmaps
|
size_t info_slices; // initial slices reserved for the arena bitmaps
|
||||||
int numa_node; // associated NUMA node
|
int numa_node; // associated NUMA node
|
||||||
bool is_exclusive; // only allow allocations if specifically for this arena
|
bool is_exclusive; // only allow allocations if specifically for this arena
|
||||||
bool is_large; // memory area consists of large- or huge OS pages (always committed)
|
|
||||||
_Atomic(mi_msecs_t) purge_expire; // expiration time when slices can be purged from `slices_purge`.
|
_Atomic(mi_msecs_t) purge_expire; // expiration time when slices can be purged from `slices_purge`.
|
||||||
|
|
||||||
mi_bitmap_t* slices_free; // is the slice free?
|
mi_bitmap_t* slices_free; // is the slice free?
|
||||||
|
@ -333,8 +332,8 @@ static bool mi_arena_reserve(mi_subproc_t* subproc, size_t req_size, bool allow_
|
||||||
Arena iteration
|
Arena iteration
|
||||||
----------------------------------------------------------- */
|
----------------------------------------------------------- */
|
||||||
|
|
||||||
static inline bool mi_arena_is_suitable(mi_arena_t* arena, mi_arena_t* req_arena, int numa_node, bool allow_large) {
|
static inline bool mi_arena_is_suitable(mi_arena_t* arena, mi_arena_t* req_arena, int numa_node, bool allow_pinned) {
|
||||||
if (!allow_large && arena->is_large) return false;
|
if (!allow_pinned && arena->memid.is_pinned) return false;
|
||||||
if (!mi_arena_id_is_suitable(arena, req_arena)) return false;
|
if (!mi_arena_id_is_suitable(arena, req_arena)) return false;
|
||||||
if (req_arena == NULL) { // if not specific, check numa affinity
|
if (req_arena == NULL) { // if not specific, check numa affinity
|
||||||
const bool numa_suitable = (numa_node < 0 || arena->numa_node < 0 || arena->numa_node == numa_node);
|
const bool numa_suitable = (numa_node < 0 || arena->numa_node < 0 || arena->numa_node == numa_node);
|
||||||
|
@ -1104,7 +1103,7 @@ static mi_bitmap_t* mi_arena_bitmap_init(size_t slice_count, uint8_t** base) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool mi_manage_os_memory_ex2(mi_subproc_t* subproc, void* start, size_t size, bool is_large, int numa_node, bool exclusive, mi_memid_t memid, mi_arena_id_t* arena_id) mi_attr_noexcept
|
static bool mi_manage_os_memory_ex2(mi_subproc_t* subproc, void* start, size_t size, int numa_node, bool exclusive, mi_memid_t memid, mi_arena_id_t* arena_id) mi_attr_noexcept
|
||||||
{
|
{
|
||||||
mi_assert(!is_large || (memid.initially_committed && memid.is_pinned));
|
mi_assert(!is_large || (memid.initially_committed && memid.is_pinned));
|
||||||
mi_assert(_mi_is_aligned(start,MI_ARENA_SLICE_SIZE));
|
mi_assert(_mi_is_aligned(start,MI_ARENA_SLICE_SIZE));
|
||||||
|
@ -1155,7 +1154,6 @@ static bool mi_manage_os_memory_ex2(mi_subproc_t* subproc, void* start, size_t s
|
||||||
arena->slice_count = slice_count;
|
arena->slice_count = slice_count;
|
||||||
arena->info_slices = info_slices;
|
arena->info_slices = info_slices;
|
||||||
arena->numa_node = numa_node; // TODO: or get the current numa node if -1? (now it allows anyone to allocate on -1)
|
arena->numa_node = numa_node; // TODO: or get the current numa node if -1? (now it allows anyone to allocate on -1)
|
||||||
arena->is_large = is_large;
|
|
||||||
arena->purge_expire = 0;
|
arena->purge_expire = 0;
|
||||||
// mi_lock_init(&arena->abandoned_visit_lock);
|
// mi_lock_init(&arena->abandoned_visit_lock);
|
||||||
|
|
||||||
|
@ -1190,14 +1188,14 @@ static bool mi_manage_os_memory_ex2(mi_subproc_t* subproc, void* start, size_t s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool mi_manage_os_memory_ex(void* start, size_t size, bool is_committed, bool is_large, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept {
|
bool mi_manage_os_memory_ex(void* start, size_t size, bool is_committed, bool is_pinned, bool is_zero, int numa_node, bool exclusive, mi_arena_id_t* arena_id) mi_attr_noexcept {
|
||||||
mi_memid_t memid = _mi_memid_create(MI_MEM_EXTERNAL);
|
mi_memid_t memid = _mi_memid_create(MI_MEM_EXTERNAL);
|
||||||
memid.mem.os.base = start;
|
memid.mem.os.base = start;
|
||||||
memid.mem.os.size = size;
|
memid.mem.os.size = size;
|
||||||
memid.initially_committed = is_committed;
|
memid.initially_committed = is_committed;
|
||||||
memid.initially_zero = is_zero;
|
memid.initially_zero = is_zero;
|
||||||
memid.is_pinned = is_large;
|
memid.is_pinned = is_pinned;
|
||||||
return mi_manage_os_memory_ex2(_mi_subproc(), start, size, is_large, numa_node, exclusive, memid, arena_id);
|
return mi_manage_os_memory_ex2(_mi_subproc(), start, size, numa_node, exclusive, memid, arena_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserve a range of regular OS memory
|
// Reserve a range of regular OS memory
|
||||||
|
@ -1207,13 +1205,12 @@ static int mi_reserve_os_memory_ex2(mi_subproc_t* subproc, size_t size, bool com
|
||||||
mi_memid_t memid;
|
mi_memid_t memid;
|
||||||
void* start = _mi_os_alloc_aligned(size, MI_ARENA_SLICE_ALIGN, commit, allow_large, &memid);
|
void* start = _mi_os_alloc_aligned(size, MI_ARENA_SLICE_ALIGN, commit, allow_large, &memid);
|
||||||
if (start == NULL) return ENOMEM;
|
if (start == NULL) return ENOMEM;
|
||||||
const bool is_large = memid.is_pinned; // todo: use separate is_large field?
|
if (!mi_manage_os_memory_ex2(subproc, start, size, -1 /* numa node */, exclusive, memid, arena_id)) {
|
||||||
if (!mi_manage_os_memory_ex2(subproc, start, size, is_large, -1 /* numa node */, exclusive, memid, arena_id)) {
|
|
||||||
_mi_os_free_ex(start, size, commit, memid);
|
_mi_os_free_ex(start, size, commit, memid);
|
||||||
_mi_verbose_message("failed to reserve %zu KiB memory\n", _mi_divide_up(size, 1024));
|
_mi_verbose_message("failed to reserve %zu KiB memory\n", _mi_divide_up(size, 1024));
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
_mi_verbose_message("reserved %zu KiB memory%s\n", _mi_divide_up(size, 1024), is_large ? " (in large os pages)" : "");
|
_mi_verbose_message("reserved %zu KiB memory%s\n", _mi_divide_up(size, 1024), memid.is_pinned ? " (in large os pages)" : "");
|
||||||
// mi_debug_show_arenas(true, true, false);
|
// mi_debug_show_arenas(true, true, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1373,7 +1370,7 @@ int mi_reserve_huge_os_pages_at_ex(size_t pages, int numa_node, size_t timeout_m
|
||||||
}
|
}
|
||||||
_mi_verbose_message("numa node %i: reserved %zu GiB huge pages (of the %zu GiB requested)\n", numa_node, pages_reserved, pages);
|
_mi_verbose_message("numa node %i: reserved %zu GiB huge pages (of the %zu GiB requested)\n", numa_node, pages_reserved, pages);
|
||||||
|
|
||||||
if (!mi_manage_os_memory_ex2(_mi_subproc(), p, hsize, true, numa_node, exclusive, memid, arena_id)) {
|
if (!mi_manage_os_memory_ex2(_mi_subproc(), p, hsize, numa_node, exclusive, memid, arena_id)) {
|
||||||
_mi_os_free(p, hsize, memid);
|
_mi_os_free(p, hsize, memid);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue