ctdb-common: Optimize sock_queue's memory managament
authorSwen Schillig <swen@vnet.ibm.com>
Mon, 8 Jan 2018 13:55:31 +0000 (14:55 +0100)
committerMartin Schwenke <martins@samba.org>
Tue, 30 Jan 2018 17:12:32 +0000 (18:12 +0100)
Make use of talloc pools for the sock_queue's memory requirements.

Signed-off-by: Swen Schillig <swen@vnet.ibm.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Tue Jan 30 18:12:32 CET 2018 on sn-devel-144

ctdb/common/sock_io.c

index ef7cfeb..51341ce 100644 (file)
@@ -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;