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 <pl@kamp.de>
This commit is contained in:
Peter Lieven
2015-05-05 14:14:26 +02:00
parent b4098c535e
commit a027931a2c

View File

@@ -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;
}
}