test-tool: Make it possible to disable memory caching
Disable memory caching in libiscsi if the environment variable LIBISCSI_CACHE_ALLOCATIONS has been set to zero. This makes Valgrind reports more meaningful. Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
d8de6531f8
commit
cf4076dba9
@@ -51,6 +51,8 @@ struct sockaddr;
|
|||||||
"<host>[:<port>]\""
|
"<host>[:<port>]\""
|
||||||
|
|
||||||
|
|
||||||
|
EXTERN void iscsi_set_cache_allocations(int ca);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following three functions are used to integrate libiscsi in an event
|
* The following three functions are used to integrate libiscsi in an event
|
||||||
* system.
|
* system.
|
||||||
|
|||||||
+28
-11
@@ -33,6 +33,17 @@
|
|||||||
#include "iscsi-private.h"
|
#include "iscsi-private.h"
|
||||||
#include "slist.h"
|
#include "slist.h"
|
||||||
|
|
||||||
|
int cache_allocations = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the internal memory allocator caches allocations. Disable
|
||||||
|
* memory allocation caching to improve the accuracy of Valgrind reports.
|
||||||
|
*/
|
||||||
|
void iscsi_set_cache_allocations(int ca)
|
||||||
|
{
|
||||||
|
cache_allocations = ca;
|
||||||
|
}
|
||||||
|
|
||||||
void* iscsi_malloc(struct iscsi_context *iscsi, size_t size) {
|
void* iscsi_malloc(struct iscsi_context *iscsi, size_t size) {
|
||||||
void * ptr = malloc(size);
|
void * ptr = malloc(size);
|
||||||
if (ptr != NULL) iscsi->mallocs++;
|
if (ptr != NULL) iscsi->mallocs++;
|
||||||
@@ -94,19 +105,25 @@ void iscsi_sfree(struct iscsi_context *iscsi, void* ptr) {
|
|||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) {
|
if (cache_allocations) {
|
||||||
int i;
|
if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) {
|
||||||
/* SMALL_ALLOC_MAX_FREE should be adjusted that this happens rarely */
|
int i;
|
||||||
ISCSI_LOG(iscsi, 6, "smalloc free == SMALLOC_MAX_FREE");
|
/* SMALL_ALLOC_MAX_FREE should be adjusted that this */
|
||||||
/* remove oldest half of free pointers and copy
|
/* happens rarely */
|
||||||
* upper half to lower half */
|
ISCSI_LOG(iscsi, 6, "smalloc free == SMALLOC_MAX_FREE");
|
||||||
iscsi->smalloc_free >>= 1;
|
/* remove oldest half of free pointers and copy
|
||||||
for (i = 0; i < iscsi->smalloc_free; i++) {
|
* upper half to lower half */
|
||||||
iscsi_free(iscsi, iscsi->smalloc_ptrs[i]);
|
iscsi->smalloc_free >>= 1;
|
||||||
iscsi->smalloc_ptrs[i] = iscsi->smalloc_ptrs[i + iscsi->smalloc_free];
|
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->smalloc_ptrs[iscsi->smalloc_free++] = ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct iscsi_context *
|
struct iscsi_context *
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ iscsi_sanitize_crypto_erase_sync
|
|||||||
iscsi_sanitize_crypto_erase_task
|
iscsi_sanitize_crypto_erase_task
|
||||||
iscsi_sanitize_exit_failure_mode_sync
|
iscsi_sanitize_exit_failure_mode_sync
|
||||||
iscsi_sanitize_exit_failure_mode_task
|
iscsi_sanitize_exit_failure_mode_task
|
||||||
|
iscsi_set_cache_allocations
|
||||||
iscsi_set_noautoreconnect
|
iscsi_set_noautoreconnect
|
||||||
iscsi_set_reconnect_max_retries
|
iscsi_set_reconnect_max_retries
|
||||||
iscsi_set_timeout
|
iscsi_set_timeout
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ iscsi_sanitize_crypto_erase_sync
|
|||||||
iscsi_sanitize_crypto_erase_task
|
iscsi_sanitize_crypto_erase_task
|
||||||
iscsi_sanitize_exit_failure_mode_sync
|
iscsi_sanitize_exit_failure_mode_sync
|
||||||
iscsi_sanitize_exit_failure_mode_task
|
iscsi_sanitize_exit_failure_mode_task
|
||||||
|
iscsi_set_cache_allocations
|
||||||
iscsi_set_noautoreconnect
|
iscsi_set_noautoreconnect
|
||||||
iscsi_set_reconnect_max_retries
|
iscsi_set_reconnect_max_retries
|
||||||
iscsi_set_timeout
|
iscsi_set_timeout
|
||||||
|
|||||||
@@ -971,6 +971,11 @@ main(int argc, char *argv[])
|
|||||||
};
|
};
|
||||||
int i, c;
|
int i, c;
|
||||||
int opt_idx = 0;
|
int opt_idx = 0;
|
||||||
|
char *ca;
|
||||||
|
|
||||||
|
ca = getenv("LIBISCSI_CACHE_ALLOCATIONS");
|
||||||
|
if (ca && atoi(ca) == 0)
|
||||||
|
iscsi_set_cache_allocations(0);
|
||||||
|
|
||||||
sd = malloc(sizeof(struct scsi_device));
|
sd = malloc(sizeof(struct scsi_device));
|
||||||
memset(sd, '\0', sizeof(struct scsi_device));
|
memset(sd, '\0', sizeof(struct scsi_device));
|
||||||
|
|||||||
Reference in New Issue
Block a user