ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
LWPool Class Reference

#include <LWPool.h>

Collaboration diagram for LWPool:

Public Member Functions

 LWPool (unsigned chunksize)
 
 ~LWPool ()
 
char * acquire ()
 
char * acquireClean ()
 
void release (char *)
 
void erase ()
 
long long getMemDishedOut () const
 
long long getMemOwned () const
 

Static Public Member Functions

static long long getMotherMemOwned ()
 
static void forceCleanupMotherPool ()
 

Private Member Functions

 LWPool (const LWPool &)
 
LWPooloperator= (const LWPool &)
 
LWPoolAreagrow ()
 
void freeArea (LWPoolArea *)
 
unsigned growSize () const
 
unsigned chunkSize () const
 
void init ()
 
bool belongsInArea (char *, LWPoolArea *) const
 
char * searchAcquire ()
 
LWPoolAreafindArea (char *)
 
bool isMotherPool () const
 
 LWPool (unsigned chunksize, unsigned growsize)
 

Static Private Member Functions

static LWPoolgetMotherPool ()
 

Private Attributes

const unsigned m_chunksize
 
const unsigned m_growsize
 
unsigned m_nchunksPerArea
 
std::vector< LWPoolArea * > m_areas
 
LWPoolAream_likelyNonEmptyArea
 
LWPoolAream_likelyReleaseArea
 
std::mutex m_mutex
 

Detailed Description

Definition at line 24 of file LWPool.h.

Constructor & Destructor Documentation

◆ LWPool() [1/3]

LWPool::LWPool ( unsigned  chunksize)

Definition at line 32 of file LWPool.cxx.

33  : m_chunksize(chunksize),
35 {
36  //Normal constructor
37  init();
38 }

◆ ~LWPool()

LWPool::~LWPool ( )

Definition at line 61 of file LWPool.cxx.

62 {
63  erase();
64 }

◆ LWPool() [2/3]

LWPool::LWPool ( const LWPool )
private

◆ LWPool() [3/3]

LWPool::LWPool ( unsigned  chunksize,
unsigned  growsize 
)
private

Definition at line 41 of file LWPool.cxx.

42  : m_chunksize(chunksize),
43  m_growsize(ngrowsize)
44 {
45  //Mother pool constructor
46  init();
47 }

Member Function Documentation

◆ acquire()

char* LWPool::acquire ( )

◆ acquireClean()

char * LWPool::acquireClean ( )

Definition at line 105 of file LWPool.cxx.

106 {
107  char * c = acquire();
108  memset(c,0,m_chunksize);
109  return c;
110 }

◆ belongsInArea()

bool LWPool::belongsInArea ( char *  ,
LWPoolArea  
) const
private

◆ chunkSize()

unsigned LWPool::chunkSize ( ) const
inlineprivate

Definition at line 54 of file LWPool.h.

54 { return m_chunksize; }

◆ erase()

void LWPool::erase ( )

Definition at line 67 of file LWPool.cxx.

68 {
69  std::scoped_lock lock (m_mutex);
70  for (LWPoolArea* a : m_areas) {
71  char * c = reinterpret_cast<char*>(a);
72  if (isMotherPool())
73  delete[] c;
74  else
76  }
77  m_areas.clear();
78  m_likelyNonEmptyArea = nullptr;
79  m_likelyReleaseArea = nullptr;
80 }

◆ findArea()

LWPoolArea * LWPool::findArea ( char *  c)
private

Definition at line 131 of file LWPool.cxx.

132 {
133  //Figure out which area (if any), we belong in. For reasons of cpu
134  //and (in particular) cache-efficiency we do not actually ask the
135  //classes themselves, rather we just look at their addresses (since
136  //their addresses marks the beginning of the pool-areas also):
137 
139  std::lower_bound(m_areas.begin(),m_areas.end(),reinterpret_cast<void*>(c));
140  LWPoolArea* a(areaIt==m_areas.end()?m_areas.back():*(--areaIt));
141  assert(a&&a->belongsInArea(c)&&"Trying to release chunk back to a mem-pool from which it was never acquired");
142  assert(reinterpret_cast<char*>(a)<c&&c<reinterpret_cast<char*>(a)+m_growsize);
143  return a;
144 }

◆ forceCleanupMotherPool()

void LWPool::forceCleanupMotherPool ( )
static

Definition at line 206 of file LWPool.cxx.

207 {
208  getMotherPool()->erase();
209 }

◆ freeArea()

void LWPool::freeArea ( LWPoolArea a)
private

Definition at line 174 of file LWPool.cxx.

175 {
176  assert(!m_areas.empty());
177 
178  if (m_likelyNonEmptyArea==a)
180  if (m_likelyReleaseArea==a)
182 
183  //Find index of the area (fixme: use binary search!):
184  unsigned i(0);
185  const unsigned nareasplusone(m_areas.size()+1);
186  for (;i<nareasplusone;++i) {
187  if (a==m_areas.at(i))
188  break;
189  }
190  assert(i<m_areas.size());
191  const unsigned nareasminusone(nareasplusone-2);
192  if (i<nareasminusone) {
193  //This is not the last area in the list, so move those above down by one:
194  for (unsigned j=i;j<nareasminusone;++j)
195  m_areas.at(j) = m_areas.at(j+1);
196  }
197  m_areas.resize(nareasminusone);
198  char * c = reinterpret_cast<char*>(a);
199  if (isMotherPool())
200  delete[] c;
201  else
202  getMotherPool()->release(c);
203 }

◆ getMemDishedOut()

long long LWPool::getMemDishedOut ( ) const

Definition at line 96 of file LWPool.cxx.

96  {
97  std::scoped_lock lock (m_mutex);
98  long long l(0);
99  for (LWPoolArea* a : m_areas)
100  l += a->getMemDishedOut();
101  return l;
102 }

◆ getMemOwned()

long long LWPool::getMemOwned ( ) const

Definition at line 89 of file LWPool.cxx.

90 {
91  std::scoped_lock lock (m_mutex);
92  return m_growsize*m_areas.size();
93 }

◆ getMotherMemOwned()

long long LWPool::getMotherMemOwned ( )
static

Definition at line 83 of file LWPool.cxx.

84 {
85  return getMotherPool()->getMemOwned();
86 }

◆ getMotherPool()

LWPool * LWPool::getMotherPool ( )
staticprivate

Definition at line 20 of file LWPool.cxx.

21 {
22  //The mother pool parameters determine the growth
23  //dynamics of all pools:
24  static constexpr unsigned extra = sizeof(LWPool)+sizeof(LWPoolAreaBookKeeper)+8;
25  static constexpr unsigned poolgrow = 16384+extra;
26  static constexpr unsigned motherpoolgrow = poolgrow*32+extra;
27  static LWPool mother ATLAS_THREAD_SAFE (poolgrow,motherpoolgrow);
28  return &mother;
29 }

◆ grow()

LWPoolArea * LWPool::grow ( )
private

Definition at line 147 of file LWPool.cxx.

148 {
149  char * c(0);
150  if (isMotherPool()) {
152  c = new char[m_growsize];
153  } else {
154  c = getMotherPool()->acquire();
155  }
156  assert(c);
158 
159  if (m_nchunksPerArea==UINT_MAX)
160  m_nchunksPerArea = a->totalNumberOfChunks();
161 
162  unsigned debug(m_areas.capacity());
163  m_areas.push_back(a);
164  if (debug!=m_areas.capacity())
165  LWHISTMALLOC(sizeof(m_areas.at(0))*m_areas.capacity());
166  sort(m_areas.begin(),m_areas.end());//always keep sorted
167  //fixme: make slightly faster by manually inserting and moving up mem.
169 
170  return a;
171 }

◆ growSize()

unsigned LWPool::growSize ( ) const
inlineprivate

Definition at line 53 of file LWPool.h.

53 { return m_growsize; }

◆ init()

void LWPool::init ( )
private

Definition at line 50 of file LWPool.cxx.

51 {
54  m_nchunksPerArea = UINT_MAX;
55  assert(m_chunksize>=1);
56  LWHISTMALLOC(sizeof(m_areas[0])*16);
57  m_areas.reserve(16);
58 }

◆ isMotherPool()

bool LWPool::isMotherPool ( ) const
inlineprivate

Definition at line 61 of file LWPool.h.

61 { return this==getMotherPool(); }

◆ operator=()

LWPool& LWPool::operator= ( const LWPool )
private

◆ release()

void LWPool::release ( char *  )

◆ searchAcquire()

char * LWPool::searchAcquire ( )
private

Definition at line 113 of file LWPool.cxx.

114 {
116  for (LWPoolArea* a : m_areas) {
117  char * c = a->acquire();
118  if (c) {
120  return c;
121  }
122  }
123 
124  //3) All areas empty - create a new area:
126  assert(m_likelyNonEmptyArea);
127  return m_likelyNonEmptyArea->acquire();
128 }

Member Data Documentation

◆ m_areas

std::vector<LWPoolArea*> LWPool::m_areas
private

Definition at line 43 of file LWPool.h.

◆ m_chunksize

const unsigned LWPool::m_chunksize
private

Definition at line 40 of file LWPool.h.

◆ m_growsize

const unsigned LWPool::m_growsize
private

Definition at line 41 of file LWPool.h.

◆ m_likelyNonEmptyArea

LWPoolArea* LWPool::m_likelyNonEmptyArea
private

Definition at line 44 of file LWPool.h.

◆ m_likelyReleaseArea

LWPoolArea* LWPool::m_likelyReleaseArea
private

Definition at line 45 of file LWPool.h.

◆ m_mutex

std::mutex LWPool::m_mutex
mutableprivate

Definition at line 46 of file LWPool.h.

◆ m_nchunksPerArea

unsigned LWPool::m_nchunksPerArea
private

Definition at line 42 of file LWPool.h.


The documentation for this class was generated from the following files:
LWPoolArea::create
static LWPoolArea * create(unsigned chunksize, char *mem, unsigned length_of_mem, unsigned nchunks=UINT_MAX)
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LWPoolAreaBookKeeper
Definition: LWPoolAreaBookKeeper.h:30
LWPool::m_likelyNonEmptyArea
LWPoolArea * m_likelyNonEmptyArea
Definition: LWPool.h:44
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
LWPool::getMemOwned
long long getMemOwned() const
Definition: LWPool.cxx:89
std::sort
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:554
LWPool::m_nchunksPerArea
unsigned m_nchunksPerArea
Definition: LWPool.h:42
LWPool::acquire
char * acquire()
LWPool::grow
LWPoolArea * grow()
Definition: LWPool.cxx:147
LWPool::init
void init()
Definition: LWPool.cxx:50
LWPool::chunkSize
unsigned chunkSize() const
Definition: LWPool.h:54
lumiFormat.i
int i
Definition: lumiFormat.py:92
LWPool::m_growsize
const unsigned m_growsize
Definition: LWPool.h:41
LWPool::getMotherPool
static LWPool * getMotherPool()
Definition: LWPool.cxx:20
LWPoolArea::acquire
char * acquire()
python.handimod.extra
int extra
Definition: handimod.py:522
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
LWPoolArea
Definition: LWPoolArea.h:25
LWPool::m_areas
std::vector< LWPoolArea * > m_areas
Definition: LWPool.h:43
LWPool::release
void release(char *)
a
TList * a
Definition: liststreamerinfos.cxx:10
LWHISTMALLOC
#define LWHISTMALLOC(s)
Definition: LWPool.h:73
LWPool::m_chunksize
const unsigned m_chunksize
Definition: LWPool.h:40
LWPool::isMotherPool
bool isMotherPool() const
Definition: LWPool.h:61
LWPool::LWPool
LWPool(unsigned chunksize)
Definition: LWPool.cxx:32
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
LWPool
Definition: LWPool.h:24
LWPool::m_mutex
std::mutex m_mutex
Definition: LWPool.h:46
python.compressB64.c
def c
Definition: compressB64.py:93
LWPool::erase
void erase()
Definition: LWPool.cxx:67
LWPool::m_likelyReleaseArea
LWPoolArea * m_likelyReleaseArea
Definition: LWPool.h:45