From 90052609ee39f7a8eae9b125d2dee3ac3ccdce33 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Thu, 6 Sep 2012 08:41:17 +0200 Subject: [PATCH] defrag: avoid to run cleaning repetitively --- src/defrag.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/defrag.c b/src/defrag.c index d26dfd57a7..f78d5b19c5 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -106,6 +106,7 @@ typedef struct DefragContext_ { SCMutex frag_pool_lock; time_t timeout; /**< Default timeout. */ + time_t last_timeouted; /**< time of last cleaning */ } DefragContext; /** @@ -473,6 +474,8 @@ DefragContextNew(void) dc->timeout = timeout; } + dc->last_timeouted = 0; + SCLogDebug("Defrag Initialized:"); SCLogDebug("\tTimeout: %"PRIuMAX, (uintmax_t)dc->timeout); SCLogDebug("\tMaximum defrag trackers: %"PRIuMAX, tracker_pool_size); @@ -1026,6 +1029,15 @@ DefragTimeoutTracker(ThreadVars *tv, DecodeThreadVars *dtv, DefragContext *dc, { HashListTableBucket *next = HashListTableGetListHead(dc->frag_table); DefragTracker *tracker; + struct timeval ts; + + TimeGet(&ts); + /* If last cleaning was made in the current second, we leave */ + if (dc->last_timeouted >= ts.tv_sec) { + return; + } else { + dc->last_timeouted = ts.tv_sec; + } while (next != NULL) { tracker = HashListTableGetListData(next);