OmniSciDB  7bf56492aa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Data_Namespace::DataMgr Class Reference

#include <DataMgr.h>

+ Collaboration diagram for Data_Namespace::DataMgr:

Classes

struct  SystemMemoryUsage
 

Public Member Functions

 DataMgr (const std::string &dataDir, const MapDParameters &mapd_parameters, const bool useGpus, const int numGpus, const int startGpu=0, const size_t reservedGpuMem=(1<< 27), const size_t numReaderThreads=0)
 
 ~DataMgr ()
 
AbstractBuffercreateChunkBuffer (const ChunkKey &key, const MemoryLevel memoryLevel, const int deviceId=0, const size_t page_size=0)
 
AbstractBuffergetChunkBuffer (const ChunkKey &key, const MemoryLevel memoryLevel, const int deviceId=0, const size_t numBytes=0)
 
void deleteChunksWithPrefix (const ChunkKey &keyPrefix)
 
void deleteChunksWithPrefix (const ChunkKey &keyPrefix, const MemoryLevel memLevel)
 
AbstractBufferalloc (const MemoryLevel memoryLevel, const int deviceId, const size_t numBytes)
 
void free (AbstractBuffer *buffer)
 
void freeAllBuffers ()
 
void copy (AbstractBuffer *destBuffer, AbstractBuffer *srcBuffer)
 
bool isBufferOnDevice (const ChunkKey &key, const MemoryLevel memLevel, const int deviceId)
 
std::vector< MemoryInfogetMemoryInfo (const MemoryLevel memLevel)
 
std::string dumpLevel (const MemoryLevel memLevel)
 
void clearMemory (const MemoryLevel memLevel)
 
const std::map< ChunkKey,
File_Namespace::FileBuffer * > & 
getChunkMap ()
 
void checkpoint (const int db_id, const int tb_id)
 
void getChunkMetadataVec (std::vector< std::pair< ChunkKey, ChunkMetadata >> &chunkMetadataVec)
 
void getChunkMetadataVecForKeyPrefix (std::vector< std::pair< ChunkKey, ChunkMetadata >> &chunkMetadataVec, const ChunkKey &keyPrefix)
 
bool gpusPresent ()
 
void removeTableRelatedDS (const int db_id, const int tb_id)
 
void setTableEpoch (const int db_id, const int tb_id, const int start_epoch)
 
size_t getTableEpoch (const int db_id, const int tb_id)
 
CudaMgr_Namespace::CudaMgrgetCudaMgr () const
 
File_Namespace::GlobalFileMgrgetGlobalFileMgr () const
 
SystemMemoryUsage getSystemMemoryUsage () const
 

Public Attributes

std::vector< int > levelSizes_
 

Private Member Functions

size_t getTotalSystemMemory () const
 
void populateMgrs (const MapDParameters &mapd_parameters, const size_t userSpecifiedNumReaderThreads)
 
void convertDB (const std::string basePath)
 
void checkpoint ()
 
void createTopLevelMetadata () const
 

Private Attributes

std::vector< std::vector
< AbstractBufferMgr * > > 
bufferMgrs_
 
std::unique_ptr
< CudaMgr_Namespace::CudaMgr
cudaMgr_
 
std::string dataDir_
 
bool hasGpus_
 
size_t reservedGpuMem_
 
std::map< ChunkKey,
std::shared_ptr
< mapd_shared_mutex > > 
chunkMutexMap_
 
mapd_shared_mutex chunkMutexMapMutex_
 

Friends

class GlobalFileMgr
 

Detailed Description

Definition at line 98 of file DataMgr.h.

Constructor & Destructor Documentation

Data_Namespace::DataMgr::DataMgr ( const std::string &  dataDir,
const MapDParameters mapd_parameters,
const bool  useGpus,
const int  numGpus,
const int  startGpu = 0,
const size_t  reservedGpuMem = (1 << 27),
const size_t  numReaderThreads = 0 
)

Definition at line 46 of file DataMgr.cpp.

References createTopLevelMetadata(), cudaMgr_, hasGpus_, populateMgrs(), and reservedGpuMem_.

