From: Swen Schillig Date: Mon, 8 Jan 2018 13:55:31 +0000 (+0100) Subject: ctdb-common: Optimize sock_queue's memory managament X-Git-Tag: tevent-0.9.36~260 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=32d867cf09a15626b991be414ab6440f68953f35;p=thirdparty%2Fsamba.git ctdb-common: Optimize sock_queue's memory managament Make use of talloc pools for the sock_queue's memory requirements. Signed-off-by: Swen Schillig Reviewed-by: Amitay Isaacs Reviewed-by: Martin Schwenke Autobuild-User(master): Martin Schwenke Autobuild-Date(master): Tue Jan 30 18:12:32 CET 2018 on sn-devel-144 --- diff --git a/ctdb/common/sock_io.c b/ctdb/common/sock_io.c index ef7cfeb2ea1..51341ce023e 100644 --- a/ctdb/common/sock_io.c +++ b/ctdb/common/sock_io.c @@ -94,6 +94,17 @@ struct sock_queue { size_t buflen, begin, end; }; +/* + * The reserved talloc headers, SOCK_QUEUE_OBJ_COUNT, + * and the pre-allocated pool-memory SOCK_QUEUE_POOL_SIZE, + * are used for the sub-objects queue->im, queue->queue, queue->fde + * and queue->buf. + * If the memory allocating sub-objects of struct sock_queue change, + * those values need to be adjusted. + */ +#define SOCK_QUEUE_OBJ_COUNT 4 +#define SOCK_QUEUE_POOL_SIZE 2048 + static bool sock_queue_set_fd(struct sock_queue *queue, int fd); static void sock_queue_handler(struct tevent_context *ev, struct tevent_fd *fde, uint16_t flags, @@ -111,10 +122,12 @@ struct sock_queue *sock_queue_setup(TALLOC_CTX *mem_ctx, { struct sock_queue *queue; - queue = talloc_zero(mem_ctx, struct sock_queue); + queue = talloc_pooled_object(mem_ctx, struct sock_queue, + SOCK_QUEUE_OBJ_COUNT, SOCK_QUEUE_POOL_SIZE); if (queue == NULL) { return NULL; } + memset(queue, 0, sizeof(struct sock_queue)); queue->ev = ev; queue->callback = callback;