From a6b40c77023c8667890d98762989e2e6cb3dc99c Mon Sep 17 00:00:00 2001 From: kanoi Date: Fri, 29 Aug 2014 17:39:54 +1000 Subject: [PATCH] ckdb - add klist cull to reduce a list to minimum - and cull transfer --- src/ckdb.c | 5 ++++- src/klist.c | 33 +++++++++++++++++++++++++++++++++ src/klist.h | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/ckdb.c b/src/ckdb.c index f06c85b5..05abe8d1 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -9685,8 +9685,11 @@ static void *socketer(__maybe_unused void *arg) } K_WLOCK(transfer_free); k_list_transfer_to_head(trf_store, transfer_free); - K_WUNLOCK(transfer_free); trf_store = k_free_store(trf_store); + if (transfer_free->count == transfer_free->total && + transfer_free->total > ALLOC_TRANSFER * 16) + k_cull_list(transfer_free); + K_WUNLOCK(transfer_free); } } diff --git a/src/klist.c b/src/klist.c index adca979e..aef01127 100644 --- a/src/klist.c +++ b/src/klist.c @@ -378,3 +378,36 @@ K_STORE *_k_free_store(K_STORE *store, KLIST_FFL_ARGS) return NULL; } + +// Must be locked and none in use and/or unlinked +void _k_cull_list(K_LIST *list, KLIST_FFL_ARGS) +{ + int i; + + if (list->is_store) { + quithere(1, "List %s can't %s() a store" KLIST_FFL, + list->name, __func__, KLIST_FFL_PASS); + } + + if (list->count != list->total) { + quithere(1, "List %s can't %s() a list in use" KLIST_FFL, + list->name, __func__, KLIST_FFL_PASS); + } + + for (i = 0; i < list->item_mem_count; i++) + free(list->item_memory[i]); + free(list->item_memory); + list->item_memory = NULL; + list->item_mem_count = 0; + + for (i = 0; i < list->data_mem_count; i++) + free(list->data_memory[i]); + free(list->data_memory); + list->data_memory = NULL; + list->data_mem_count = 0; + + list->total = list->count = list->count_up = 0; + list->head = list->tail = NULL; + + k_alloc_items(list, KLIST_FFL_PASS); +} diff --git a/src/klist.h b/src/klist.h index 4621b487..51f63fd6 100644 --- a/src/klist.h +++ b/src/klist.h @@ -94,5 +94,7 @@ extern K_LIST *_k_free_list(K_LIST *list, KLIST_FFL_ARGS); #define k_free_list(_list) _k_free_list(_list, KLIST_FFL_HERE) extern K_STORE *_k_free_store(K_STORE *store, KLIST_FFL_ARGS); #define k_free_store(_store) _k_free_store(_store, KLIST_FFL_HERE) +extern void _k_cull_list(K_LIST *list, KLIST_FFL_ARGS); +#define k_cull_list(_list) _k_cull_list(_list, KLIST_FFL_HERE) #endif