From: Mike Stepanek (mstepane) Date: Thu, 6 Feb 2020 16:45:32 +0000 (+0000) Subject: Merge pull request #1960 in SNORT/snort3 from ~MASHASAN/snort3:memory_cap_per_thread... X-Git-Tag: 3.0.0-268~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9a2e58ccec18dcfc59643bf475e2448fdc53ff5;p=thirdparty%2Fsnort3.git Merge pull request #1960 in SNORT/snort3 from ~MASHASAN/snort3:memory_cap_per_thread to master Squashed commit of the following: commit 466a7cfba777b9d1693c3da0321d5b05852603a4 Author: Masud Hasan Date: Tue Jan 21 22:40:53 2020 -0500 memory: Treating config value memory.cap as per thread instead of global --- diff --git a/src/main/snort.cc b/src/main/snort.cc index 9831406d3..273a8c4fb 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -397,7 +397,7 @@ void Snort::setup(int argc, char* argv[]) set_quick_exit(false); - memory::MemoryCap::calculate(ThreadConfig::get_instance_max()); + memory::MemoryCap::calculate(); memory::MemoryCap::print(); host_cache.print_config(); diff --git a/src/memory/memory_cap.cc b/src/memory/memory_cap.cc index a7ae6d6ca..f2cb3553b 100644 --- a/src/memory/memory_cap.cc +++ b/src/memory/memory_cap.cc @@ -179,39 +179,13 @@ bool MemoryCap::over_threshold() // once reload is implemented for the memory manager, the configuration // model will need to be updated -void MemoryCap::calculate(unsigned num_threads) +void MemoryCap::calculate() { assert(!is_packet_thread()); const MemoryConfig& config = *SnortConfig::get_conf()->memory; - auto main_thread_used = s_tracker.used(); - - if ( !config.cap ) - { - thread_cap = preemptive_threshold = 0; - return; - } - - if ( main_thread_used > config.cap ) - { - ParseError("main thread memory usage (%zu) is greater than cap\n", main_thread_used); - return; - } - - auto real_cap = config.cap - main_thread_used; - thread_cap = real_cap / num_threads; - - // FIXIT-L do we want to add some fixed overhead to allow the packet threads to - // startup and preallocate flows and whatnot? - - if ( !thread_cap ) - { - ParseError("per-thread memory cap is 0"); - return; - } - - if ( config.threshold ) - preemptive_threshold = memory::calculate_threshold(thread_cap, config.threshold); + thread_cap = config.cap; + preemptive_threshold = memory::calculate_threshold(thread_cap, config.threshold); } void MemoryCap::print() @@ -219,15 +193,13 @@ void MemoryCap::print() if ( !MemoryModule::is_active() ) return; - const MemoryConfig& config = *SnortConfig::get_conf()->memory; - if ( SnortConfig::log_verbose() or mem_stats.allocations ) LogLabel("memory (heap)"); if ( SnortConfig::log_verbose() ) { - LogMessage(" global cap: %zu\n", config.cap); - LogMessage(" global preemptive threshold percent: %u\n", config.threshold); + LogMessage(" thread cap: %zu\n", thread_cap); + LogMessage(" thread preemptive threshold: %zu\n", preemptive_threshold); } if ( mem_stats.allocations ) @@ -235,8 +207,6 @@ void MemoryCap::print() LogMessage(" main thread usage: %zu\n", s_tracker.used()); LogMessage(" allocations: %" PRIu64 "\n", mem_stats.allocations); LogMessage(" deallocations: %" PRIu64 "\n", mem_stats.deallocations); - LogMessage(" thread cap: %zu\n", thread_cap); - LogMessage(" preemptive threshold: %zu\n", preemptive_threshold); } } diff --git a/src/memory/memory_cap.h b/src/memory/memory_cap.h index 90a2dcc1a..450f3322f 100644 --- a/src/memory/memory_cap.h +++ b/src/memory/memory_cap.h @@ -38,7 +38,7 @@ public: static bool over_threshold(); // call from main thread - static void calculate(unsigned num_threads); + static void calculate(); // call from main thread static void print();