17 #ifndef PREGION_MGR_HPP 18 #define PREGION_MGR_HPP 42 Instance_->initPRegionTable();
43 Instance_->setCacheParams();
50 Instance_->shutPRegionTable();
69 assert(rid < getNumPRegions() &&
"Region index out of range!");
70 return instantiateNewPRegion(rid);
75 bool does_need_cache_line_alignment,
bool does_need_logging)
const;
78 void freeMem(
void *ptr,
bool should_log =
true)
const;
79 void deleteMem(
void *ptr,
bool should_log =
true)
const;
87 int *is_created =
nullptr);
89 bool is_in_recovery =
false);
110 pthread_mutex_t PRegionTableLock_;
111 std::atomic<PRegionExtentMap*> ExtentMap_;
113 enum OpType { kCreate_, kFind_, kClose_, kDelete_ };
115 PRegionMgr() : PRegionTable_{
nullptr}, PRegionTableFD_{-1},
117 { pthread_mutex_init(&PRegionTableLock_, NULL); }
119 ~
PRegionMgr() {
delete ExtentMap_.load(std::memory_order_relaxed); }
126 void acquireTableLock()
127 { pthread_mutex_lock(&PRegionTableLock_); }
128 void releaseTableLock()
129 { pthread_mutex_unlock(&PRegionTableLock_); }
132 void acquireExclusiveFLock()
133 { flock(PRegionTableFD_, LOCK_EX); }
135 { flock(PRegionTableFD_, LOCK_UN); }
137 uint32_t getNumPRegions()
const 138 {
return *(
static_cast<uint32_t*
>(PRegionTable_)); }
140 void setNumPRegions(uint32_t);
142 void *computePRegionBaseAddr(
void *addr)
const;
145 return reinterpret_cast<PRegion*
>(
146 static_cast<char*
>(PRegionTable_) +
147 sizeof(uint32_t) + rid *
sizeof(
PRegion));
150 void *computeNewPRegionBaseAddr()
const;
152 PRegion *getPRegionArrayPtr()
const;
154 void initPRegionTable();
155 void shutPRegionTable();
157 void setCacheParams();
158 int getCacheLineSize()
const;
160 void initPRegionRoot(
PRegion*);
162 region_id_t initNewPRegionImpl(
const char *name,
int flags);
163 region_id_t mapNewPRegion(
const char *name,
int flags,
void *base_addr);
164 void mapNewPRegionImpl(
166 int flags,
void *base_addr);
167 void initExistingPRegionImpl(
PRegion *preg,
const char *name,
int flags);
168 void mapExistingPRegion(
PRegion *preg,
const char *name,
int flags);
169 int mapFile(
const char *name,
int flags,
void *base_addr,
bool does_exist);
173 void insertExtent(
void *first_addr,
void *last_addr,
region_id_t rid);
174 void deleteExtent(
void *first_addr,
void *last_addr,
region_id_t rid);
181 size_t sz,
region_id_t rid,
bool does_need_cache_line_alignment,
182 bool does_need_logging)
const 185 sz, does_need_cache_line_alignment, does_need_logging);
203 bool does_need_cache_line_alignment =
false;
204 bool does_need_logging =
false;
206 sz, rid, does_need_cache_line_alignment, does_need_logging);
212 bool does_need_cache_line_alignment =
true;
214 sz, rid, does_need_cache_line_alignment, should_log);
217 inline PRegion *PRegionMgr::getPRegionArrayPtr()
const 219 return reinterpret_cast<PRegion*
>(
220 static_cast<char*
>(PRegionTable_) +
sizeof(uint32_t));
232 inline void *PRegionMgr::computePRegionBaseAddr(
void *addr)
const 234 assert(addr >= (static_cast<char*>(PRegionTable_) +
kPRegionSize_) &&
235 addr < (static_cast<char*>(PRegionTable_) +
237 "Location not in any persistent region!");
239 ((reinterpret_cast<uint64_t>(addr) -
246 inline void *PRegionMgr::computeNewPRegionBaseAddr()
const 248 uint32_t num_regions = getNumPRegions();
250 else return static_cast<char*
>(
252 reinterpret_cast<char*
>(getPRegionArrayPtr()) +
253 (num_regions - 1) *
sizeof(
PRegion))->
254 get_base_addr()) + kPRegionSize_;
264 #if defined(ATLAS_ALLOC_DUMP) 265 assert(Instance_ &&
"Region manager does not exist!");
266 std::cout <<
"------- Start of region information -------" << std::endl;
267 std::cout <<
"Region table base: " << PRegionTable_ << std::endl;
268 PRegion *pregion_arr_ptr = getPRegionArrayPtr();
270 for (; curr < getNumPRegions(); ++curr, ++pregion_arr_ptr)
272 std::cout <<
"------- End of region information -------" << std::endl;
281 inline void PRegionMgr::tracePRegion(
region_id_t rid, OpType op)
const 283 #if defined(ATLAS_ALLOC_TRACE) 285 std::cout <<
"[Atlas] " <<
286 (op == kCreate_ ?
"Created " :
287 op == kFind_ ?
"Found " :
288 op == kClose_ ?
"Closed " :
289 op == kDelete_ ?
"Deleted " :
291 <<
"region with name=" << rgn->
get_name()
302 inline void PRegionMgr::statsPRegion(
region_id_t rid)
const 304 #if defined(ATLAS_ALLOC_STATS) static void deleteInstance()
Definition: pregion_mgr.hpp:48
static bool hasInstance()
Definition: pregion_mgr.hpp:61
Definition: pregion_mgr_util.hpp:27
static PRegionMgr & createInstance()
Definition: pregion_mgr.hpp:39
Definition: pregion_mgr.hpp:35
Definition: pregion.hpp:31
region_id_t get_id() const
Definition: pregion.hpp:52
const uint32_t kInvalidPRegion_
Definition: pregion_configs.hpp:33
void deleteForcefullyPRegion(const char *name)
Definition: pregion_mgr.cpp:310
const char * get_name() const
Definition: pregion.hpp:57
const uint32_t kMaxNumPRegions_
Definition: pregion_configs.hpp:29
void * reallocMem(void *, size_t)
Definition: pregion.cpp:156
uint32_t region_id_t
Definition: pregion_configs.hpp:22
void * allocMem(size_t sz, bool does_need_cache_line_alignment, bool does_need_logging)
Definition: pregion.cpp:26
const uint64_t kPRegionSize_
Definition: pregion_configs.hpp:28
const uint64_t kPRegionsBase_
Definition: pregion_configs.hpp:35
region_id_t findOrCreatePRegion(const char *name, int flags, int *is_created=nullptr)
Definition: pregion_mgr.cpp:96
void * callocMem(size_t nmemb, size_t sz, region_id_t) const
Definition: pregion_mgr.hpp:188
void closePRegion(region_id_t, bool is_deleting=false)
Definition: pregion_mgr.cpp:236
bool isInOpenPRegion(const void *addr, size_t sz) const
Definition: pregion_mgr.hpp:65
void freeMemImpl(region_id_t rgn_id, void *ptr, bool should_log) const
Definition: pregion_mgr.cpp:76
void * allocMemWithoutLogging(size_t sz, region_id_t rid) const
Definition: pregion_mgr.hpp:200
void deleteMem(void *ptr, bool should_log=true) const
Definition: pregion_mgr.cpp:65
void * allocMem(size_t sz, region_id_t rid, bool does_need_cache_line_alignment, bool does_need_logging) const
Definition: pregion_mgr.hpp:180
void deleteForcefullyAllPRegions()
Definition: pregion_mgr.cpp:347
uint32_t rgn_id
Definition: malloc_free_test.c:22
std::pair< void *,region_id_t > ensurePRegionMapped(void *addr)
Definition: pregion_mgr.cpp:636
void * allocMemCacheLineAligned(size_t sz, region_id_t rid, bool should_log) const
Definition: pregion_mgr.hpp:209
void * get_base_addr() const
Definition: pregion.hpp:53
void deletePRegion(const char *name)
Definition: pregion_mgr.cpp:275
void setPRegionRoot(region_id_t, void *new_root) const
Definition: pregion_mgr.cpp:370
region_id_t findPRegion(const char *name, int flags, bool is_in_recovery=false)
Definition: pregion_mgr.cpp:155
PRegion * searchPRegion(const char *name) const
Definition: pregion_mgr.cpp:608
void dumpDebugInfo() const
Definition: pregion.hpp:151
void * callocMem(size_t nmemb, size_t sz)
Definition: pregion.cpp:143
region_id_t getOpenPRegionId(const void *addr, size_t sz) const
Definition: pregion_mgr.cpp:625
region_id_t createPRegion(const char *name, int flags)
Definition: pregion_mgr.cpp:200
void * getRoot() const
Definition: pregion.hpp:91
Definition: atlas_alloc_cpp.hpp:21
void * reallocMem(void *, size_t, region_id_t) const
Definition: pregion_mgr.hpp:194
static PRegionMgr & getInstance()
Definition: pregion_mgr.hpp:56
void printStats()
Definition: pregion.hpp:163
PRegion * getPRegion(region_id_t rid) const
Definition: pregion_mgr.hpp:68
void * getPRegionRoot(region_id_t) const
Definition: pregion_mgr.hpp:223
void dumpDebugInfo() const
Definition: pregion_mgr.hpp:262
void freeMem(void *ptr, bool should_log=true) const
Definition: pregion_mgr.cpp:48