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:
Peter Lieven
2013-07-18 11:15:56 +02:00
parent cc02faabb0
commit d429276907
4 changed files with 77 additions and 13 deletions

View File

@@ -482,7 +482,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
ssize_t data_size, count;
if (iscsi->incoming == NULL) {
iscsi->incoming = iscsi_zmalloc(iscsi, sizeof(struct iscsi_in_pdu));
iscsi->incoming = iscsi_szmalloc(iscsi, sizeof(struct iscsi_in_pdu));
if (iscsi->incoming == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: failed to malloc iscsi_in_pdu");
return -1;
@@ -810,7 +810,7 @@ iscsi_free_iscsi_in_pdu(struct iscsi_context *iscsi, struct iscsi_in_pdu *in)
{
iscsi_free(iscsi, in->data);
in->data=NULL;
iscsi_free(iscsi, in);
iscsi_sfree(iscsi, in);
in=NULL;
}