LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::MallocOptionSetter Class Reference

#include "MallocOpts.h"

Public Types

using opt_type = MallocOpts::opt_type
 

Public Member Functions

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

Private Attributes

bool changed_
 
MallocOpts values_
 
std::string error_message_
 

Detailed Description

Definition at line 61 of file MallocOpts.h.

Member Typedef Documentation

Constructor & Destructor Documentation

art::MallocOptionSetter::MallocOptionSetter ( )

Definition at line 134 of file MallocOpts.cc.

References adjustMallocParams(), error_message_, hasErrors(), retrieveFromCpuType(), and retrieveFromEnv().

134  : changed_(false)
135  {
138  if (hasErrors()) {
139  std::cerr << "ERROR: Reset of malloc options has fails:\n"
140  << error_message_ << '\n';
141  }
142  }
143  }
std::string error_message_
Definition: MallocOpts.h:115
bool hasErrors() const
Definition: MallocOpts.h:70

Member Function Documentation

void art::MallocOptionSetter::adjustMallocParams ( )

Definition at line 146 of file MallocOpts.cc.

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

Referenced by MallocOptionSetter().

147  {
148  if (changed_ == false)
149  return; // only adjust if they changed
150  error_message_.clear();
151  changed_ = false;
152 
153 #ifdef M_MMAP_MAX
154  if (mallopt(M_MMAP_MAX, values_.mmap_max_) < 0)
155  error_message_ += "Could not set M_MMAP_MAX\n";
156 #endif
157 #ifdef M_TRIM_THRESHOLD
158  if (mallopt(M_TRIM_THRESHOLD, values_.trim_thr_) < 0)
159  error_message_ += "Could not set M_TRIM_THRESHOLD\n";
160 #endif
161 #ifdef M_TOP_PAD
162  if (mallopt(M_TOP_PAD, values_.top_pad_) < 0)
163  error_message_ += "ERROR: Could not set M_TOP_PAD\n";
164 #endif
165 #ifdef M_MMAP_THRESHOLD
166  if (mallopt(M_MMAP_THRESHOLD, values_.mmap_thr_) < 0)
167  error_message_ += "ERROR: Could not set M_MMAP_THRESHOLD\n";
168 #endif
169  }
opt_type mmap_max_
Definition: MallocOpts.h:41
opt_type top_pad_
Definition: MallocOpts.h:43
opt_type mmap_thr_
Definition: MallocOpts.h:44
std::string error_message_
Definition: MallocOpts.h:115
opt_type trim_thr_
Definition: MallocOpts.h:42
std::string art::MallocOptionSetter::error_message ( ) const
inline

Definition at line 75 of file MallocOpts.h.

76  {
77  return error_message_;
78  }
std::string error_message_
Definition: MallocOpts.h:115
MallocOpts art::MallocOptionSetter::get ( ) const
inline

Definition at line 106 of file MallocOpts.h.

107  {
108  return values_;
109  }
bool art::MallocOptionSetter::hasErrors ( ) const
inline

Definition at line 70 of file MallocOpts.h.

Referenced by MallocOptionSetter().

71  {
72  return !error_message_.empty();
73  }
std::string error_message_
Definition: MallocOpts.h:115
bool art::MallocOptionSetter::retrieveFromCpuType ( )

Definition at line 111 of file MallocOpts.cc.

References changed_, and values_.

Referenced by MallocOptionSetter().

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

Definition at line 172 of file MallocOpts.cc.

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

Referenced by MallocOptionSetter().

173  {
174  const char* par = getenv("ART_MALLOC_RESET");
175  if (par == 0)
176  return false; // leave quickly here
177  std::string spar(par);
178  bool rc = false;
179 
180  if (spar.size() > 1) {
181  std::istringstream ist(spar);
184 
185  if (ist.bad()) {
186  std::cerr
187  << "bad malloc options in ART_MALLOC_RESET: " << spar << '\n'
188  << "format is: "
189  << "ART_MALLOC_RESET=\"mmap_max trim_thres top_pad mmap_thres\"\n";
190  } else {
191  std::cout << "MALLOC_OPTIONS> Reset options: "
192  << "ART_MALLOC_RESET=" << par << '\n';
193  }
194  rc = true;
195  changed_ = true;
196  }
197 
198  return rc;
199  }
opt_type mmap_max_
Definition: MallocOpts.h:41
opt_type top_pad_
Definition: MallocOpts.h:43
opt_type mmap_thr_
Definition: MallocOpts.h:44
opt_type trim_thr_
Definition: MallocOpts.h:42
void art::MallocOptionSetter::set_mmap_max ( opt_type  mmap_max)
inline

Definition at line 81 of file MallocOpts.h.

82  {
83  values_.mmap_max_ = mmap_max;
84  changed_ = true;
85  }
opt_type mmap_max_
Definition: MallocOpts.h:41
void art::MallocOptionSetter::set_mmap_thr ( opt_type  mmap_thr)
inline

Definition at line 99 of file MallocOpts.h.

100  {
101  values_.mmap_thr_ = mmap_thr;
102  changed_ = true;
103  }
opt_type mmap_thr_
Definition: MallocOpts.h:44
void art::MallocOptionSetter::set_top_pad ( opt_type  top_pad)
inline

Definition at line 93 of file MallocOpts.h.

94  {
95  values_.top_pad_ = top_pad;
96  changed_ = true;
97  }
opt_type top_pad_
Definition: MallocOpts.h:43
void art::MallocOptionSetter::set_trim_thr ( opt_type  trim_thr)
inline

Definition at line 87 of file MallocOpts.h.

88  {
89  values_.trim_thr_ = trim_thr;
90  changed_ = true;
91  }
opt_type trim_thr_
Definition: MallocOpts.h:42

Member Data Documentation

bool art::MallocOptionSetter::changed_
private

Definition at line 112 of file MallocOpts.h.

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

std::string art::MallocOptionSetter::error_message_
private

Definition at line 115 of file MallocOpts.h.

Referenced by adjustMallocParams(), and MallocOptionSetter().

MallocOpts art::MallocOptionSetter::values_
private

Definition at line 113 of file MallocOpts.h.

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


The documentation for this class was generated from the following files: