OmniSciDB  06b3bd477c
 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 SystemParameters &system_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 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 (ChunkMetadataVector &chunkMetadataVec)
 
void getChunkMetadataVecForKeyPrefix (ChunkMetadataVector &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
 
foreign_storage::ForeignStorageMgrgetForeignStorageMgr () const
 

Static Public Member Functions

static size_t getTotalSystemMemory ()
 

Public Attributes

std::vector< int > levelSizes_
 

Private Member Functions

void populateMgrs (const SystemParameters &system_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::mutex buffer_access_mutex_
 

Friends

class GlobalFileMgr
 

Detailed Description

Definition at line 160 of file DataMgr.h.

Constructor & Destructor Documentation

Data_Namespace::DataMgr::DataMgr ( const std::string &  dataDir,
const SystemParameters system_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 49 of file DataMgr.cpp.

References createTopLevelMetadata(), cudaMgr_, logger::ERROR, hasGpus_, LOG, populateMgrs(), and reservedGpuMem_.

56  : dataDir_(dataDir) {
57  if (useGpus) {
58  try {
59  cudaMgr_ = std::make_unique<CudaMgr_Namespace::CudaMgr>(numGpus, startGpu);
60  reservedGpuMem_ = reservedGpuMem;
61  hasGpus_ = true;
62  } catch (const std::exception& e) {
63  LOG(ERROR) << "Unable to instantiate CudaMgr, falling back to CPU-only mode. "
64  << e.what();
65  hasGpus_ = false;
66  }
67  } else {
68  hasGpus_ = false;
69  }
70 
71  populateMgrs(system_parameters, numReaderThreads);
73 }
#define LOG(tag)
Definition: Logger.h:188
void createTopLevelMetadata() const
Definition: DataMgr.cpp:273
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:236
void populateMgrs(const SystemParameters &system_parameters, const size_t userSpecifiedNumReaderThreads)
Definition: DataMgr.cpp:160
std::string dataDir_
Definition: DataMgr.h:237

+ Here is the call graph for this function:

Data_Namespace::DataMgr::~DataMgr ( )

Definition at line 75 of file DataMgr.cpp.

References bufferMgrs_.

75  {
76  int numLevels = bufferMgrs_.size();
77  for (int level = numLevels - 1; level >= 0; --level) {
78  for (size_t device = 0; device < bufferMgrs_[level].size(); device++) {
79  delete bufferMgrs_[level][device];
80  }
81  }
82 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235

Member Function Documentation

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

Definition at line 452 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by CudaAllocator::allocGpuAbstractBuffer().

454  {
455  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
456  const auto level = static_cast<int>(memoryLevel);
457  CHECK_LT(deviceId, levelSizes_[level]);
458  return bufferMgrs_[level][deviceId]->alloc(numBytes);
459 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
std::vector< int > levelSizes_
Definition: DataMgr.h:211
#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 481 of file DataMgr.cpp.

References bufferMgrs_.

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

481  {
482  // TODO(adb): do we need a buffer mgr lock here?
483  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
484  // use reverse iterator so we start at GPU level, then CPU then DISK
485  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
486  (*deviceIt)->checkpoint(db_id, tb_id);
487  }
488  }
489 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::checkpoint ( )
private

Definition at line 491 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by convertDB().

491  {
492  // TODO(adb): SAA
493  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
494  // use reverse iterator so we start at GPU level, then CPU then DISK
495  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
496  (*deviceIt)->checkpoint();
497  }
498  }
499 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235

+ Here is the caller graph for this function:

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

Definition at line 370 of file DataMgr.cpp.

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

Referenced by Executor::clearMemory().

370  {
371  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
372 
373  // if gpu we need to iterate through all the buffermanagers for each card
374  if (memLevel == MemoryLevel::GPU_LEVEL) {
375  if (cudaMgr_) {
376  int numGpus = cudaMgr_->getDeviceCount();
377  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
378  LOG(INFO) << "clear slabs on gpu " << gpuNum;
379  bufferMgrs_[memLevel][gpuNum]->clearSlabs();
380  }
381  } else {
382  throw std::runtime_error("Unable to clear GPU memory: No GPUs detected");
383  }
384  } else {
385  bufferMgrs_[memLevel][0]->clearSlabs();
386  }
387 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
#define LOG(tag)
Definition: Logger.h:188
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:236

+ Here is the caller graph for this function:

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

Definition at line 240 of file DataMgr.cpp.

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

240  {
241  // no need for locking, as this is only called in the constructor
242 
243  /* check that "mapd_data" directory exists and it's empty */
244  std::string mapdDataPath(basePath + "/../mapd_data/");
245  boost::filesystem::path path(mapdDataPath);
246  if (boost::filesystem::exists(path)) {
247  if (!boost::filesystem::is_directory(path)) {
248  LOG(FATAL) << "Path to directory mapd_data to convert DB is not a directory.";
249  }
250  } else { // data directory does not exist
251  LOG(FATAL) << "Path to directory mapd_data to convert DB does not exist.";
252  }
253 
254  GlobalFileMgr* gfm;
255  if (g_enable_fsi) {
256  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
257  } else {
258  gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
259  }
260  size_t defaultPageSize = gfm->getDefaultPageSize();
261  LOG(INFO) << "Database conversion started.";
262  FileMgr* fm_base_db =
263  new FileMgr(gfm,
264  defaultPageSize,
265  basePath); // this call also copies data into new DB structure
266  delete fm_base_db;
267 
268  /* write content of DB into newly created/converted DB structure & location */
269  checkpoint(); // outputs data files as well as metadata files
270  LOG(INFO) << "Database conversion completed.";
271 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
#define LOG(tag)
Definition: Logger.h:188
size_t getDefaultPageSize() const
bool g_enable_fsi
Definition: Catalog.cpp:90
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:526

+ Here is the call graph for this function:

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

Definition at line 467 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().

467  {
468  destBuffer->write(srcBuffer->getMemoryPtr(),
469  srcBuffer->size(),
470  0,
471  srcBuffer->getType(),
472  srcBuffer->getDeviceId());
473 }
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 408 of file DataMgr.cpp.

References buffer_access_mutex_, and bufferMgrs_.

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

411  {
412  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
413  int level = static_cast<int>(memoryLevel);
414  return bufferMgrs_[level][deviceId]->createBuffer(key, page_size);
415 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235

+ Here is the caller graph for this function:

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

Definition at line 273 of file DataMgr.cpp.

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

Referenced by DataMgr().

274  { // create metadata shared by all tables of all DBs
275  ChunkKey chunkKey(2);
276  chunkKey[0] = 0; // top level db_id
277  chunkKey[1] = 0; // top level tb_id
278 
279  GlobalFileMgr* gfm;
280  if (g_enable_fsi) {
281  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
282  } else {
283  gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
284  }
285  auto fm_top = gfm->getFileMgr(chunkKey);
286  if (dynamic_cast<File_Namespace::FileMgr*>(fm_top)) {
287  static_cast<File_Namespace::FileMgr*>(fm_top)->createTopLevelMetadata();
288  }
289 }
std::vector< int > ChunkKey
Definition: types.h:35
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
void createTopLevelMetadata() const
Definition: DataMgr.cpp:273
AbstractBufferMgr * getFileMgr(const int db_id, const int tb_id)
bool g_enable_fsi
Definition: Catalog.cpp:90
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:526

+ 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 428 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, and levelSizes_.

428  {
429  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
430 
431  int numLevels = bufferMgrs_.size();
432  for (int level = numLevels - 1; level >= 0; --level) {
433  for (int device = 0; device < levelSizes_[level]; ++device) {
434  bufferMgrs_[level][device]->deleteBuffersWithPrefix(keyPrefix);
435  }
436  }
437 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
std::vector< int > levelSizes_
Definition: DataMgr.h:211
void Data_Namespace::DataMgr::deleteChunksWithPrefix ( const ChunkKey keyPrefix,
const MemoryLevel  memLevel 
)

Definition at line 440 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, and levelSizes_.

441  {
442  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
443 
444  if (bufferMgrs_.size() <= memLevel) {
445  return;
446  }
447  for (int device = 0; device < levelSizes_[memLevel]; ++device) {
448  bufferMgrs_[memLevel][device]->deleteBuffersWithPrefix(keyPrefix);
449  }
450 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
std::vector< int > levelSizes_
Definition: DataMgr.h:211
std::string Data_Namespace::DataMgr::dumpLevel ( const MemoryLevel  memLevel)

Definition at line 354 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, cudaMgr_, and Data_Namespace::GPU_LEVEL.

354  {
355  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
356 
357  // if gpu we need to iterate through all the buffermanagers for each card
358  if (memLevel == MemoryLevel::GPU_LEVEL) {
359  int numGpus = cudaMgr_->getDeviceCount();
360  std::ostringstream tss;
361  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
362  tss << bufferMgrs_[memLevel][gpuNum]->printSlabs();
363  }
364  return tss.str();
365  } else {
366  return bufferMgrs_[memLevel][0]->printSlabs();
367  }
368 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:236
void Data_Namespace::DataMgr::free ( AbstractBuffer buffer)

Definition at line 461 of file DataMgr.cpp.

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

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

461  {
462  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
463  int level = static_cast<int>(buffer->getType());
464  bufferMgrs_[level][buffer->getDeviceId()]->free(buffer);
465 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
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:

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

Definition at line 417 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, CHECK_LT, and levelSizes_.

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

420  {
421  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
422  const auto level = static_cast<size_t>(memoryLevel);
423  CHECK_LT(level, levelSizes_.size()); // make sure we have a legit buffermgr
424  CHECK_LT(deviceId, levelSizes_[level]); // make sure we have a legit buffermgr
425  return bufferMgrs_[level][deviceId]->getBuffer(key, numBytes);
426 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
std::vector< int > levelSizes_
Definition: DataMgr.h:211
#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 ( ChunkMetadataVector chunkMetadataVec)

Definition at line 396 of file DataMgr.cpp.

References bufferMgrs_.

396  {
397  // Can we always assume this will just be at the disklevel bc we just
398  // started?
399  // access to this object is locked by the file mgr
400  bufferMgrs_[0][0]->getChunkMetadataVec(chunkMetadataVec);
401 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
void Data_Namespace::DataMgr::getChunkMetadataVecForKeyPrefix ( ChunkMetadataVector chunkMetadataVec,
const ChunkKey keyPrefix 
)

Definition at line 403 of file DataMgr.cpp.

References bufferMgrs_.

404  {
405  bufferMgrs_[0][0]->getChunkMetadataVecForKeyPrefix(chunkMetadataVec, keyPrefix);
406 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
CudaMgr_Namespace::CudaMgr* Data_Namespace::DataMgr::getCudaMgr ( ) const
inline

Definition at line 207 of file DataMgr.h.

References cudaMgr_.

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

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

+ Here is the caller graph for this function:

foreign_storage::ForeignStorageMgr * Data_Namespace::DataMgr::getForeignStorageMgr ( ) const

Definition at line 553 of file DataMgr.cpp.

References bufferMgrs_, and g_enable_fsi.

553  {
554  if (g_enable_fsi) {
555  return dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getForeignStorageMgr();
556  }
557  return nullptr;
558 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
foreign_storage::ForeignStorageMgr * getForeignStorageMgr() const
Definition: DataMgr.cpp:553
bool g_enable_fsi
Definition: Catalog.cpp:90
GlobalFileMgr * Data_Namespace::DataMgr::getGlobalFileMgr ( ) const

Definition at line 526 of file DataMgr.cpp.

References bufferMgrs_, CHECK(), and g_enable_fsi.

Referenced by convertDB(), createTopLevelMetadata(), TableArchiver::dumpTable(), Catalog_Namespace::Catalog::getTableDataDirectories(), getTableEpoch(), TableArchiver::restoreTable(), and setTableEpoch().

526  {
527  GlobalFileMgr* global_file_mgr;
528  if (g_enable_fsi) {
529  global_file_mgr =
530  dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
531  } else {
532  global_file_mgr = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
533  }
534  CHECK(global_file_mgr);
535  return global_file_mgr;
536 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
CHECK(cgen_state)
bool g_enable_fsi
Definition: Catalog.cpp:90
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:526

+ 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 291 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, CHECK(), 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.

291  {
292  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
293 
294  std::vector<MemoryInfo> mem_info;
295  if (memLevel == MemoryLevel::CPU_LEVEL) {
296  CpuBufferMgr* cpu_buffer =
297  dynamic_cast<CpuBufferMgr*>(bufferMgrs_[MemoryLevel::CPU_LEVEL][0]);
298  CHECK(cpu_buffer);
299  MemoryInfo mi;
300 
301  mi.pageSize = cpu_buffer->getPageSize();
302  mi.maxNumPages = cpu_buffer->getMaxSize() / mi.pageSize;
303  mi.isAllocationCapped = cpu_buffer->isAllocationCapped();
304  mi.numPageAllocated = cpu_buffer->getAllocated() / mi.pageSize;
305 
306  const auto& slab_segments = cpu_buffer->getSlabSegments();
307  for (size_t slab_num = 0; slab_num < slab_segments.size(); ++slab_num) {
308  for (auto segment : slab_segments[slab_num]) {
309  MemoryData md;
310  md.slabNum = slab_num;
311  md.startPage = segment.start_page;
312  md.numPages = segment.num_pages;
313  md.touch = segment.last_touched;
314  md.memStatus = segment.mem_status;
315  md.chunk_key.insert(
316  md.chunk_key.end(), segment.chunk_key.begin(), segment.chunk_key.end());
317  mi.nodeMemoryData.push_back(md);
318  }
319  }
320  mem_info.push_back(mi);
321  } else if (hasGpus_) {
322  int numGpus = cudaMgr_->getDeviceCount();
323  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
324  GpuCudaBufferMgr* gpu_buffer =
325  dynamic_cast<GpuCudaBufferMgr*>(bufferMgrs_[MemoryLevel::GPU_LEVEL][gpuNum]);
326  CHECK(gpu_buffer);
327  MemoryInfo mi;
328 
329  mi.pageSize = gpu_buffer->getPageSize();
330  mi.maxNumPages = gpu_buffer->getMaxSize() / mi.pageSize;
331  mi.isAllocationCapped = gpu_buffer->isAllocationCapped();
332  mi.numPageAllocated = gpu_buffer->getAllocated() / mi.pageSize;
333 
334  const auto& slab_segments = gpu_buffer->getSlabSegments();
335  for (size_t slab_num = 0; slab_num < slab_segments.size(); ++slab_num) {
336  for (auto segment : slab_segments[slab_num]) {
337  MemoryData md;
338  md.slabNum = slab_num;
339  md.startPage = segment.start_page;
340  md.numPages = segment.num_pages;
341  md.touch = segment.last_touched;
342  md.chunk_key.insert(
343  md.chunk_key.end(), segment.chunk_key.begin(), segment.chunk_key.end());
344  md.memStatus = segment.mem_status;
345  mi.nodeMemoryData.push_back(md);
346  }
347  }
348  mem_info.push_back(mi);
349  }
350  }
351  return mem_info;
352 }
size_t getAllocated() override
Definition: BufferMgr.cpp:493
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< MemoryData > nodeMemoryData
Definition: DataMgr.h:65
Buffer_Namespace::MemStatus memStatus
Definition: DataMgr.h:57
size_t getMaxSize() override
Definition: BufferMgr.cpp:488
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
CHECK(cgen_state)
bool isAllocationCapped() override
Definition: BufferMgr.cpp:498
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:236
const std::vector< BufferList > & getSlabSegments()
Definition: BufferMgr.cpp:886
std::vector< int32_t > chunk_key
Definition: DataMgr.h:56

+ Here is the call graph for this function:

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

Definition at line 84 of file DataMgr.cpp.

References Data_Namespace::DataMgr::SystemMemoryUsage::frag, Data_Namespace::DataMgr::SystemMemoryUsage::free, Data_Namespace::ProcBuddyinfoParser::getFragmentationPercent(), 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.

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

+ Here is the call graph for this function:

size_t Data_Namespace::DataMgr::getTableEpoch ( const int  db_id,
const int  tb_id 
)

Definition at line 516 of file DataMgr.cpp.

References bufferMgrs_, g_enable_fsi, getGlobalFileMgr(), and File_Namespace::GlobalFileMgr::getTableEpoch().

516  {
517  GlobalFileMgr* gfm;
518  if (g_enable_fsi) {
519  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
520  } else {
521  gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
522  }
523  return gfm->getTableEpoch(db_id, tb_id);
524 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
size_t getTableEpoch(const int db_id, const int tb_id)
bool g_enable_fsi
Definition: Catalog.cpp:90
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:526

+ Here is the call graph for this function:

size_t Data_Namespace::DataMgr::getTotalSystemMemory ( )
static

Definition at line 141 of file DataMgr.cpp.

Referenced by populateMgrs().

141  {
142 #ifdef __APPLE__
143  int mib[2];
144  size_t physical_memory;
145  size_t length;
146  // Get the Physical memory size
147  mib[0] = CTL_HW;
148  mib[1] = HW_MEMSIZE;
149  length = sizeof(size_t);
150  sysctl(mib, 2, &physical_memory, &length, NULL, 0);
151  return physical_memory;
152 
153 #else // Linux
154  long pages = sysconf(_SC_PHYS_PAGES);
155  long page_size = sysconf(_SC_PAGE_SIZE);
156  return pages * page_size;
157 #endif
158 }

+ Here is the caller graph for this function:

bool Data_Namespace::DataMgr::gpusPresent ( )
inline

Definition at line 202 of file DataMgr.h.

References hasGpus_.

Referenced by get_available_gpus().

202 { 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 389 of file DataMgr.cpp.

References buffer_access_mutex_, and bufferMgrs_.

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

391  {
392  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
393  return bufferMgrs_[memLevel][deviceId]->isBufferOnDevice(key);
394 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::populateMgrs ( const SystemParameters system_parameters,
const size_t  userSpecifiedNumReaderThreads 
)
private

Definition at line 160 of file DataMgr.cpp.

References bufferMgrs_, SystemParameters::cpu_buffer_mem_bytes, cudaMgr_, dataDir_, g_enable_fsi, getTotalSystemMemory(), GlobalFileMgr, SystemParameters::gpu_buffer_mem_bytes, hasGpus_, logger::INFO, levelSizes_, LOG, SystemParameters::max_cpu_slab_size, SystemParameters::max_gpu_slab_size, SystemParameters::min_cpu_slab_size, SystemParameters::min_gpu_slab_size, reservedGpuMem_, and VLOG.

Referenced by DataMgr().

161  {
162  // no need for locking, as this is only called in the constructor
163  bufferMgrs_.resize(2);
164  if (g_enable_fsi) {
165  bufferMgrs_[0].push_back(
166  new PersistentStorageMgr(dataDir_, userSpecifiedNumReaderThreads));
167  } else {
168  bufferMgrs_[0].push_back(
169  new GlobalFileMgr(0, dataDir_, userSpecifiedNumReaderThreads));
170  }
171  levelSizes_.push_back(1);
172  size_t page_size{512};
173  size_t cpuBufferSize = system_parameters.cpu_buffer_mem_bytes;
174  if (cpuBufferSize == 0) { // if size is not specified
175  const auto total_system_memory = getTotalSystemMemory();
176  VLOG(1) << "Detected " << (float)total_system_memory / (1024 * 1024)
177  << "M of total system memory.";
178  cpuBufferSize = total_system_memory *
179  0.8; // should get free memory instead of this ugly heuristic
180  }
181  size_t minCpuSlabSize = std::min(system_parameters.min_cpu_slab_size, cpuBufferSize);
182  minCpuSlabSize = (minCpuSlabSize / page_size) * page_size;
183  size_t maxCpuSlabSize = std::min(system_parameters.max_cpu_slab_size, cpuBufferSize);
184  maxCpuSlabSize = (maxCpuSlabSize / page_size) * page_size;
185  LOG(INFO) << "Min CPU Slab Size is " << (float)minCpuSlabSize / (1024 * 1024) << "MB";
186  LOG(INFO) << "Max CPU Slab Size is " << (float)maxCpuSlabSize / (1024 * 1024) << "MB";
187  LOG(INFO) << "Max memory pool size for CPU is " << (float)cpuBufferSize / (1024 * 1024)
188  << "MB";
189  if (hasGpus_) {
190  LOG(INFO) << "Reserved GPU memory is " << (float)reservedGpuMem_ / (1024 * 1024)
191  << "MB includes render buffer allocation";
192  bufferMgrs_.resize(3);
193  bufferMgrs_[1].push_back(new CpuBufferMgr(0,
194  cpuBufferSize,
195  cudaMgr_.get(),
196  minCpuSlabSize,
197  maxCpuSlabSize,
198  page_size,
199  bufferMgrs_[0][0]));
200  levelSizes_.push_back(1);
201  int numGpus = cudaMgr_->getDeviceCount();
202  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
203  size_t gpuMaxMemSize =
204  system_parameters.gpu_buffer_mem_bytes != 0
205  ? system_parameters.gpu_buffer_mem_bytes
206  : (cudaMgr_->getDeviceProperties(gpuNum)->globalMem) - (reservedGpuMem_);
207  size_t minGpuSlabSize =
208  std::min(system_parameters.min_gpu_slab_size, gpuMaxMemSize);
209  minGpuSlabSize = (minGpuSlabSize / page_size) * page_size;
210  size_t maxGpuSlabSize =
211  std::min(system_parameters.max_gpu_slab_size, gpuMaxMemSize);
212  maxGpuSlabSize = (maxGpuSlabSize / page_size) * page_size;
213  LOG(INFO) << "Min GPU Slab size for GPU " << gpuNum << " is "
214  << (float)minGpuSlabSize / (1024 * 1024) << "MB";
215  LOG(INFO) << "Max GPU Slab size for GPU " << gpuNum << " is "
216  << (float)maxGpuSlabSize / (1024 * 1024) << "MB";
217  LOG(INFO) << "Max memory pool size for GPU " << gpuNum << " is "
218  << (float)gpuMaxMemSize / (1024 * 1024) << "MB";
219  bufferMgrs_[2].push_back(new GpuCudaBufferMgr(gpuNum,
220  gpuMaxMemSize,
221  cudaMgr_.get(),
222  minGpuSlabSize,
223  maxGpuSlabSize,
224  page_size,
225  bufferMgrs_[1][0]));
226  }
227  levelSizes_.push_back(numGpus);
228  } else {
229  bufferMgrs_[1].push_back(new CpuBufferMgr(0,
230  cpuBufferSize,
231  cudaMgr_.get(),
232  minCpuSlabSize,
233  maxCpuSlabSize,
234  page_size,
235  bufferMgrs_[0][0]));
236  levelSizes_.push_back(1);
237  }
238 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
std::vector< int > levelSizes_
Definition: DataMgr.h:211
#define LOG(tag)
Definition: Logger.h:188
static size_t getTotalSystemMemory()
Definition: DataMgr.cpp:141
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:236
bool g_enable_fsi
Definition: Catalog.cpp:90
#define VLOG(n)
Definition: Logger.h:291
friend class GlobalFileMgr
Definition: DataMgr.h:161
std::string dataDir_
Definition: DataMgr.h:237

+ 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 501 of file DataMgr.cpp.

References buffer_access_mutex_, and bufferMgrs_.

501  {
502  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
503  bufferMgrs_[0][0]->removeTableRelatedDS(db_id, tb_id);
504 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:240
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
void Data_Namespace::DataMgr::setTableEpoch ( const int  db_id,
const int  tb_id,
const int  start_epoch 
)

Definition at line 506 of file DataMgr.cpp.

References bufferMgrs_, g_enable_fsi, getGlobalFileMgr(), and File_Namespace::GlobalFileMgr::setTableEpoch().

506  {
507  GlobalFileMgr* gfm;
508  if (g_enable_fsi) {
509  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
510  } else {
511  gfm = dynamic_cast<GlobalFileMgr*>(bufferMgrs_[0][0]);
512  }
513  gfm->setTableEpoch(db_id, tb_id, start_epoch);
514 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:235
void setTableEpoch(const int db_id, const int tb_id, const int start_epoch)
bool g_enable_fsi
Definition: Catalog.cpp:90
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:526

+ Here is the call graph for this function:

Friends And Related Function Documentation

friend class GlobalFileMgr
friend

Definition at line 161 of file DataMgr.h.

Referenced by populateMgrs().

Member Data Documentation

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

Definition at line 236 of file DataMgr.h.

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

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

Definition at line 237 of file DataMgr.h.

Referenced by populateMgrs().

bool Data_Namespace::DataMgr::hasGpus_
private

Definition at line 238 of file DataMgr.h.

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

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

Definition at line 211 of file DataMgr.h.

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

size_t Data_Namespace::DataMgr::reservedGpuMem_
private

Definition at line 239 of file DataMgr.h.

Referenced by DataMgr(), and populateMgrs().


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