]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: improve 'under stress' behavior
authorVictor Julien <victor@inliniac.net>
Mon, 27 Jan 2020 09:34:00 +0000 (10:34 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 7 Jul 2020 08:29:41 +0000 (10:29 +0200)
When under stress, the packet threads ultimately fall back
to walking the hash table until they find a flow they can
safely evict and reuse. This could lead to all threads
fighting over the FlowBucket locks.

Fix by adding a limit to the number of hash rows that are
checked for a new flow. If the limit is reached, simply fail
to get a flow.

src/flow-hash.c

index 26aa7efd7476c730d6120798e497e46accd80998..e418a9d9e3da2e5c2c2642aeaafd87185a7047e6 100644 (file)
@@ -880,11 +880,18 @@ static Flow *FlowGetUsedFlow(ThreadVars *tv, DecodeThreadVars *dtv)
 {
     uint32_t idx = SC_ATOMIC_GET(flow_prune_idx) % flow_config.hash_size;
     uint32_t cnt = flow_config.hash_size;
+    uint32_t tried = 0;
 
     while (cnt--) {
+        tried++;
         if (++idx >= flow_config.hash_size)
             idx = 0;
 
+        if (tried >= 25) {
+            (void) SC_ATOMIC_ADD(flow_prune_idx, (flow_config.hash_size - cnt));
+            break;
+        }
+
         FlowBucket *fb = &flow_hash[idx];
 
         if (FBLOCK_TRYLOCK(fb) != 0)