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

◆ opt_type

Definition at line 55 of file MallocOpts.h.

Constructor & Destructor Documentation

◆ MallocOptionSetter()

edm::MallocOptionSetter::MallocOptionSetter ( )

Definition at line 132 of file MallocOpts.cc.

132  : changed_(false) {
135  if (hasErrors()) {
136  std::cerr << "ERROR: Reset of malloc options has fails:\n" << error_message_ << "\n";
137  }
138  }
139  }

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

Member Function Documentation

◆ adjustMallocParams()

void edm::MallocOptionSetter::adjustMallocParams ( )

Definition at line 141 of file MallocOpts.cc.

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  }

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().

◆ error_message()

std::string edm::MallocOptionSetter::error_message ( ) const
inline

Definition at line 62 of file MallocOpts.h.

62 { return error_message_; }

References error_message_.

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

◆ get()

MallocOpts edm::MallocOptionSetter::get ( ) const
inline

◆ hasErrors()

bool edm::MallocOptionSetter::hasErrors ( ) const
inline

Definition at line 61 of file MallocOpts.h.

61 { return !error_message_.empty(); }

References error_message_.

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

◆ retrieveFromCpuType()

bool edm::MallocOptionSetter::retrieveFromCpuType ( )

Definition at line 110 of file MallocOpts.cc.

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  }

References changed_, and values_.

Referenced by MallocOptionSetter().

◆ retrieveFromEnv()

bool edm::MallocOptionSetter::retrieveFromEnv ( )

Definition at line 167 of file MallocOpts.cc.

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  }

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().

◆ set_mmap_max()

void edm::MallocOptionSetter::set_mmap_max ( opt_type  mmap_max)
inline

Definition at line 64 of file MallocOpts.h.

64  {
65  values_.mmap_max_ = mmap_max;
66  changed_ = true;
67  }

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

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

◆ set_mmap_thr()

void edm::MallocOptionSetter::set_mmap_thr ( opt_type  mmap_thr)
inline

Definition at line 76 of file MallocOpts.h.

76  {
77  values_.mmap_thr_ = mmap_thr;
78  changed_ = true;
79  }

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

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

◆ set_top_pad()

void edm::MallocOptionSetter::set_top_pad ( opt_type  top_pad)
inline

Definition at line 72 of file MallocOpts.h.

72  {
73  values_.top_pad_ = top_pad;
74  changed_ = true;
75  }

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

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

◆ set_trim_thr()

void edm::MallocOptionSetter::set_trim_thr ( opt_type  trim_thr)
inline

Definition at line 68 of file MallocOpts.h.

68  {
69  values_.trim_thr_ = trim_thr;
70  changed_ = true;
71  }

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

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

Member Data Documentation

◆ changed_

bool edm::MallocOptionSetter::changed_
private

◆ error_message_

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

Definition at line 87 of file MallocOpts.h.

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

◆ values_

MallocOpts edm::MallocOptionSetter::values_
private
edm::MallocOpts::trim_thr_
opt_type trim_thr_
Definition: MallocOpts.h:40
edm::MallocOptionSetter::retrieveFromCpuType
bool retrieveFromCpuType()
Definition: MallocOpts.cc:110
edm::MallocOptionSetter::changed_
bool changed_
Definition: MallocOpts.h:84
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::MallocOpts::mmap_thr_
opt_type mmap_thr_
Definition: MallocOpts.h:42
edm::MallocOptionSetter::error_message_
std::string error_message_
Definition: MallocOpts.h:87
edm::MallocOptionSetter::adjustMallocParams
void adjustMallocParams()
Definition: MallocOpts.cc:141
edm::MallocOpts::mmap_max_
opt_type mmap_max_
Definition: MallocOpts.h:39
edm::MallocOptionSetter::hasErrors
bool hasErrors() const
Definition: MallocOpts.h:61
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::MallocOpts::top_pad_
opt_type top_pad_
Definition: MallocOpts.h:41
edm::MallocOptionSetter::values_
MallocOpts values_
Definition: MallocOpts.h:85
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
edm::MallocOptionSetter::retrieveFromEnv
bool retrieveFromEnv()
Definition: MallocOpts.cc:167