CMS 3D CMS Logo

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 131 of file MallocOpts.cc.

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

131  : changed_(false) {
134  if (hasErrors()) {
135  std::cerr << "ERROR: Reset of malloc options has fails:\n" << error_message_ << "\n";
136  }
137  }
138  }
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 140 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().

140  {
141  if (changed_ == false)
142  return; // only adjust if they changed
143  error_message_.clear();
144  changed_ = false;
145 
146 #ifndef __SANITIZE_ADDRESS__
147 #ifdef M_MMAP_MAX
148  if (mallopt(M_MMAP_MAX, values_.mmap_max_) < 0)
149  error_message_ += "Could not set M_MMAP_MAX\n";
150 #endif
151 #ifdef M_TRIM_THRESHOLD
152  if (mallopt(M_TRIM_THRESHOLD, values_.trim_thr_) < 0)
153  error_message_ += "Could not set M_TRIM_THRESHOLD\n";
154 #endif
155 #ifdef M_TOP_PAD
156  if (mallopt(M_TOP_PAD, values_.top_pad_) < 0)
157  error_message_ += "ERROR: Could not set M_TOP_PAD\n";
158 #endif
159 #ifdef M_MMAP_THRESHOLD
160  if (mallopt(M_MMAP_THRESHOLD, values_.mmap_thr_) < 0)
161  error_message_ += "ERROR: Could not set M_MMAP_THRESHOLD\n";
162 #endif
163 #endif
164  }
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.

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.

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 109 of file MallocOpts.cc.

References changed_, and values_.

Referenced by MallocOptionSetter().

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

Definition at line 166 of file MallocOpts.cc.

References MessageLogger_cfi::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().

166  {
167  const char* par = getenv("CMSRUN_MALLOC_RESET");
168  if (par == nullptr)
169  return false; // leave quickly here
170  std::string spar(par);
171  bool rc = false;
172 
173  // CMSRUN_MALLOC_RESET = "mmap_max trim_thres top_pad mmap_thres"
174 
175  if (spar.size() > 1) {
176  std::istringstream ist(spar);
178 
179  if (ist.bad()) {
180  std::cerr << "bad malloc options in CMSRUN_MALLOC_RESET: " << spar << "\n"
181  << "format is: "
182  << "CMSRUN_MALLOC_RESET=\"mmap_max trim_thres top_pad mmap_thres\"\n";
183  } else {
184  std::cout << "MALLOC_OPTIONS> Reset options: "
185  << "CMSRUN_MALLOC_RESET=" << par << "\n";
186  }
187  rc = true;
188  changed_ = true;
189  }
190 
191  return rc;
192  }
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
void edm::MallocOptionSetter::set_mmap_max ( opt_type  mmap_max)
inline

Definition at line 64 of file MallocOpts.h.

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.

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.

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.

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

Definition at line 84 of file MallocOpts.h.

Referenced by adjustMallocParams(), retrieveFromCpuType(), and retrieveFromEnv().

std::string edm::MallocOptionSetter::error_message_
private

Definition at line 87 of file MallocOpts.h.

Referenced by adjustMallocParams(), and MallocOptionSetter().

MallocOpts edm::MallocOptionSetter::values_
private

Definition at line 85 of file MallocOpts.h.

Referenced by adjustMallocParams(), retrieveFromCpuType(), and retrieveFromEnv().