diff --git a/HISTORY b/HISTORY index 6c89b46..dc0b7e8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.54 2021-08-06 + * fast_allocator.[hc]: correct reclaim_interval logic + Version 1.53 2021-06-30 * process_action support action status * uniq_skiplist.h: add function uniq_skiplist_iterator_at diff --git a/src/fast_allocator.c b/src/fast_allocator.c index 9179ea7..dd7c793 100644 --- a/src/fast_allocator.c +++ b/src/fast_allocator.c @@ -450,7 +450,7 @@ void *fast_allocator_alloc(struct fast_allocator_context *acontext, ptr = fast_mblock_alloc_object(&allocator_info->mblock); if (ptr == NULL) { - if (acontext->allocator_array.reclaim_interval <= 0) + if (acontext->allocator_array.reclaim_interval < 0) { return NULL; } diff --git a/src/fast_allocator.h b/src/fast_allocator.h index f52bc67..3627bc3 100644 --- a/src/fast_allocator.h +++ b/src/fast_allocator.h @@ -47,10 +47,10 @@ struct fast_allocator_array { int count; int alloc; - int reclaim_interval; //<= 0 for never reclaim + int reclaim_interval; //< 0 for never reclaim int last_reclaim_time; volatile int64_t malloc_bytes; //total alloc bytes - int64_t malloc_bytes_limit; //water mark bytes for malloc + int64_t malloc_bytes_limit; //water mark bytes for malloc double expect_usage_ratio; struct fast_allocator_info **allocators; }; @@ -69,10 +69,10 @@ struct fast_allocator_context #define FAST_ALLOCATOR_INIT_REGION(region, _start, _end, _step, _alloc_once) \ do { \ - region.start = _start; \ - region.end = _end; \ - region.step = _step; \ - region.alloc_elements_once = _alloc_once; \ + (region).start = _start; \ + (region).end = _end; \ + (region).step = _step; \ + (region).alloc_elements_once = _alloc_once; \ } while(0) #ifdef __cplusplus @@ -86,7 +86,7 @@ parameters: mblock_name_prefix: the name prefix of mblock alloc_bytes_limit: the alloc limit, 0 for no limit expect_usage_ratio: the trunk usage ratio - reclaim_interval: reclaim interval in second, 0 for never reclaim + reclaim_interval: reclaim interval in second, < 0 for never reclaim need_lock: if need lock return error no, 0 for success, != 0 fail */ @@ -103,7 +103,7 @@ parameters: region_count: the region count alloc_bytes_limit: the alloc limit, 0 for no limit expect_usage_ratio: the trunk usage ratio - reclaim_interval: reclaim interval in second, 0 for never reclaim + reclaim_interval: reclaim interval in second, < 0 for never reclaim need_lock: if need lock return error no, 0 for success, != 0 fail */