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 4 years ago
parent ff97d7c15d
commit fa72a5add8

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

Loading…
Cancel
Save