LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MemoryAdjuster_service.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // MemoryAdjuster
4 //
5 // ======================================================================
6 
10 #include "fhiclcpp/types/Atom.h"
11 #include "fhiclcpp/types/Name.h"
13 
14 //====================================================================================
15 
16 namespace {
17  using namespace fhicl;
18  struct Config {
19  Atom<int> m_mmap_max{Name{"M_MMAP_MAX"}, -1};
20  Atom<int> m_trim_thr{Name{"M_TRIM_THRESHOLD"}, -1};
21  Atom<int> m_top_pad{Name{"M_TOP_PAD"}, -1};
22  Atom<int> m_mmap_thr{Name{"M_MMAP_THRESHOLD"}, -1};
23  Atom<bool> dump{Name{"dump"}, false};
24  };
25 }
26 
27 namespace art {
28 
29  class ActivityRegistry;
30 
32  public:
34  MemoryAdjuster(ServiceTable<Config> const& config[[gnu::unused]])
35  {
36 #ifndef __linux__
37  mf::LogAbsolute("MemoryAdjuster")
38  << "\n"
39  << "Service not supported for this operating system.\n"
40  << "If desired, please log an issue with:\n\n"
41  << "https://cdcvs.fnal.gov/redmine/projects/cet-is/issues/new\n\n";
42 #else
43  auto& mopts = art::getGlobalOptionSetter();
44  auto const p_mmap_max = config().m_mmap_max();
45  auto const p_trim_thr = config().m_trim_thr();
46  auto const p_top_pad = config().m_top_pad();
47  auto const p_mmap_thr = config().m_mmap_thr();
48  if (p_mmap_max >= 0) {
49  mopts.set_mmap_max(p_mmap_max);
50  }
51  if (p_trim_thr >= 0) {
52  mopts.set_trim_thr(p_trim_thr);
53  }
54  if (p_top_pad >= 0) {
55  mopts.set_top_pad(p_top_pad);
56  }
57  if (p_mmap_thr >= 0) {
58  mopts.set_mmap_thr(p_mmap_thr);
59  }
60  mopts.adjustMallocParams();
61 
62  if (mopts.hasErrors()) {
63  mf::LogWarning("MemoryCheck")
64  << "ERROR: Problem with setting malloc options\n"
65  << mopts.error_message();
66  }
67  if (config().dump()) {
68  mf::LogWarning("MemoryCheck")
69  << "Malloc options: " << mopts.get() << "\n";
70  }
71 #endif
72  } // c'tor
73  };
74 
75 } // art
76 
77 // ======================================================================
78 
79 // The DECLARE macro call should be moved to the header file, should you
80 // create one.
83 
84 // ======================================================================
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
#define DECLARE_ART_SERVICE(svc, scope)
Definition: ServiceMacros.h:91
MemoryAdjuster(ServiceTable< Config > const &config[[gnu::unused]])
parameter set interface
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
HLT enums.
MallocOptionSetter & getGlobalOptionSetter()
Definition: MallocOpts.cc:207
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute