commit fe69a42: [Minor] Optimize memory layout for task

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Sep 30 15:14:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-30 15:58:02 +0100
URL: https://github.com/rspamd/rspamd/commit/fe69a42861ad1ff52c01f6e7c1b7df54b0c8bd7a

[Minor] Optimize memory layout for task

---
 src/libserver/task.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/libserver/task.c b/src/libserver/task.c
index f960829fc..e2fcdb2d6 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -66,8 +66,20 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg,
 				 struct ev_loop *event_loop)
 {
 	struct rspamd_task *new_task;
+	rspamd_mempool_t *task_pool;
+	guint flags = 0;
 
-	new_task = g_malloc0 (sizeof (struct rspamd_task));
+	if (pool == NULL) {
+		task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "task");
+		flags |= RSPAMD_TASK_FLAG_OWN_POOL;
+	}
+	else {
+		task_pool = pool;
+	}
+
+	new_task = rspamd_mempool_alloc0 (task_pool, sizeof (struct rspamd_task));
+	new_task->task_pool = task_pool;
+	new_task->flags = flags;
 	new_task->worker = worker;
 	new_task->lang_det = lang_det;
 
@@ -93,15 +105,6 @@ rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg,
 	new_task->task_timestamp = ev_time ();
 	new_task->time_real_finish = NAN;
 
-	if (pool == NULL) {
-		new_task->task_pool =
-				rspamd_mempool_new (rspamd_mempool_suggest_size (), "task");
-		new_task->flags |= RSPAMD_TASK_FLAG_OWN_POOL;
-	}
-	else {
-		new_task->task_pool = pool;
-	}
-
 	new_task->request_headers = kh_init (rspamd_req_headers_hash);
 	new_task->sock = -1;
 	new_task->flags |= (RSPAMD_TASK_FLAG_MIME);
@@ -293,8 +296,6 @@ rspamd_task_free (struct rspamd_task *task)
 		if (task->flags & RSPAMD_TASK_FLAG_OWN_POOL) {
 			rspamd_mempool_delete (task->task_pool);
 		}
-
-		g_free (task);
 	}
 }
 


More information about the Commits mailing list