From a027931a2c1da83c838cccfeaa1114aaa4ec364b Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Tue, 5 May 2015 14:14:26 +0200 Subject: [PATCH] init: simplify the case that the freelist is full in iscsi_sfree if the freelist gets full we are likely in a low load situation so we do not need to make all the work copying the pointers. Signed-off-by: Peter Lieven --- lib/init.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/init.c b/lib/init.c index 0f40468..5a867e1 100644 --- a/lib/init.c +++ b/lib/init.c @@ -94,24 +94,15 @@ void iscsi_sfree(struct iscsi_context *iscsi, void* ptr) { if (ptr == NULL) { return; } - if (iscsi->cache_allocations) { - if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) { - int i; - /* SMALL_ALLOC_MAX_FREE should be adjusted that this */ - /* happens rarely */ - ISCSI_LOG(iscsi, 6, "smalloc free == SMALLOC_MAX_FREE"); - /* remove oldest half of free pointers and copy - * upper half to lower half */ - iscsi->smalloc_free >>= 1; - for (i = 0; i < iscsi->smalloc_free; i++) { - iscsi_free(iscsi, iscsi->smalloc_ptrs[i]); - iscsi->smalloc_ptrs[i] = - iscsi->smalloc_ptrs[i + iscsi->smalloc_free]; - } - } - iscsi->smalloc_ptrs[iscsi->smalloc_free++] = ptr; - } else { + if (!iscsi->cache_allocations) { iscsi_free(iscsi, ptr); + } else if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) { + /* SMALL_ALLOC_MAX_FREE should be adjusted that this */ + /* happens rarely */ + ISCSI_LOG(iscsi, 6, "smalloc free == SMALLOC_MAX_FREE"); + iscsi_free(iscsi, ptr); + } else { + iscsi->smalloc_ptrs[iscsi->smalloc_free++] = ptr; } }