CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Private Attributes
edm::MallocOptionSetter Class Reference

#include <MallocOpts.h>

Public Types

typedef MallocOpts::opt_type opt_type
 

Public Member Functions

void adjustMallocParams ()
 
std::string error_message () const
 
MallocOpts get () const
 
bool hasErrors () const
 
 MallocOptionSetter ()
 
bool retrieveFromCpuType ()
 
bool retrieveFromEnv ()
 
void set_mmap_max (opt_type mmap_max)
 
void set_mmap_thr (opt_type mmap_thr)
 
void set_top_pad (opt_type top_pad)
 
void set_trim_thr (opt_type trim_thr)
 

Private Attributes

bool changed_
 
std::string error_message_
 
MallocOpts values_
 

Detailed Description

Definition at line 53 of file MallocOpts.h.

Member Typedef Documentation

Definition at line 55 of file MallocOpts.h.

Constructor & Destructor Documentation

edm::MallocOptionSetter::MallocOptionSetter ( )

Definition at line 132 of file MallocOpts.cc.

References adjustMallocParams(), EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, error_message_, hasErrors(), retrieveFromCpuType(), and retrieveFromEnv().

132  : changed_(false) {
135  if (hasErrors()) {
136  std::cerr << "ERROR: Reset of malloc options has fails:\n" << error_message_ << "\n";
137  }
138  }
139  }
std::string error_message_
Definition: MallocOpts.h:87
bool hasErrors() const
Definition: MallocOpts.h:61

Member Function Documentation

void edm::MallocOptionSetter::adjustMallocParams ( )

Definition at line 141 of file MallocOpts.cc.

References changed_, error_message_, edm::MallocOpts::mmap_max_, edm::MallocOpts::mmap_thr_, edm::MallocOpts::top_pad_, edm::MallocOpts::trim_thr_, and values_.

Referenced by MallocOptionSetter(), and edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

141  {
142  if (changed_ == false)
143  return; // only adjust if they changed
144  error_message_.clear();
145  changed_ = false;
146 
147 #ifndef __SANITIZE_ADDRESS__
148 #ifdef M_MMAP_MAX
149  if (mallopt(M_MMAP_MAX, values_.mmap_max_) < 0)
150  error_message_ += "Could not set M_MMAP_MAX\n";
151 #endif
152 #ifdef M_TRIM_THRESHOLD
153  if (mallopt(M_TRIM_THRESHOLD, values_.trim_thr_) < 0)
154  error_message_ += "Could not set M_TRIM_THRESHOLD\n";
155 #endif
156 #ifdef M_TOP_PAD
157  if (mallopt(M_TOP_PAD, values_.top_pad_) < 0)
158  error_message_ += "ERROR: Could not set M_TOP_PAD\n";
159 #endif
160 #ifdef M_MMAP_THRESHOLD
161  if (mallopt(M_MMAP_THRESHOLD, values_.mmap_thr_) < 0)
162  error_message_ += "ERROR: Could not set M_MMAP_THRESHOLD\n";
163 #endif
164 #endif
165  }
std::string error_message_
Definition: MallocOpts.h:87
opt_type mmap_max_
Definition: MallocOpts.h:39
opt_type trim_thr_
Definition: MallocOpts.h:40
opt_type mmap_thr_
Definition: MallocOpts.h:42
opt_type top_pad_
Definition: MallocOpts.h:41
std::string edm::MallocOptionSetter::error_message ( ) const
inline

Definition at line 62 of file MallocOpts.h.

References error_message_.

Referenced by edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

62 { return error_message_; }
std::string error_message_
Definition: MallocOpts.h:87
MallocOpts edm::MallocOptionSetter::get ( ) const
inline
bool edm::MallocOptionSetter::hasErrors ( ) const
inline

Definition at line 61 of file MallocOpts.h.

References error_message_.

Referenced by MallocOptionSetter(), and edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

61 { return !error_message_.empty(); }
std::string error_message_
Definition: MallocOpts.h:87
bool edm::MallocOptionSetter::retrieveFromCpuType ( )

Definition at line 110 of file MallocOpts.cc.

References changed_, and values_.

Referenced by MallocOptionSetter().

