From 84696ebe2a67339f654c21a0e8564b03590aef14 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 28 Jan 2014 17:13:05 +0100 Subject: [PATCH] stream: configurable stream chunk prealloc The stream chunk pool contains preallocating stream chunks (StreamMsg). These are used for raw reassembly, used in raw content inspection by the detection engine. The default setting so far has been 250, which was hardcoded. This meant that in setups that needed more, allocs and frees would be happen constantly. This patch introduces a yaml option to set the 'prealloc' value in the pool. The default is still 250. stream.reassembly.chunk-prealloc Related to feature #1093. --- src/stream-tcp-reassemble.c | 18 ++++++++++++++++-- src/stream.c | 6 ++++-- src/stream.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index a1b16f8387..b3133c27a5 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -439,6 +439,22 @@ int StreamTcpReassemblyConfig(char quiet) segment_pool_mutex = my_segment_lock; segment_pool_pktsizes = my_segment_pktsizes; segment_pool_num = npools; + + uint32_t stream_chunk_prealloc = 250; + ConfNode *chunk = ConfGetNode("stream.reassembly.chunk-prealloc"); + if (chunk) { + uint32_t prealloc = 0; + if (ByteExtractStringUint32(&prealloc, 10, strlen(chunk->val), chunk->val) == -1) + { + SCLogError(SC_ERR_INVALID_ARGUMENT, "chunk-prealloc of " + "%s is invalid", chunk->val); + return -1; + } + stream_chunk_prealloc = prealloc; + } + if (!quiet) + SCLogInfo("stream.reassembly \"chunk-prealloc\": %u", stream_chunk_prealloc); + StreamMsgQueuesInit(stream_chunk_prealloc); return 0; } @@ -449,8 +465,6 @@ int StreamTcpReassembleInit(char quiet) if (StreamTcpReassemblyConfig(quiet) < 0) return -1; - StreamMsgQueuesInit(); - #ifdef DEBUG SCMutexInit(&segment_pool_memuse_mutex, NULL); SCMutexInit(&segment_pool_cnt_mutex, NULL); diff --git a/src/stream.c b/src/stream.c index d6bc3877d9..962530b0b4 100644 --- a/src/stream.c +++ b/src/stream.c @@ -161,12 +161,14 @@ void StreamMsgPoolFree(void *ptr) { } } -void StreamMsgQueuesInit(void) { +void StreamMsgQueuesInit(uint32_t prealloc) { #ifdef DEBUG SCMutexInit(&stream_pool_memuse_mutex, NULL); #endif SCMutexLock(&stream_msg_pool_mutex); - stream_msg_pool = PoolInit(0,250,0,StreamMsgPoolAlloc,StreamMsgInit,NULL,NULL,StreamMsgPoolFree); + stream_msg_pool = PoolInit(0, prealloc, 0, + StreamMsgPoolAlloc,StreamMsgInit, + NULL,NULL,StreamMsgPoolFree); if (stream_msg_pool == NULL) exit(EXIT_FAILURE); /* XXX */ SCMutexUnlock(&stream_msg_pool_mutex); diff --git a/src/stream.h b/src/stream.h index c8453c931c..6a5b754275 100644 --- a/src/stream.h +++ b/src/stream.h @@ -56,7 +56,7 @@ typedef struct StreamMsgQueue_ { } StreamMsgQueue; /* prototypes */ -void StreamMsgQueuesInit(void); +void StreamMsgQueuesInit(uint32_t prealloc); void StreamMsgQueuesDeinit(char); StreamMsg *StreamMsgGetFromPool(void);