flow: free spare pool more aggressively

The flows exceeding the spare pools config setting would be freed
per at max 100 flows a second. After a high speed test this would
lead to excessive memory use for a long time.

This patch updates the logic to free 10% of the excess flows per
run, freeing multiple blocks of flows as needed.

Bug: #4731.
pull/6438/head
Victor Julien 5 years ago
parent ff97d7c15d
commit fa72a5add8

@ -173,8 +173,8 @@ void FlowSparePoolUpdate(uint32_t size)
{ {
const int64_t todo = (int64_t)flow_config.prealloc - (int64_t)size; const int64_t todo = (int64_t)flow_config.prealloc - (int64_t)size;
if (todo < 0) { if (todo < 0) {
/* remove one block at most at a time */
uint32_t to_remove = (uint32_t)(todo * -1) / 10; uint32_t to_remove = (uint32_t)(todo * -1) / 10;
while (to_remove) {
if (to_remove < flow_spare_pool_block_size) if (to_remove < flow_spare_pool_block_size)
return; return;
@ -184,6 +184,7 @@ void FlowSparePoolUpdate(uint32_t size)
if (p != NULL) { if (p != NULL) {
flow_spare_pool = p->next; flow_spare_pool = p->next;
flow_spare_pool_flow_cnt -= p->queue.len; flow_spare_pool_flow_cnt -= p->queue.len;
to_remove -= p->queue.len;
} }
SCMutexUnlock(&flow_spare_pool_m); SCMutexUnlock(&flow_spare_pool_m);
@ -194,7 +195,7 @@ void FlowSparePoolUpdate(uint32_t size)
} }
SCFree(p); SCFree(p);
} }
}
} else if (todo > 0) { } else if (todo > 0) {
FlowSparePool *head = NULL, *tail = NULL; FlowSparePool *head = NULL, *tail = NULL;

Loading…
Cancel
Save