]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4384: memory: account memory for profiler only when packet thread is...
authorAkhilesh MY (amuttuva) <amuttuva@cisco.com>
Wed, 31 Jul 2024 09:36:32 +0000 (09:36 +0000)
committerShanmugam S (shanms) <shanms@cisco.com>
Wed, 31 Jul 2024 09:36:32 +0000 (09:36 +0000)
Merge in SNORT/snort3 from ~AMUTTUVA/snort3:mp_seg to master

Squashed commit of the following:

commit 57c9c1a52f19347c0b8c85829dbf203e70c52476
Author: Akhilesh MY <amuttuva@cisco.com>
Date:   Thu Jul 11 05:12:15 2024 -0400

    memory: account memory for profiler only when packet thread is involved

src/main.cc
src/main.h
src/memory/memory_overloads.cc

index 929d28ec791c5eccc32bfbdbd8959e6c19d28759..f48e1789f74a14b8546b34a9e30b61bb9b6787d7 100644 (file)
@@ -72,7 +72,7 @@
 
 using namespace snort;
 
-static bool exit_requested = false;
+bool exit_requested = false;
 static int main_exit_code = 0;
 static bool paused = false;
 static bool pthreads_started = false;
index 6e4dd58f06471371e446feaa9a5c75b27ed881df..b13c38206ea23355357e1f6be91bf6eb355a2927 100644 (file)
@@ -22,7 +22,7 @@
 #define MAIN_H
 
 struct lua_State;
-
+extern bool exit_requested;
 const char* get_prompt();
 
 // commands provided by the snort module
index 69083ecf5f9223d1bf7298b688c13aef96bef883..996fca972d4e1134ddc9f4c480e46c4792488581 100644 (file)
@@ -27,7 +27,7 @@
 #include <cassert>
 
 #include "profiler/memory_profiler_active_context.h"
-
+#include "main.h"
 #include "memory_allocator.h"
 
 #ifdef UNIT_TEST
@@ -54,7 +54,7 @@ struct alignas(max_align_t) Metadata
 
     // number of requested bytes
     size_t payload_size;
-    uint32_t thread_id;
+    bool is_packet_thread;
     // stat used to keep track of allocation/deallocation
     MemoryTracker* mp_inspector_stats = nullptr;
 
@@ -87,7 +87,7 @@ inline Metadata::Metadata(size_t n) :
 #if defined(REG_TEST) || defined(UNIT_TEST)
     sanity(SANITY_CHECK_VALUE),
 #endif
-    payload_size(n), thread_id(instance_id),
+    payload_size(n), is_packet_thread(snort::is_packet_thread()),
     mp_inspector_stats(&mp_active_context.get_default())
 { }
 
@@ -187,12 +187,12 @@ void Interface<Allocator>::deallocate(void* p)
     assert(meta);
 
 #ifdef ENABLE_MEMORY_PROFILER
-    if (!snort::Snort::is_exiting())
+    if ( !snort::Snort::is_exiting() and !exit_requested )
     {
-        if (meta->mp_inspector_stats and meta->thread_id == instance_id) 
+        if ( meta->mp_inspector_stats and  meta->is_packet_thread == true )
             meta->mp_inspector_stats->update_deallocs(meta->total_size());
         else
-            mp_active_context.update_deallocs(meta->total_size());
+            mp_active_context.get_fallback().update_deallocs(meta->total_size());
     }
 #endif