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

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

References adjustMallocParams(), beam_dqm_sourceclient-live_cfg::cerr, error_message_, hasErrors(), retrieveFromCpuType(), and retrieveFromEnv().

Member Function Documentation

◆ adjustMallocParams()

void edm::MallocOptionSetter::adjustMallocParams ( )

Definition at line 140 of file MallocOpts.cc.

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  }

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

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  }

References changed_, and values_.

Referenced by MallocOptionSetter().

◆ retrieveFromEnv()

bool edm::MallocOptionSetter::retrieveFromEnv ( )

Definition at line 166 of file MallocOpts.cc.

166  {
167  const char* par = std::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  }

References beam_dqm_sourceclient-live_cfg::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:109
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::MallocOptionSetter::error_message_
std::string error_message_
Definition: MallocOpts.h:87
edm::MallocOptionSetter::adjustMallocParams
void adjustMallocParams()
Definition: MallocOpts.cc:140
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
edm::MallocOpts::mmap_max_
opt_type mmap_max_
Definition: MallocOpts.h:39
edm::MallocOptionSetter::hasErrors
bool hasErrors() const
Definition: MallocOpts.h:61
edm::MallocOpts::top_pad_
opt_type top_pad_
Definition: MallocOpts.h:41
edm::MallocOptionSetter::values_
MallocOpts values_
Definition: MallocOpts.h:85
edm::MallocOptionSetter::retrieveFromEnv
bool retrieveFromEnv()
Definition: MallocOpts.cc:166