summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorSwen Schillig <swen@vnet.ibm.com>2018-03-12 17:56:21 +0100
committerChristof Schmitt <cs@samba.org>2018-12-07 23:27:16 +0100
commit353a947b4a983f6664391da6769b914d42612567 (patch)
treefa37c377521da0258be116ecd084989e746bf22e /ctdb/common
parent382705f495dd7f196efc8bb24b9cee3649b44836 (diff)
downloadsamba-353a947b4a983f6664391da6769b914d42612567.tar.gz
ctdb: Adding memory pool for queue callback
The received packet is copied into a newly allocated memory chunk for further processing by the assigned callback. Once this is done, the memory is free'd. This is repeated for each received packet making the memory allocation / free an expensive task. To optimize this process, a memory pool is defined which is sized identically to the queue's buffer. During tests it could be seen that more than 95% of all messages were sized below the standard buffer_size of 1k. Signed-off-by: Swen Schillig <swen@vnet.ibm.com> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Christof Schmitt <cs@samba.org> Autobuild-User(master): Christof Schmitt <cs@samba.org> Autobuild-Date(master): Fri Dec 7 23:27:16 CET 2018 on sn-devel-144
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/ctdb_io.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ctdb/common/ctdb_io.c b/ctdb/common/ctdb_io.c
index 5bed7a61b31..d86540762ea 100644
--- a/ctdb/common/ctdb_io.c
+++ b/ctdb/common/ctdb_io.c
@@ -65,6 +65,7 @@ struct ctdb_queue {
size_t alignment;
void *private_data;
ctdb_queue_cb_fn_t callback;
+ TALLOC_CTX *data_pool;
const char *name;
uint32_t buffer_size;
};
@@ -115,7 +116,7 @@ static void queue_process(struct ctdb_queue *queue)
}
/* Extract complete packet */
- data = talloc_memdup(queue,
+ data = talloc_memdup(queue->data_pool,
queue->buffer.data + queue->buffer.offset,
pkt_size);
@@ -479,5 +480,11 @@ struct ctdb_queue *ctdb_queue_setup(struct ctdb_context *ctdb,
queue->buffer_size = 1024;
}
+ queue->data_pool = talloc_pool(queue, queue->buffer_size);
+ if (queue->data_pool == NULL) {
+ TALLOC_FREE(queue);
+ return NULL;
+ }
+
return queue;
}