]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3793: 7.5.0 Forward-port -- memory: subtract the allocated memory from...
authorSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 4 Apr 2023 15:41:34 +0000 (15:41 +0000)
committerSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 4 Apr 2023 15:41:34 +0000 (15:41 +0000)
Merge in SNORT/snort3 from ~MMATIRKO/snort3:memory_forward_75 to master

Squashed commit of the following:

commit c1e4fa90a08069e186bdf9717bcb8524b123a220
Author: Steve Chew (stechew) <stechew@cisco.com>
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

src/memory/memory_cap.cc
src/memory/test/memory_cap_test.cc

index 88f2fc9661bac301162bba5926e978e5b99ca7fc..15bf92dcbc9ee6b8312c85c0950d2dc957dca01f 100644 (file)
@@ -62,6 +62,7 @@ static std::atomic<uint64_t> 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;
index 0daeb83af00a5f613c2c6ecb6f76febad6a7631f..35f5ad8f841344fd2faf864e3f0e5226974dad06 100644 (file)
@@ -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();