From 0806435fcce53a92ecfc39a3d192336f85644160 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Mon, 15 May 2023 15:10:01 +0800 Subject: [PATCH] fast_allocator.c adapt fast_mblock_malloc_trunk_notify_func --- HISTORY | 3 ++- src/fast_allocator.c | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/HISTORY b/HISTORY index fc85850..d01644e 100644 --- a/HISTORY +++ b/HISTORY @@ -1,9 +1,10 @@ -Version 1.66 2023-05-08 +Version 1.66 2023-05-15 * struct fast_task_info add field: notify_next for nio notify queue * lc_pair in struct fc_queue change to lcp * sorted queue use double link chain for quick push * add function uniq_skiplist_clear + * fast_mblock_malloc_trunk_notify_func prototype changed Version 1.65 2023-01-09 * locked_list.h: add functions locked_list_move and locked_list_move_tail diff --git a/src/fast_allocator.c b/src/fast_allocator.c index 9d3870f..8e5ad9e 100644 --- a/src/fast_allocator.c +++ b/src/fast_allocator.c @@ -55,17 +55,19 @@ static int fast_allocator_malloc_trunk_check(const int alloc_bytes, void *args) acontext->allocator_array.malloc_bytes_limit ? 0 : EOVERFLOW; } -static void fast_allocator_malloc_trunk_notify_func(const int alloc_bytes, void *args) +static void fast_allocator_malloc_trunk_notify_func( + const enum fast_mblock_notify_type type, + const struct fast_mblock_malloc *node, void *args) { - if (alloc_bytes > 0) + if (type == fast_mblock_notify_type_alloc) { __sync_add_and_fetch(&((struct fast_allocator_context *)args)-> - allocator_array.malloc_bytes, alloc_bytes); + allocator_array.malloc_bytes, node->trunk_size); } else { __sync_sub_and_fetch(&((struct fast_allocator_context *)args)-> - allocator_array.malloc_bytes, -1 * alloc_bytes); + allocator_array.malloc_bytes, node->trunk_size); } } @@ -459,6 +461,15 @@ int fast_allocator_retry_reclaim(struct fast_allocator_context *acontext, return *total_reclaim_bytes > 0 ? 0 : EAGAIN; } +static inline void malloc_trunk_notify( + const enum fast_mblock_notify_type type, + const int alloc_bytes, void *args) +{ + struct fast_mblock_malloc node; + node.trunk_size = alloc_bytes; + fast_allocator_malloc_trunk_notify_func(type, &node, args); +} + void *fast_allocator_alloc(struct fast_allocator_context *acontext, const int bytes) { @@ -512,7 +523,8 @@ void *fast_allocator_alloc(struct fast_allocator_context *acontext, { return NULL; } - fast_allocator_malloc_trunk_notify_func(alloc_bytes, acontext); + malloc_trunk_notify(fast_mblock_notify_type_alloc, + alloc_bytes, acontext); obj = (char *)ptr + sizeof(struct fast_allocator_wrapper); if (acontext->allocator_array.allocators[0]->mblock. @@ -576,7 +588,7 @@ void fast_allocator_free(struct fast_allocator_context *acontext, void *obj) } else { - fast_allocator_malloc_trunk_notify_func(-1 * + malloc_trunk_notify(fast_mblock_notify_type_reclaim, pWrapper->alloc_bytes, acontext); if (acontext->allocator_array.allocators[0]->mblock.