53  : dataDir_(dataDir) {
54  if (useGpus) {
55  try {
56  cudaMgr_ = std::make_unique<CudaMgr_Namespace::CudaMgr>(numGpus, startGpu);
57  reservedGpuMem_ = reservedGpuMem;
58  hasGpus_ = true;
59  } catch (std::runtime_error& error) {
60  hasGpus_ = false;
61  }
62  } else {
63  hasGpus_ = false;
64  }
65 
66  populateMgrs(mapd_parameters, numReaderThreads);
68 }
void createTopLevelMetadata() const
Definition: DataMgr.cpp:224
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:175
void populateMgrs(const MapDParameters &mapd_parameters, const size_t userSpecifiedNumReaderThreads)
Definition: DataMgr.cpp:151
std::string dataDir_
Definition: DataMgr.h:176

+ Here is the call graph for this function:

Data_Namespace::DataMgr::~DataMgr ( )

Definition at line 70 of file DataMgr.cpp.

References bufferMgrs_.

70  {
71  int numLevels = bufferMgrs_.size();
72  for (int level = numLevels - 1; level >= 0; --level) {
73  for (size_t device = 0; device < bufferMgrs_[level].size(); device++) {
74  delete bufferMgrs_[level][device];
75  }
76  }
77 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174

Member Function Documentation

AbstractBuffer * Data_Namespace::DataMgr::alloc ( const MemoryLevel  memoryLevel,
const int  deviceId,
const size_t  numBytes 
)

Definition at line 435 of file DataMgr.cpp.

References bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by CudaAllocator::allocGpuAbstractBuffer().

437  {
438  const auto level = static_cast<int>(memoryLevel);
439  CHECK_LT(deviceId, levelSizes_[level]);
440  return bufferMgrs_[level][deviceId]->alloc(numBytes);
441 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
std::vector< int > levelSizes_
Definition: DataMgr.h:153
#define CHECK_LT(x, y)
Definition: Logger.h:207

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::checkpoint ( const int  db_id,
const int  tb_id 
)

Definition at line 467 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by Catalog_Namespace::Catalog::checkpoint().

467  {
468  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
469  // use reverse iterator so we start at GPU level, then CPU then DISK
470  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
471  (*deviceIt)->checkpoint(db_id, tb_id);
472  }
473  }
474 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::checkpoint ( )
private

Definition at line 476 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by convertDB().

476  {
477  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
478  // use reverse iterator so we start at GPU level, then CPU then DISK
479  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
480  (*deviceIt)->checkpoint();
481  }
482  }
483 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::clearMemory ( const MemoryLevel  memLevel)

Definition at line 361 of file DataMgr.cpp.

References bufferMgrs_, cudaMgr_, Data_Namespace::GPU_LEVEL, logger::INFO, and LOG.

Referenced by Executor::clearMemory().

361  {
362  // if gpu we need to iterate through all the buffermanagers for each card
363  if (memLevel == MemoryLevel::GPU_LEVEL) {
364  if (cudaMgr_) {
365  int numGpus = cudaMgr_->getDeviceCount();
366  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
367  LOG(INFO) << "clear slabs on gpu " << gpuNum;
368  bufferMgrs_[memLevel][gpuNum]->clearSlabs();
369  }
370  } else {
371  throw std::runtime_error("Unable to clear GPU memory: No GPUs detected");
372  }
373  } else {
374  bufferMgrs_[memLevel][0]->clearSlabs();
375  }
376 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
#define LOG(tag)
Definition: Logger.h:188
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:175

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::convertDB ( const std::string  basePath)
private

Definition at line 198 of file DataMgr.cpp.

References bufferMgrs_, checkpoint(), logger::FATAL, File_Namespace::GlobalFileMgr::getDefaultPageSize(), logger::INFO, and LOG.

