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:
25
lib/init.c
25
lib/init.c
@@ -94,24 +94,15 @@ void iscsi_sfree(struct iscsi_context *iscsi, void* ptr) {
|
|||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (iscsi->cache_allocations) {
|
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 {
|
|
||||||
iscsi_free(iscsi, ptr);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user