From: Akhilesh MY (amuttuva) Date: Wed, 31 Jul 2024 09:36:32 +0000 (+0000) Subject: Pull request #4384: memory: account memory for profiler only when packet thread is... X-Git-Tag: 3.3.3.0~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9654089ed673dfc7eac85de0f43e87e401b8a6c6;p=thirdparty%2Fsnort3.git Pull request #4384: memory: account memory for profiler only when packet thread is involved Merge in SNORT/snort3 from ~AMUTTUVA/snort3:mp_seg to master Squashed commit of the following: commit 57c9c1a52f19347c0b8c85829dbf203e70c52476 Author: Akhilesh MY Date: Thu Jul 11 05:12:15 2024 -0400 memory: account memory for profiler only when packet thread is involved --- diff --git a/src/main.cc b/src/main.cc index 929d28ec7..f48e1789f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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; diff --git a/src/main.h b/src/main.h index 6e4dd58f0..b13c38206 100644 --- a/src/main.h +++ b/src/main.h @@ -22,7 +22,7 @@ #define MAIN_H struct lua_State; - +extern bool exit_requested; const char* get_prompt(); // commands provided by the snort module diff --git a/src/memory/memory_overloads.cc b/src/memory/memory_overloads.cc index 69083ecf5..996fca972 100644 --- a/src/memory/memory_overloads.cc +++ b/src/memory/memory_overloads.cc @@ -27,7 +27,7 @@ #include #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::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