PDU further optimize iscsi_add_data()
This patch further improves add data and esepcially preassigns the right amount of memory where the amount is preknown
This commit is contained in:
33
lib/pdu.c
33
lib/pdu.c
@@ -31,8 +31,8 @@
|
||||
#include "slist.h"
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags)
|
||||
iscsi_allocate_pdu_with_itt_flags_size(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags, size_t payload_size)
|
||||
{
|
||||
struct iscsi_pdu *pdu;
|
||||
|
||||
@@ -43,7 +43,10 @@ iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode
|
||||
}
|
||||
|
||||
pdu->outdata.size = ISCSI_HEADER_SIZE;
|
||||
pdu->outdata.data = iscsi_zmalloc(iscsi, pdu->outdata.size);
|
||||
pdu->outdata.alloc_size = 64;
|
||||
while (pdu->outdata.alloc_size < ISCSI_HEADER_SIZE+payload_size) pdu->outdata.alloc_size<<=1;
|
||||
pdu->outdata.data = iscsi_malloc(iscsi, pdu->outdata.alloc_size);
|
||||
memset(pdu->outdata.data, 0, ISCSI_HEADER_SIZE);
|
||||
|
||||
if (pdu->outdata.data == NULL) {
|
||||
iscsi_set_error(iscsi, "failed to allocate pdu header");
|
||||
@@ -70,6 +73,13 @@ iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode
|
||||
return pdu;
|
||||
}
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags)
|
||||
{
|
||||
return iscsi_allocate_pdu_with_itt_flags_size(iscsi, opcode, response_opcode, itt, flags, 0);
|
||||
}
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode)
|
||||
@@ -77,6 +87,13 @@ iscsi_allocate_pdu(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
return iscsi_allocate_pdu_with_itt_flags(iscsi, opcode, response_opcode, iscsi->itt++, 0);
|
||||
}
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu_size(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, size_t payload_size)
|
||||
{
|
||||
return iscsi_allocate_pdu_with_itt_flags_size(iscsi, opcode, response_opcode, iscsi->itt++, 0, payload_size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
@@ -120,18 +137,20 @@ iscsi_add_data(struct iscsi_context *iscsi, struct iscsi_data *data,
|
||||
aligned = (aligned+3)&0xfffffffc;
|
||||
}
|
||||
|
||||
int new_alloc_size=data->alloc_size;
|
||||
if (new_alloc_size < PAGE_SIZE) new_alloc_size=PAGE_SIZE;
|
||||
int new_alloc_size = data->alloc_size;
|
||||
if (new_alloc_size < 64) new_alloc_size=64;
|
||||
|
||||
while (aligned > new_alloc_size) new_alloc_size<<=1;
|
||||
|
||||
if (data->data != NULL && data->alloc_size == 0) data->alloc_size=data->size;
|
||||
|
||||
if (data->alloc_size == 0)
|
||||
if (data->alloc_size == 0) {
|
||||
data->data = iscsi_malloc(iscsi, new_alloc_size);
|
||||
}
|
||||
else
|
||||
if (data->alloc_size != new_alloc_size)
|
||||
if (data->alloc_size != new_alloc_size) {
|
||||
data->data = realloc(data->data, new_alloc_size);
|
||||
}
|
||||
|
||||
if (data->data == NULL) {
|
||||
iscsi_set_error(iscsi, "failed to allocate buffer for %d "
|
||||
|
||||
Reference in New Issue
Block a user