From: Victor Julien Date: Mon, 27 Jan 2020 09:34:00 +0000 (+0100) Subject: flow: improve 'under stress' behavior X-Git-Tag: suricata-6.0.0-beta1~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54d2f2c300178056f6ae427edaee21b53624c88e;p=thirdparty%2Fsuricata.git flow: improve 'under stress' behavior 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. --- diff --git a/src/flow-hash.c b/src/flow-hash.c index 26aa7efd74..e418a9d9e3 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -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)