MEMORY introduce a small allocation pool
This patch finally introduces a small allocation pool which recycles all the small portions of memory that are used for headers and pdu structures. This was the initial idea behind wrapping all memory functions in libiscsi. The results of booting are test system up to the login prompt are quite impressive: BEFORE: libiscsi:5 memory is clean at iscsi_destroy_context() after 10712 mallocs, 18 realloc(s) and 10712 free(s) AFTER: libiscsi:5 memory is clean at iscsi_destroy_context() after 41 mallocs, 18 realloc(s), 41 free(s) and 10584 reused small allocations Signed-off-by: Peter Lieven <pl@kamp.de>
This commit is contained in:
29
lib/pdu.c
29
lib/pdu.c
@@ -84,15 +84,14 @@ iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode
|
||||
{
|
||||
struct iscsi_pdu *pdu;
|
||||
|
||||
pdu = iscsi_zmalloc(iscsi, sizeof(struct iscsi_pdu));
|
||||
pdu = iscsi_szmalloc(iscsi, sizeof(struct iscsi_pdu));
|
||||
if (pdu == NULL) {
|
||||
iscsi_set_error(iscsi, "failed to allocate pdu");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pdu->outdata.size = ISCSI_HEADER_SIZE;
|
||||
pdu->outdata.data = iscsi_malloc(iscsi, pdu->outdata.size);
|
||||
memset(pdu->outdata.data, 0, ISCSI_HEADER_SIZE);
|
||||
pdu->outdata.data = iscsi_szmalloc(iscsi, pdu->outdata.size);
|
||||
|
||||
if (pdu->outdata.data == NULL) {
|
||||
iscsi_set_error(iscsi, "failed to allocate pdu header");
|
||||
@@ -134,13 +133,21 @@ iscsi_free_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return;
|
||||
}
|
||||
|
||||
iscsi_free(iscsi, pdu->outdata.data);
|
||||
if (pdu->outdata.size <= iscsi->smalloc_size) {
|
||||
iscsi_sfree(iscsi, pdu->outdata.data);
|
||||
} else {
|
||||
iscsi_free(iscsi, pdu->outdata.data);
|
||||
}
|
||||
pdu->outdata.data = NULL;
|
||||
|
||||
iscsi_free(iscsi, pdu->indata.data);
|
||||
if (pdu->indata.size <= iscsi->smalloc_size) {
|
||||
iscsi_sfree(iscsi, pdu->indata.data);
|
||||
} else {
|
||||
iscsi_free(iscsi, pdu->indata.data);
|
||||
}
|
||||
pdu->indata.data = NULL;
|
||||
|
||||
iscsi_free(iscsi, pdu);
|
||||
iscsi_sfree(iscsi, pdu);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,9 +171,15 @@ iscsi_add_data(struct iscsi_context *iscsi, struct iscsi_data *data,
|
||||
}
|
||||
|
||||
if (data->size == 0) {
|
||||
data->data = iscsi_malloc(iscsi, aligned);
|
||||
if (aligned <= iscsi->smalloc_size) {
|
||||
data->data = iscsi_szmalloc(iscsi, aligned);
|
||||
} else {
|
||||
data->data = iscsi_malloc(iscsi, aligned);
|
||||
}
|
||||
} else {
|
||||
data->data = iscsi_realloc(iscsi, data->data, aligned);
|
||||
if (aligned > iscsi->smalloc_size) {
|
||||
data->data = iscsi_realloc(iscsi, data->data, aligned);
|
||||
}
|
||||
}
|
||||
if (data->data == NULL) {
|
||||
iscsi_set_error(iscsi, "failed to allocate buffer for %d "
|
||||
|
||||
Reference in New Issue
Block a user