]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1960 in SNORT/snort3 from ~MASHASAN/snort3:memory_cap_per_thread...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Thu, 6 Feb 2020 16:45:32 +0000 (16:45 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Thu, 6 Feb 2020 16:45:32 +0000 (16:45 +0000)
Squashed commit of the following:

commit 466a7cfba777b9d1693c3da0321d5b05852603a4
Author: Masud Hasan <mashasan@cisco.com>
Date:   Tue Jan 21 22:40:53 2020 -0500

    memory: Treating config value memory.cap as per thread instead of global

src/main/snort.cc
src/memory/memory_cap.cc
src/memory/memory_cap.h

index 9831406d3fb5138a542c751f0c540bd7cddcc0bf..273a8c4fb9dd68615e757e353b1685287c309ae2 100644 (file)
@@ -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();
 
index a7ae6d6ca4afa5949622b9e32a9333b47965061f..f2cb3553b82be1600ee78169b98b6a8831290377 100644 (file)
@@ -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);
     }
 }
 
index 90a2dcc1ad450eb6f98caf579021d1590d26772b..450f3322f4305bc1a474c1c40e221478d52d58b6 100644 (file)
@@ -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();