]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: spare pool return optimization 8945/head
authorVictor Julien <vjulien@oisf.net>
Mon, 29 May 2023 12:05:38 +0000 (14:05 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 31 May 2023 05:58:19 +0000 (07:58 +0200)
In case small blocks of flows are returned, try to merge
them with existing small list head. Add full block as second
in the list as with the rest of the code.

src/flow-spare-pool.c

index 905c0853ff51b614cbd58c98a5fc18c2a722fc75..e47b983b8e04b8c1371490d9c14accfe8d3f4907 100644 (file)
@@ -126,13 +126,50 @@ void FlowSparePoolReturnFlows(FlowQueuePrivate *fqp)
     p->queue = *fqp;
 
     SCMutexLock(&flow_spare_pool_m);
-    p->next = flow_spare_pool;
-    flow_spare_pool = p;
     flow_spare_pool_flow_cnt += fqp->len;
+    if (flow_spare_pool != NULL) {
+        if (p->queue.len == flow_spare_pool_block_size) {
+            /* full block insert */
+
+            if (flow_spare_pool->queue.len < flow_spare_pool_block_size) {
+                p->next = flow_spare_pool->next;
+                flow_spare_pool->next = p;
+                p = NULL;
+            } else {
+                p->next = flow_spare_pool;
+                flow_spare_pool = p;
+                p = NULL;
+            }
+        } else {
+            /* incomplete block insert */
+
+            if (p->queue.len + flow_spare_pool->queue.len <= flow_spare_pool_block_size) {
+                FlowQueuePrivateAppendPrivate(&flow_spare_pool->queue, &p->queue);
+                /* free 'p' outside of lock below */
+            } else {
+                // put smallest first
+                if (p->queue.len < flow_spare_pool->queue.len) {
+                    p->next = flow_spare_pool;
+                    flow_spare_pool = p;
+                } else {
+                    p->next = flow_spare_pool->next;
+                    flow_spare_pool->next = p;
+                }
+                p = NULL;
+            }
+        }
+    } else {
+        p->next = flow_spare_pool;
+        flow_spare_pool = p;
+        p = NULL;
+    }
     SCMutexUnlock(&flow_spare_pool_m);
 
     FlowQueuePrivate empty = { NULL, NULL, 0 };
     *fqp = empty;
+
+    if (p != NULL)
+        SCFree(p);
 }
 
 FlowQueuePrivate FlowSpareGetFromPool(void)