LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MallocOpts.h
Go to the documentation of this file.
1 #ifndef art_Utilities_MallocOpts_h
2 #define art_Utilities_MallocOpts_h
3 
4 // -*- C++ -*-
5 //
6 // Package: Utilities
7 // Class : MallocOpts
8 //
9 // Original Author: Jim Kowalkowski
10 //
11 //
12 // ------------------ malloc option setter -----------------------
13 //
14 // There is a global instance of MallocOptionSetter. Upon construction,
15 // it gets the CPU type. If is it AMD or Intel, it sets the mallopt
16 // parameters to a set that works best for that environment. The best
17 // values have been chosen based on running a simple fw job.
18 //
19 // The four values that get reset are:
20 // M_MMAP_MAX, M_TRIM_THRESHOLD, M_TOP_PAD, M_MMAP_THRESHOLD
21 //
22 // Current the best AMD and Intel values were calculated using:
23 // AMD Opteron(tm) Processor 248
24 // Intel Dual Core something or other
25 //
26 // These values will need to be checked when new CPUs are available or
27 // when we move to 64 bit executables.
28 
29 #include <ostream>
30 #include <string>
31 
32 namespace art {
33  struct MallocOpts {
34  using opt_type = int;
35 
36  MallocOpts() = default;
37  MallocOpts(opt_type max, opt_type trim, opt_type pad, opt_type mmap_thr)
38  : mmap_max_(max), trim_thr_(trim), top_pad_(pad), mmap_thr_(mmap_thr)
39  {}
40 
45 
46  bool
47  operator==(const MallocOpts& opts) const noexcept
48  {
49  return mmap_max_ == opts.mmap_max_ && trim_thr_ == opts.trim_thr_ &&
50  top_pad_ == opts.top_pad_ && mmap_thr_ == opts.mmap_thr_;
51  }
52  bool
53  operator!=(const MallocOpts& opts) const noexcept
54  {
55  return !operator==(opts);
56  }
57  };
58 
59  std::ostream& operator<<(std::ostream& ost, const MallocOpts&);
60 
62  public:
65 
66  bool retrieveFromCpuType();
67  bool retrieveFromEnv();
68  void adjustMallocParams();
69  bool
70  hasErrors() const
71  {
72  return !error_message_.empty();
73  }
74  std::string
75  error_message() const
76  {
77  return error_message_;
78  }
79 
80  void
82  {
83  values_.mmap_max_ = mmap_max;
84  changed_ = true;
85  }
86  void
88  {
89  values_.trim_thr_ = trim_thr;
90  changed_ = true;
91  }
92  void
94  {
95  values_.top_pad_ = top_pad;
96  changed_ = true;
97  }
98  void
100  {
101  values_.mmap_thr_ = mmap_thr;
102  changed_ = true;
103  }
104 
105  MallocOpts
106  get() const
107  {
108  return values_;
109  }
110 
111  private:
112  bool changed_;
114 
115  std::string error_message_;
116  };
117 
118 } // namespace art
119 
120 #endif /* art_Utilities_MallocOpts_h */
121 
122 // Local Variables:
123 // mode: c++
124 // End:
void set_trim_thr(opt_type trim_thr)
Definition: MallocOpts.h:87
opt_type mmap_max_
Definition: MallocOpts.h:41
MallocOpts(opt_type max, opt_type trim, opt_type pad, opt_type mmap_thr)
Definition: MallocOpts.h:37
bool operator==(const MallocOpts &opts) const noexcept
Definition: MallocOpts.h:47
opt_type top_pad_
Definition: MallocOpts.h:43
opt_type mmap_thr_
Definition: MallocOpts.h:44
MallocOpts()=default
std::string error_message_
Definition: MallocOpts.h:115
bool hasErrors() const
Definition: MallocOpts.h:70
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
opt_type trim_thr_
Definition: MallocOpts.h:42
void set_mmap_thr(opt_type mmap_thr)
Definition: MallocOpts.h:99
void set_mmap_max(opt_type mmap_max)
Definition: MallocOpts.h:81
MallocOpts::opt_type opt_type
Definition: MallocOpts.h:63
Definition: MVAAlg.h:12
std::string error_message() const
Definition: MallocOpts.h:75
void set_top_pad(opt_type top_pad)
Definition: MallocOpts.h:93
bool operator!=(const MallocOpts &opts) const noexcept
Definition: MallocOpts.h:53