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  typedef int opt_type;
35 
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 
41  opt_type mmap_max_;
42  opt_type trim_thr_;
43  opt_type top_pad_;
44  opt_type mmap_thr_;
45 
46  bool
47  operator==(const MallocOpts& opts) const
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
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  }
75  error_message() const
76  {
77  return error_message_;
78  }
79 
80  void
81  set_mmap_max(opt_type mmap_max)
82  {
83  values_.mmap_max_ = mmap_max;
84  changed_ = true;
85  }
86  void
87  set_trim_thr(opt_type trim_thr)
88  {
89  values_.trim_thr_ = trim_thr;
90  changed_ = true;
91  }
92  void
93  set_top_pad(opt_type top_pad)
94  {
95  values_.top_pad_ = top_pad;
96  changed_ = true;
97  }
98  void
99  set_mmap_thr(opt_type mmap_thr)
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 
116  };
117 
118 } // namespace art
119 
120 #endif /* art_Utilities_MallocOpts_h */
121 
122 // Local Variables:
123 // mode: c++
124 // End:
static std::string trim(const std::string &str, const std::string &whitespace=" \t")
Definition: doxyindexer.cpp:47
MallocOpts::opt_type opt_type
Definition: MallocOpts.h:63
void set_trim_thr(opt_type trim_thr)
Definition: MallocOpts.h:87
opt_type mmap_max_
Definition: MallocOpts.h:41
std::string string
Definition: nybbler.cc:12
MallocOpts(opt_type max, opt_type trim, opt_type pad, opt_type mmap_thr)
Definition: MallocOpts.h:37
opt_type top_pad_
Definition: MallocOpts.h:43
opt_type mmap_thr_
Definition: MallocOpts.h:44
bool operator!=(const MallocOpts &opts) const
Definition: MallocOpts.h:53
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
static int max(int a, int b)
void set_mmap_thr(opt_type mmap_thr)
Definition: MallocOpts.h:99
void set_mmap_max(opt_type mmap_max)
Definition: MallocOpts.h:81
opts
Definition: ECLAPI.py:241
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
Definition: MallocOpts.h:47