From: Steven Baigal (sbaigal) Date: Tue, 4 Apr 2023 15:41:34 +0000 (+0000) Subject: Pull request #3793: 7.5.0 Forward-port -- memory: subtract the allocated memory from... X-Git-Tag: 3.1.59.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=642fd0b8c737fb17c22afb108601a0aca140a300;p=thirdparty%2Fsnort3.git Pull request #3793: 7.5.0 Forward-port -- memory: subtract the allocated memory from the thread pruned before comparing to the target Merge in SNORT/snort3 from ~MMATIRKO/snort3:memory_forward_75 to master Squashed commit of the following: commit c1e4fa90a08069e186bdf9717bcb8524b123a220 Author: Steve Chew (stechew) Date: Wed Mar 29 05:26:48 2023 +0000 Pull request #554: memory: subtract the allocated memory from the thread pruned before comparing to the target Merge in FIREPOWER/snort3 from ~RDEMPSTE/snort3:free_space_allocs to hotfix/7.0.5-DE * commit '71b3d000f9788a3ef14f6b9b5a606354623fe58f': memory: subtract the allocated memory from the thread pruned before comparing to the target --- diff --git a/src/memory/memory_cap.cc b/src/memory/memory_cap.cc index 88f2fc966..15bf92dcb 100644 --- a/src/memory/memory_cap.cc +++ b/src/memory/memory_cap.cc @@ -62,6 +62,7 @@ static std::atomic current_epoch { 0 }; static THREAD_LOCAL uint64_t last_dealloc = 0; static THREAD_LOCAL uint64_t start_dealloc = 0; +static THREAD_LOCAL uint64_t start_alloc = 0; static THREAD_LOCAL uint64_t start_epoch = 0; static HeapInterface* heap = nullptr; @@ -230,6 +231,7 @@ void MemoryCap::free_space() return; start_dealloc = last_dealloc = mc.deallocated; + start_alloc = mc.allocated; start_epoch = current_epoch; mc.reap_cycles++; } @@ -237,7 +239,9 @@ void MemoryCap::free_space() mc.pruned += (mc.deallocated - last_dealloc); last_dealloc = mc.deallocated; - if ( mc.deallocated - start_dealloc >= config.prune_target ) + uint64_t alloc = mc.allocated - start_alloc; + uint64_t dealloc = mc.deallocated - start_dealloc; + if ( dealloc > alloc and ( ( dealloc - alloc ) >= config.prune_target ) ) { start_dealloc = 0; return; diff --git a/src/memory/test/memory_cap_test.cc b/src/memory/test/memory_cap_test.cc index 0daeb83af..35f5ad8f8 100644 --- a/src/memory/test/memory_cap_test.cc +++ b/src/memory/test/memory_cap_test.cc @@ -224,17 +224,17 @@ TEST(memory, prune1) const MemoryCounts& mc = MemoryCap::get_mem_stats(); CHECK(mc.start_up_use == start); - flows = 1; + flows = 2; free_space(); - CHECK(flows == 1); + CHECK(flows == 2); heap->total = cap + 1; periodic_check(); CHECK(heap->epoch == 2); - CHECK(flows == 1); + CHECK(flows == 2); free_space(); - CHECK(flows == 0); + CHECK(flows == 1); heap->total = cap; periodic_check(); @@ -246,6 +246,10 @@ TEST(memory, prune1) free_space(); CHECK(flows == 0); + heap->dealloc++; + free_space(); + CHECK(flows == 0); + CHECK(mc.start_up_use == start); CHECK(mc.max_in_use == cap + 1); CHECK(mc.cur_in_use == cap); @@ -255,9 +259,9 @@ TEST(memory, prune1) CHECK(mc.deallocated == heap->dealloc); CHECK(mc.reap_cycles == 1); - CHECK(mc.reap_attempts == 1); + CHECK(mc.reap_attempts == 2); CHECK(mc.reap_failures == 0); - CHECK(mc.pruned == 1); + CHECK(mc.pruned == 2); heap->total = start; MemoryCap::stop();