198  {
199  /* check that "mapd_data" directory exists and it's empty */
200  std::string mapdDataPath(basePath + "/../mapd_data/");
201  boost::filesystem::path path(mapdDataPath);
202  if (boost::filesystem::exists(path)) {
203  if (!boost::filesystem::is_directory(path)) {
204  LOG(FATAL) << "Path to directory mapd_data to convert DB is not a directory.";
205  }
206  } else { // data directory does not exist
207  LOG(FATAL) << "Path to directory mapd_data to convert DB does not exist.";
208  }
209 
210  GlobalFileMgr* gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
211  size_t defaultPageSize = gfm->getDefaultPageSize();
212  LOG(INFO) << "Database conversion started.";
213  FileMgr* fm_base_db =
214  new FileMgr(gfm,
215  defaultPageSize,
216  basePath); // this call also copies data into new DB structure
217  delete fm_base_db;
218 
219  /* write content of DB into newly created/converted DB structure & location */
220  checkpoint(); // outputs data files as well as metadata files
221  LOG(INFO) << "Database conversion completed.";
222 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
#define LOG(tag)
Definition: Logger.h:188
size_t getDefaultPageSize() const

+ Here is the call graph for this function:

void Data_Namespace::DataMgr::copy ( AbstractBuffer destBuffer,
AbstractBuffer srcBuffer 
)

Definition at line 453 of file DataMgr.cpp.

References Data_Namespace::AbstractBuffer::getDeviceId(), Data_Namespace::AbstractBuffer::getMemoryPtr(), Data_Namespace::AbstractBuffer::getType(), Data_Namespace::AbstractBuffer::size(), and Data_Namespace::AbstractBuffer::write().

453  {
454  destBuffer->write(srcBuffer->getMemoryPtr(),
455  srcBuffer->size(),
456  0,
457  srcBuffer->getType(),
458  srcBuffer->getDeviceId());
459 }
virtual size_t size() const =0
virtual int8_t * getMemoryPtr()=0
virtual MemoryLevel getType() const =0
virtual void write(int8_t *src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int src_device_id=-1)=0
virtual int getDeviceId() const

+ Here is the call graph for this function:

AbstractBuffer * Data_Namespace::DataMgr::createChunkBuffer ( const ChunkKey key,
const MemoryLevel  memoryLevel,
const int  deviceId = 0,
const size_t  page_size = 0 
)

Definition at line 397 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by Chunk_NS::Chunk::createChunkBuffer().

400  {
401  int level = static_cast<int>(memoryLevel);
402  return bufferMgrs_[level][deviceId]->createBuffer(key, page_size);
403 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::createTopLevelMetadata ( ) const
private

Definition at line 224 of file DataMgr.cpp.

References bufferMgrs_, and File_Namespace::GlobalFileMgr::getFileMgr().

Referenced by DataMgr().

225  { // create metadata shared by all tables of all DBs
226  ChunkKey chunkKey(2);
227  chunkKey[0] = 0; // top level db_id
228  chunkKey[1] = 0; // top level tb_id
229 
230  GlobalFileMgr* gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
231  auto fm_top = gfm->getFileMgr(chunkKey);
232  if (dynamic_cast<File_Namespace::FileMgr*>(fm_top)) {
233  static_cast<File_Namespace::FileMgr*>(fm_top)->createTopLevelMetadata();
234  }
235 }
std::vector< int > ChunkKey
Definition: types.h:35
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
void createTopLevelMetadata() const
Definition: DataMgr.cpp:224
AbstractBufferMgr * getFileMgr(const int db_id, const int tb_id)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::deleteChunksWithPrefix ( const ChunkKey keyPrefix)

Definition at line 415 of file DataMgr.cpp.

References bufferMgrs_, and levelSizes_.

Referenced by freeAllBuffers().

415  {
416  int numLevels = bufferMgrs_.size();
417  for (int level = numLevels - 1; level >= 0; --level) {
418  for (int device = 0; device < levelSizes_[level]; ++device) {
419  bufferMgrs_[level][device]->deleteBuffersWithPrefix(keyPrefix);
420  }
421  }
422 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
std::vector< int > levelSizes_
Definition: DataMgr.h:153

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::deleteChunksWithPrefix ( const ChunkKey keyPrefix,
const MemoryLevel  memLevel 
)

Definition at line 425 of file DataMgr.cpp.

References bufferMgrs_, and levelSizes_.

426  {
427  if (bufferMgrs_.size() <= memLevel) {
428  return;
429  }
430  for (int device = 0; device < levelSizes_[memLevel]; ++device) {
431  bufferMgrs_[memLevel][device]->deleteBuffersWithPrefix(keyPrefix);
432  }
433 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
std::vector< int > levelSizes_
Definition: DataMgr.h:153
std::string Data_Namespace::DataMgr::dumpLevel ( const MemoryLevel  memLevel)

Definition at line 347 of file DataMgr.cpp.

References bufferMgrs_, cudaMgr_, and Data_Namespace::GPU_LEVEL.

347  {
348  // if gpu we need to iterate through all the buffermanagers for each card
349  if (memLevel == MemoryLevel::GPU_LEVEL) {
350  int numGpus = cudaMgr_->getDeviceCount();
351  std::ostringstream tss;
352  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
353  tss << bufferMgrs_[memLevel][gpuNum]->printSlabs();
354  }
355  return tss.str();
356  } else {
357  return bufferMgrs_[memLevel][0]->printSlabs();
358  }
359 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:175
void Data_Namespace::DataMgr::free ( AbstractBuffer buffer)

Definition at line 443 of file DataMgr.cpp.

References bufferMgrs_, Data_Namespace::AbstractBuffer::getDeviceId(), and Data_Namespace::AbstractBuffer::getType().

Referenced by ThrustAllocator::deallocate(), CudaAllocator::free(), CudaAllocator::freeGpuAbstractBuffer(), and ThrustAllocator::~ThrustAllocator().

443  {
444  int level = static_cast<int>(buffer->getType());
445  bufferMgrs_[level][buffer->getDeviceId()]->free(buffer);
446 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
virtual MemoryLevel getType() const =0
virtual int getDeviceId() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::freeAllBuffers ( )

Definition at line 448 of file DataMgr.cpp.

References deleteChunksWithPrefix().

Referenced by Executor::executeWorkUnitImpl().

448  {
449  ChunkKey keyPrefix = {-1};
450  deleteChunksWithPrefix(keyPrefix);
451 }
std::vector< int > ChunkKey
Definition: types.h:35
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:415

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AbstractBuffer * Data_Namespace::DataMgr::getChunkBuffer ( const ChunkKey key,
const MemoryLevel  memoryLevel,
const int  deviceId = 0,
const size_t  numBytes = 0 
)

Definition at line 405 of file DataMgr.cpp.

References bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by Chunk_NS::Chunk::getChunkBuffer().

408  {
409  const auto level = static_cast<size_t>(memoryLevel);
410  CHECK_LT(level, levelSizes_.size()); // make sure we have a legit buffermgr
411  CHECK_LT(deviceId, levelSizes_[level]); // make sure we have a legit buffermgr
412  return bufferMgrs_[level][deviceId]->getBuffer(key, numBytes);
413 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
std::vector< int > levelSizes_
Definition: DataMgr.h:153
#define CHECK_LT(x, y)
Definition: Logger.h:207

+ Here is the caller graph for this function:

const std::map<ChunkKey, File_Namespace::FileBuffer*>& Data_Namespace::DataMgr::getChunkMap ( )
void Data_Namespace::DataMgr::getChunkMetadataVec ( std::vector< std::pair< ChunkKey, ChunkMetadata >> &  chunkMetadataVec)

Definition at line 384 of file DataMgr.cpp.

References bufferMgrs_.

385  {
386  // Can we always assume this will just be at the disklevel bc we just
387  // started?
388  bufferMgrs_[0][0]->getChunkMetadataVec(chunkMetadataVec);
389 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
void Data_Namespace::DataMgr::getChunkMetadataVecForKeyPrefix ( std::vector< std::pair< ChunkKey, ChunkMetadata >> &  chunkMetadataVec,
const ChunkKey keyPrefix 
)

Definition at line 391 of file DataMgr.cpp.

References bufferMgrs_.

393  {
394  bufferMgrs_[0][0]->getChunkMetadataVecForKeyPrefix(chunkMetadataVec, keyPrefix);
395 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
CudaMgr_Namespace::CudaMgr* Data_Namespace::DataMgr::getCudaMgr ( ) const
inline

Definition at line 149 of file DataMgr.h.

References cudaMgr_.

Referenced by copy_from_gpu(), copy_to_gpu(), CudaAllocator::copyFromDevice(), CudaAllocator::copyToDevice(), CudaAllocator::CudaAllocator(), get_available_gpus(), Executor::isArchPascalOrLater(), CudaAllocator::setDeviceMem(), and CudaAllocator::zeroDeviceMem().

149 { return cudaMgr_.get(); }
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:175

+ Here is the caller graph for this function:

GlobalFileMgr * Data_Namespace::DataMgr::getGlobalFileMgr ( ) const

Definition at line 498 of file DataMgr.cpp.

References bufferMgrs_, and CHECK().

Referenced by TableArchiver::dumpTable(), Catalog_Namespace::Catalog::getTableDataDirectories(), and TableArchiver::restoreTable().

498  {
499  auto global_file_mgr = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
500  CHECK(global_file_mgr);
501  return global_file_mgr;
502 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< MemoryInfo > Data_Namespace::DataMgr::getMemoryInfo ( const MemoryLevel  memLevel)

Definition at line 237 of file DataMgr.cpp.

References bufferMgrs_, Data_Namespace::MemoryData::chunk_key, Data_Namespace::CPU_LEVEL, cudaMgr_, Buffer_Namespace::BufferMgr::getAllocated(), Buffer_Namespace::BufferMgr::getMaxSize(), Buffer_Namespace::BufferMgr::getPageSize(), Buffer_Namespace::BufferMgr::getSlabSegments(), Data_Namespace::GPU_LEVEL, hasGpus_, Data_Namespace::MemoryInfo::isAllocationCapped, Buffer_Namespace::BufferMgr::isAllocationCapped(), Data_Namespace::MemoryInfo::maxNumPages, Data_Namespace::MemoryData::memStatus, Data_Namespace::MemoryInfo::nodeMemoryData, Data_Namespace::MemoryInfo::numPageAllocated, Data_Namespace::MemoryData::numPages, Data_Namespace::MemoryInfo::pageSize, Data_Namespace::MemoryData::slabNum, Data_Namespace::MemoryData::startPage, and Data_Namespace::MemoryData::touch.

Referenced by Executor::executeWorkUnitImpl().

237  {
238  // TODO (vraj) : Reduce the duplicate code
239  std::vector<MemoryInfo> memInfo;
240  if (memLevel == MemoryLevel::CPU_LEVEL) {
241  CpuBufferMgr* cpuBuffer =
242  dynamic_cast<CpuBufferMgr*>(bufferMgrs_[MemoryLevel::CPU_LEVEL][0]);
243  MemoryInfo mi;
244 
245  mi.pageSize = cpuBuffer->getPageSize();
246  mi.maxNumPages = cpuBuffer->getMaxSize() / mi.pageSize;
247  mi.isAllocationCapped = cpuBuffer->isAllocationCapped();
248  mi.numPageAllocated = cpuBuffer->getAllocated() / mi.pageSize;
249 
250  const std::vector<BufferList> slab_segments = cpuBuffer->getSlabSegments();
251  size_t numSlabs = slab_segments.size();
252 
253  for (size_t slabNum = 0; slabNum != numSlabs; ++slabNum) {
254  for (auto segIt : slab_segments[slabNum]) {
255  MemoryData md;
256  md.slabNum = slabNum;
257  md.startPage = segIt.start_page;
258  md.numPages = segIt.num_pages;
259  md.touch = segIt.last_touched;
260  md.memStatus = segIt.mem_status;
261  md.chunk_key.insert(
262  md.chunk_key.end(), segIt.chunk_key.begin(), segIt.chunk_key.end());
263  mi.nodeMemoryData.push_back(md);
264  }
265  }
266  memInfo.push_back(mi);
267  } else if (hasGpus_) {
268  int numGpus = cudaMgr_->getDeviceCount();
269  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
270  GpuCudaBufferMgr* gpuBuffer =
271  dynamic_cast<GpuCudaBufferMgr*>(bufferMgrs_[MemoryLevel::GPU_LEVEL][gpuNum]);
272  MemoryInfo mi;
273 
274  mi.pageSize = gpuBuffer->getPageSize();
275  mi.maxNumPages = gpuBuffer->getMaxSize() / mi.pageSize;
276  mi.isAllocationCapped = gpuBuffer->isAllocationCapped();
277  mi.numPageAllocated = gpuBuffer->getAllocated() / mi.pageSize;
278  const std::vector<BufferList> slab_segments = gpuBuffer->getSlabSegments();
279  size_t numSlabs = slab_segments.size();
280 
281  for (size_t slabNum = 0; slabNum != numSlabs; ++slabNum) {
282  for (auto segIt : slab_segments[slabNum]) {
283  MemoryData md;
284  md.slabNum = slabNum;
285  md.startPage = segIt.start_page;
286  md.numPages = segIt.num_pages;
287  md.touch = segIt.last_touched;
288  md.chunk_key.insert(
289  md.chunk_key.end(), segIt.chunk_key.begin(), segIt.chunk_key.end());
290  md.memStatus = segIt.mem_status;
291  mi.nodeMemoryData.push_back(md);
292  }
293  }
294  memInfo.push_back(mi);
295  }
296  }
297  return memInfo;
298 }
size_t getAllocated() override
Definition: BufferMgr.cpp:483
std::vector< MemoryData > nodeMemoryData
Definition: DataMgr.h:64
Buffer_Namespace::MemStatus memStatus
Definition: DataMgr.h:56
size_t getMaxSize() override
Definition: BufferMgr.cpp:478
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
bool isAllocationCapped() override
Definition: BufferMgr.cpp:488
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:175
const std::vector< BufferList > & getSlabSegments()
Definition: BufferMgr.cpp:878
std::vector< int32_t > chunk_key
Definition: DataMgr.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DataMgr::SystemMemoryUsage Data_Namespace::DataMgr::getSystemMemoryUsage ( ) const

Definition at line 79 of file DataMgr.cpp.

References Data_Namespace::DataMgr::SystemMemoryUsage::free, Data_Namespace::DataMgr::SystemMemoryUsage::regular, Data_Namespace::DataMgr::SystemMemoryUsage::resident, Data_Namespace::DataMgr::SystemMemoryUsage::shared, Data_Namespace::DataMgr::SystemMemoryUsage::total, and Data_Namespace::DataMgr::SystemMemoryUsage::vtotal.

79  {
80  SystemMemoryUsage usage;
81 
82 #ifdef __linux__
83 
84  // Determine Linux available memory and total memory.
85  // Available memory is different from free memory because
86  // when Linux sees free memory, it tries to use it for
87  // stuff like disk caching. However, the memory is not
88  // reserved and is still available to be allocated by
89  // user processes.
90  // Parsing /proc/meminfo for this info isn't very elegant
91  // but as a virtual file it should be reasonably fast.
92  // See also:
93  // https://github.com/torvalds/linux/commit/34e431b0ae398fc54ea69ff85ec700722c9da773
95  usage.free = mi["MemAvailable"];
96  usage.total = mi["MemTotal"];
97 
98  // Determine process memory in use.
99  // See also:
100  // https://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-runtime-using-c
101  // http://man7.org/linux/man-pages/man5/proc.5.html
102  int64_t size = 0;
103  int64_t resident = 0;
104  int64_t shared = 0;
105 
106  std::ifstream fstatm("/proc/self/statm");
107  fstatm >> size >> resident >> shared;
108  fstatm.close();
109 
110  long page_size =
111  sysconf(_SC_PAGE_SIZE); // in case x86-64 is configured to use 2MB pages
112 
113  usage.resident = resident * page_size;
114  usage.vtotal = size * page_size;
115  usage.regular = (resident - shared) * page_size;
116  usage.shared = shared * page_size;
117 
118 #else
119 
120  usage.total = 0;
121  usage.free = 0;
122  usage.resident = 0;
123  usage.vtotal = 0;
124  usage.regular = 0;
125  usage.shared = 0;
126 
127 #endif
128 
129  return usage;
130 }
Parse /proc/meminfo into key/value pairs.
Definition: DataMgr.h:68
size_t Data_Namespace::DataMgr::getTableEpoch ( const int  db_id,
const int  tb_id 
)

Definition at line 494 of file DataMgr.cpp.

References bufferMgrs_.

494  {
495  return dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])->getTableEpoch(db_id, tb_id);
496 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
size_t getTableEpoch(const int db_id, const int tb_id)
Definition: DataMgr.cpp:494
size_t Data_Namespace::DataMgr::getTotalSystemMemory ( ) const
private

Definition at line 132 of file DataMgr.cpp.

Referenced by populateMgrs().

132  {
133 #ifdef __APPLE__
134  int mib[2];
135  size_t physical_memory;
136  size_t length;
137  // Get the Physical memory size
138  mib[0] = CTL_HW;
139  mib[1] = HW_MEMSIZE;
140  length = sizeof(size_t);
141  sysctl(mib, 2, &physical_memory, &length, NULL, 0);
142  return physical_memory;
143 
144 #else // Linux
145  long pages = sysconf(_SC_PHYS_PAGES);
146  long page_size = sysconf(_SC_PAGE_SIZE);
147  return pages * page_size;
148 #endif
149 }

+ Here is the caller graph for this function:

bool Data_Namespace::DataMgr::gpusPresent ( )
inline

Definition at line 144 of file DataMgr.h.

References hasGpus_.

Referenced by get_available_gpus().

144 { return hasGpus_; }

+ Here is the caller graph for this function:

bool Data_Namespace::DataMgr::isBufferOnDevice ( const ChunkKey key,
const MemoryLevel  memLevel,
const int  deviceId 
)

Definition at line 378 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by Chunk_NS::Chunk::isChunkOnDevice().

380  {
381  return bufferMgrs_[memLevel][deviceId]->isBufferOnDevice(key);
382 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::populateMgrs ( const MapDParameters mapd_parameters,
const size_t  userSpecifiedNumReaderThreads 
)
private

Definition at line 151 of file DataMgr.cpp.

References bufferMgrs_, MapDParameters::cpu_buffer_mem_bytes, cudaMgr_, dataDir_, getTotalSystemMemory(), GlobalFileMgr, MapDParameters::gpu_buffer_mem_bytes, hasGpus_, logger::INFO, levelSizes_, LOG, reservedGpuMem_, and VLOG.

Referenced by DataMgr().

152  {
153  bufferMgrs_.resize(2);
154  bufferMgrs_[0].push_back(new GlobalFileMgr(0, dataDir_, userSpecifiedNumReaderThreads));
155  levelSizes_.push_back(1);
156  size_t cpuBufferSize = mapd_parameters.cpu_buffer_mem_bytes;
157  if (cpuBufferSize == 0) { // if size is not specified
158  const auto total_system_memory = getTotalSystemMemory();
159  VLOG(1) << "Detected " << (float)total_system_memory / (1024 * 1024)
160  << "M of total system memory.";
161  cpuBufferSize = total_system_memory *
162  0.8; // should get free memory instead of this ugly heuristic
163  }
164  size_t cpuSlabSize = std::min(static_cast<size_t>(1L << 32), cpuBufferSize);
165  // cpuSlabSize -= cpuSlabSize % 512 == 0 ? 0 : 512 - (cpuSlabSize % 512);
166  cpuSlabSize = (cpuSlabSize / 512) * 512;
167  LOG(INFO) << "cpuSlabSize is " << (float)cpuSlabSize / (1024 * 1024) << "M";
168  LOG(INFO) << "memory pool for CPU is " << (float)cpuBufferSize / (1024 * 1024) << "M";
169  if (hasGpus_) {
170  LOG(INFO) << "reserved GPU memory is " << (float)reservedGpuMem_ / (1024 * 1024)
171  << "M includes render buffer allocation";
172  bufferMgrs_.resize(3);
173  bufferMgrs_[1].push_back(new CpuBufferMgr(
174  0, cpuBufferSize, cudaMgr_.get(), cpuSlabSize, 512, bufferMgrs_[0][0]));
175  levelSizes_.push_back(1);
176  int numGpus = cudaMgr_->getDeviceCount();
177  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
178  size_t gpuMaxMemSize =
179  mapd_parameters.gpu_buffer_mem_bytes != 0
180  ? mapd_parameters.gpu_buffer_mem_bytes
181  : (cudaMgr_->getDeviceProperties(gpuNum)->globalMem) - (reservedGpuMem_);
182  size_t gpuSlabSize = std::min(static_cast<size_t>(1L << 31), gpuMaxMemSize);
183  gpuSlabSize -= gpuSlabSize % 512 == 0 ? 0 : 512 - (gpuSlabSize % 512);
184  LOG(INFO) << "gpuSlabSize is " << (float)gpuSlabSize / (1024 * 1024) << "M";
185  LOG(INFO) << "memory pool for GPU " << gpuNum << " is "
186  << (float)gpuMaxMemSize / (1024 * 1024) << "M";
187  bufferMgrs_[2].push_back(new GpuCudaBufferMgr(
188  gpuNum, gpuMaxMemSize, cudaMgr_.get(), gpuSlabSize, 512, bufferMgrs_[1][0]));
189  }
190  levelSizes_.push_back(numGpus);
191  } else {
192  bufferMgrs_[1].push_back(new CpuBufferMgr(
193  0, cpuBufferSize, cudaMgr_.get(), cpuSlabSize, 512, bufferMgrs_[0][0]));
194  levelSizes_.push_back(1);
195  }
196 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
std::vector< int > levelSizes_
Definition: DataMgr.h:153
#define LOG(tag)
Definition: Logger.h:188
size_t gpu_buffer_mem_bytes
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:175
size_t getTotalSystemMemory() const
Definition: DataMgr.cpp:132
size_t cpu_buffer_mem_bytes
#define VLOG(n)
Definition: Logger.h:291
friend class GlobalFileMgr
Definition: DataMgr.h:99
std::string dataDir_
Definition: DataMgr.h:176

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::removeTableRelatedDS ( const int  db_id,
const int  tb_id 
)

Definition at line 485 of file DataMgr.cpp.

References bufferMgrs_.

485  {
486  dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])->removeTableRelatedDS(db_id, tb_id);
487 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
void removeTableRelatedDS(const int db_id, const int tb_id)
Definition: DataMgr.cpp:485
void Data_Namespace::DataMgr::setTableEpoch ( const int  db_id,
const int  tb_id,
const int  start_epoch 
)

Definition at line 489 of file DataMgr.cpp.

References bufferMgrs_.

489  {
490  dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0])
491  ->setTableEpoch(db_id, tb_id, start_epoch);
492 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:174
void setTableEpoch(const int db_id, const int tb_id, const int start_epoch)
Definition: DataMgr.cpp:489

Friends And Related Function Documentation

friend class GlobalFileMgr
friend

Definition at line 99 of file DataMgr.h.

Referenced by populateMgrs().

Member Data Documentation

std::map<ChunkKey, std::shared_ptr<mapd_shared_mutex> > Data_Namespace::DataMgr::chunkMutexMap_
private

Definition at line 179 of file DataMgr.h.

mapd_shared_mutex Data_Namespace::DataMgr::chunkMutexMapMutex_
private

Definition at line 180 of file DataMgr.h.

std::unique_ptr<CudaMgr_Namespace::CudaMgr> Data_Namespace::DataMgr::cudaMgr_
private

Definition at line 175 of file DataMgr.h.

Referenced by clearMemory(), DataMgr(), dumpLevel(), getCudaMgr(), getMemoryInfo(), and populateMgrs().

std::string Data_Namespace::DataMgr::dataDir_
private

Definition at line 176 of file DataMgr.h.

Referenced by populateMgrs().

bool Data_Namespace::DataMgr::hasGpus_
private

Definition at line 177 of file DataMgr.h.

Referenced by DataMgr(), getMemoryInfo(), gpusPresent(), and populateMgrs().

std::vector<int> Data_Namespace::DataMgr::levelSizes_

Definition at line 153 of file DataMgr.h.

Referenced by alloc(), deleteChunksWithPrefix(), getChunkBuffer(), and populateMgrs().

size_t Data_Namespace::DataMgr::reservedGpuMem_
private

Definition at line 178 of file DataMgr.h.

Referenced by DataMgr(), and populateMgrs().


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