110  {
111  bool rc = true;
112 
113  switch (get_cpu_type()) {
114  case AMD_CPU: {
115  values_ = amd_opts;
116  changed_ = true;
117  break;
118  }
119  case INTEL_CPU: {
120  values_ = intel_opts;
121  changed_ = true;
122  break;
123  }
124  case UNKNOWN_CPU:
125  default:
126  rc = false;
127  }
128 
129  return rc;
130  }
bool edm::MallocOptionSetter::retrieveFromEnv ( )

Definition at line 167 of file MallocOpts.cc.

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, changed_, gather_cfg::cout, edm::MallocOpts::mmap_max_, edm::MallocOpts::mmap_thr_, AlCaHLTBitMon_QueryRunRegistry::string, edm::MallocOpts::top_pad_, edm::MallocOpts::trim_thr_, and values_.

Referenced by MallocOptionSetter().

167  {
168  const char* par = std::getenv("CMSRUN_MALLOC_RESET");
169  if (par == nullptr)
170  return false; // leave quickly here
171  std::string spar(par);
172  bool rc = false;
173 
174  // CMSRUN_MALLOC_RESET = "mmap_max trim_thres top_pad mmap_thres"
175 
176  if (spar.size() > 1) {
177  std::istringstream ist(spar);
179 
180  if (ist.bad()) {
181  std::cerr << "bad malloc options in CMSRUN_MALLOC_RESET: " << spar << "\n"
182  << "format is: "
183  << "CMSRUN_MALLOC_RESET=\"mmap_max trim_thres top_pad mmap_thres\"\n";
184  } else {
185  std::cout << "MALLOC_OPTIONS> Reset options: "
186  << "CMSRUN_MALLOC_RESET=" << par << "\n";
187  }
188  rc = true;
189  changed_ = true;
190  }
191 
192  return rc;
193  }
opt_type mmap_max_
Definition: MallocOpts.h:39
opt_type trim_thr_
Definition: MallocOpts.h:40
tuple cout
Definition: gather_cfg.py:144
opt_type mmap_thr_
Definition: MallocOpts.h:42
opt_type top_pad_
Definition: MallocOpts.h:41
void edm::MallocOptionSetter::set_mmap_max ( opt_type  mmap_max)
inline

Definition at line 64 of file MallocOpts.h.

References changed_, edm::MallocOpts::mmap_max_, and values_.

Referenced by edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

64  {
65  values_.mmap_max_ = mmap_max;
66  changed_ = true;
67  }
opt_type mmap_max_
Definition: MallocOpts.h:39
void edm::MallocOptionSetter::set_mmap_thr ( opt_type  mmap_thr)
inline

Definition at line 76 of file MallocOpts.h.

References changed_, edm::MallocOpts::mmap_thr_, and values_.

Referenced by edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

76  {
77  values_.mmap_thr_ = mmap_thr;
78  changed_ = true;
79  }
opt_type mmap_thr_
Definition: MallocOpts.h:42
void edm::MallocOptionSetter::set_top_pad ( opt_type  top_pad)
inline

Definition at line 72 of file MallocOpts.h.

References changed_, edm::MallocOpts::top_pad_, and values_.

Referenced by edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

72  {
73  values_.top_pad_ = top_pad;
74  changed_ = true;
75  }
opt_type top_pad_
Definition: MallocOpts.h:41
void edm::MallocOptionSetter::set_trim_thr ( opt_type  trim_thr)
inline

Definition at line 68 of file MallocOpts.h.

References changed_, edm::MallocOpts::trim_thr_, and values_.

Referenced by edm::service::SimpleMemoryCheck::SimpleMemoryCheck().

68  {
69  values_.trim_thr_ = trim_thr;
70  changed_ = true;
71  }
opt_type trim_thr_
Definition: MallocOpts.h:40

Member Data Documentation

bool edm::MallocOptionSetter::changed_
private
std::string edm::MallocOptionSetter::error_message_
private

Definition at line 87 of file MallocOpts.h.

Referenced by adjustMallocParams(), error_message(), hasErrors(), and MallocOptionSetter().

MallocOpts edm::MallocOptionSetter::values_
private