OmniSciDB  bf83d84833
 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, std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr, const bool useGpus, const size_t reservedGpuMem=(1<< 27), const size_t numReaderThreads=0, const DiskCacheConfig cacheConfig=DiskCacheConfig())
 
 ~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 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
 
PersistentStorageMgrgetPersistentStorageMgr () const
 
void resetPersistentStorage (const DiskCacheConfig &cache_config, const size_t num_reader_threads, const SystemParameters &sys_params)
 

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, const DiskCacheConfig &cache_config)
 
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,
std::unique_ptr< CudaMgr_Namespace::CudaMgr cudaMgr,
const bool  useGpus,
const size_t  reservedGpuMem = (1 << 27),
const size_t  numReaderThreads = 0,
const DiskCacheConfig  cacheConfig = DiskCacheConfig() 
)
explicit

Definition at line 44 of file DataMgr.cpp.

51  : cudaMgr_{std::move(cudaMgr)}
52  , dataDir_{dataDir}
53  , hasGpus_{false}
54  , reservedGpuMem_{reservedGpuMem} {
55  if (useGpus) {
56  if (cudaMgr_) {
57  hasGpus_ = true;
58  } else {
59  LOG(ERROR) << "CudaMgr instance is invalid, falling back to CPU-only mode.";
60  hasGpus_ = false;
61  }
62  } else {
63  // NOTE: useGpus == false with a valid cudaMgr is a potentially valid configuration.
64  // i.e. QueryEngine can be set to cpu-only for a cuda-enabled build, but still have
65  // rendering enabled. The renderer would require a CudaMgr in this case, in addition
66  // to a GpuCudaBufferMgr for cuda-backed thrust allocations.
67  // We're still setting hasGpus_ to false in that case tho to enforce cpu-only query
68  // execution.
69  hasGpus_ = false;
70  }
71 
72  populateMgrs(system_parameters, numReaderThreads, cache_config);
74 }
#define LOG(tag)
Definition: Logger.h:188
void populateMgrs(const SystemParameters &system_parameters, const size_t userSpecifiedNumReaderThreads, const DiskCacheConfig &cache_config)
Definition: DataMgr.cpp:180
void createTopLevelMetadata() const
Definition: DataMgr.cpp:288
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:239
std::string dataDir_
Definition: DataMgr.h:240
Data_Namespace::DataMgr::~DataMgr ( )

Definition at line 76 of file DataMgr.cpp.

References bufferMgrs_.

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

Member Function Documentation

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

Definition at line 460 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, CHECK_LT, and levelSizes_.

Referenced by ThrustAllocator::allocate(), ThrustAllocator::allocateScopedBuffer(), and CudaAllocator::allocGpuAbstractBuffer().

462  {
463  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
464  const auto level = static_cast<int>(memoryLevel);
465  CHECK_LT(deviceId, levelSizes_[level]);
466  return bufferMgrs_[level][deviceId]->alloc(numBytes);
467 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
std::vector< int > levelSizes_
Definition: DataMgr.h:210
#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 489 of file DataMgr.cpp.

References bufferMgrs_.

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

489  {
490  // TODO(adb): do we need a buffer mgr lock here?
491  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
492  // use reverse iterator so we start at GPU level, then CPU then DISK
493  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
494  (*deviceIt)->checkpoint(db_id, tb_id);
495  }
496  }
497 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238

+ Here is the caller graph for this function:

void Data_Namespace::DataMgr::checkpoint ( )
private

Definition at line 499 of file DataMgr.cpp.

References bufferMgrs_.

Referenced by convertDB().

499  {
500  // TODO(adb): SAA
501  for (auto levelIt = bufferMgrs_.rbegin(); levelIt != bufferMgrs_.rend(); ++levelIt) {
502  // use reverse iterator so we start at GPU level, then CPU then DISK
503  for (auto deviceIt = levelIt->begin(); deviceIt != levelIt->end(); ++deviceIt) {
504  (*deviceIt)->checkpoint();
505  }
506  }
507 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238

+ Here is the caller graph for this function:

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

Definition at line 385 of file DataMgr.cpp.

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

Referenced by Executor::clearMemory().

385  {
386  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
387 
388  // if gpu we need to iterate through all the buffermanagers for each card
389  if (memLevel == MemoryLevel::GPU_LEVEL) {
390  if (cudaMgr_) {
391  int numGpus = cudaMgr_->getDeviceCount();
392  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
393  LOG(INFO) << "clear slabs on gpu " << gpuNum;
394  bufferMgrs_[memLevel][gpuNum]->clearSlabs();
395  }
396  } else {
397  LOG(WARNING) << "Unable to clear GPU memory: No GPUs detected";
398  }
399  } else {
400  bufferMgrs_[memLevel][0]->clearSlabs();
401  }
402 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
#define LOG(tag)
Definition: Logger.h:188
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:239

+ Here is the caller graph for this function:

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

Definition at line 257 of file DataMgr.cpp.

References bufferMgrs_, CHECK, checkpoint(), logger::FATAL, getGlobalFileMgr(), logger::INFO, and LOG.

257  {
258  // no need for locking, as this is only called in the constructor
259 
260  /* check that "mapd_data" directory exists and it's empty */
261  std::string mapdDataPath(basePath + "/../mapd_data/");
262  boost::filesystem::path path(mapdDataPath);
263  if (boost::filesystem::exists(path)) {
264  if (!boost::filesystem::is_directory(path)) {
265  LOG(FATAL) << "Path to directory mapd_data to convert DB is not a directory.";
266  }
267  } else { // data directory does not exist
268  LOG(FATAL) << "Path to directory mapd_data to convert DB does not exist.";
269  }
270 
271  File_Namespace::GlobalFileMgr* gfm{nullptr};
272  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
273  CHECK(gfm);
274 
275  size_t defaultPageSize = gfm->getDefaultPageSize();
276  LOG(INFO) << "Database conversion started.";
278  gfm,
279  defaultPageSize,
280  basePath); // this call also copies data into new DB structure
281  delete fm_base_db;
282 
283  /* write content of DB into newly created/converted DB structure & location */
284  checkpoint(); // outputs data files as well as metadata files
285  LOG(INFO) << "Database conversion completed.";
286 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
#define LOG(tag)
Definition: Logger.h:188
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:528
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

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

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

475  {
476  destBuffer->write(srcBuffer->getMemoryPtr(),
477  srcBuffer->size(),
478  0,
479  srcBuffer->getType(),
480  srcBuffer->getDeviceId());
481 }
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

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

References buffer_access_mutex_, and bufferMgrs_.

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

419  {
420  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
421  int level = static_cast<int>(memoryLevel);
422  return bufferMgrs_[level][deviceId]->createBuffer(key, page_size);
423 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238

+ Here is the caller graph for this function:

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

Definition at line 288 of file DataMgr.cpp.

References bufferMgrs_, CHECK, and getGlobalFileMgr().

Referenced by resetPersistentStorage().

289  { // create metadata shared by all tables of all DBs
290  ChunkKey chunkKey(2);
291  chunkKey[0] = 0; // top level db_id
292  chunkKey[1] = 0; // top level tb_id
293 
294  File_Namespace::GlobalFileMgr* gfm{nullptr};
295  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
296  CHECK(gfm);
297 
298  auto fm_top = gfm->getFileMgr(chunkKey);
299  if (dynamic_cast<File_Namespace::FileMgr*>(fm_top)) {
300  static_cast<File_Namespace::FileMgr*>(fm_top)->createTopLevelMetadata();
301  }
302 }
std::vector< int > ChunkKey
Definition: types.h:37
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
void createTopLevelMetadata() const
Definition: DataMgr.cpp:288
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:528
#define CHECK(condition)
Definition: Logger.h:197

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

References buffer_access_mutex_, bufferMgrs_, and levelSizes_.

Referenced by UpdelRoll::commitUpdate().

436  {
437  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
438 
439  int numLevels = bufferMgrs_.size();
440  for (int level = numLevels - 1; level >= 0; --level) {
441  for (int device = 0; device < levelSizes_[level]; ++device) {
442  bufferMgrs_[level][device]->deleteBuffersWithPrefix(keyPrefix);
443  }
444  }
445 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
std::vector< int > levelSizes_
Definition: DataMgr.h:210

+ Here is the caller graph for this function:

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

Definition at line 448 of file DataMgr.cpp.

References buffer_access_mutex_, bufferMgrs_, and levelSizes_.

449  {
450  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
451 
452  if (bufferMgrs_.size() <= memLevel) {
453  return;
454  }
455  for (int device = 0; device < levelSizes_[memLevel]; ++device) {
456  bufferMgrs_[memLevel][device]->deleteBuffersWithPrefix(keyPrefix);
457  }
458 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
std::vector< int > levelSizes_
Definition: DataMgr.h:210
std::string Data_Namespace::DataMgr::dumpLevel ( const MemoryLevel  memLevel)

Definition at line 369 of file DataMgr.cpp.

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

369  {
370  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
371 
372  // if gpu we need to iterate through all the buffermanagers for each card
373  if (memLevel == MemoryLevel::GPU_LEVEL) {
374  int numGpus = cudaMgr_->getDeviceCount();
375  std::ostringstream tss;
376  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
377  tss << bufferMgrs_[memLevel][gpuNum]->printSlabs();
378  }
379  return tss.str();
380  } else {
381  return bufferMgrs_[memLevel][0]->printSlabs();
382  }
383 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:239
void Data_Namespace::DataMgr::free ( AbstractBuffer buffer)

Definition at line 469 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(), BaselineHashTable::~BaselineHashTable(), CudaAllocator::~CudaAllocator(), InValuesBitmap::~InValuesBitmap(), PerfectHashTable::~PerfectHashTable(), and ThrustAllocator::~ThrustAllocator().

469  {
470  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
471  int level = static_cast<int>(buffer->getType());
472  bufferMgrs_[level][buffer->getDeviceId()]->free(buffer);
473 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
virtual MemoryLevel getType() const =0

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

References buffer_access_mutex_, bufferMgrs_, CHECK_LT, and levelSizes_.

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

428  {
429  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
430  const auto level = static_cast<size_t>(memoryLevel);
431  CHECK_LT(level, levelSizes_.size()); // make sure we have a legit buffermgr
432  CHECK_LT(deviceId, levelSizes_[level]); // make sure we have a legit buffermgr
433  return bufferMgrs_[level][deviceId]->getBuffer(key, numBytes);
434 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
std::vector< int > levelSizes_
Definition: DataMgr.h:210
#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::getChunkMetadataVecForKeyPrefix ( ChunkMetadataVector chunkMetadataVec,
const ChunkKey keyPrefix 
)

Definition at line 411 of file DataMgr.cpp.

References bufferMgrs_.

412  {
413  bufferMgrs_[0][0]->getChunkMetadataVecForKeyPrefix(chunkMetadataVec, keyPrefix);
414 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
CudaMgr_Namespace::CudaMgr* Data_Namespace::DataMgr::getCudaMgr ( ) const
inline

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

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

+ Here is the caller graph for this function:

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

Definition at line 528 of file DataMgr.cpp.

References bufferMgrs_, and CHECK.

Referenced by convertDB(), createTopLevelMetadata(), TableArchiver::dumpTable(), anonymous_namespace{DdlCommandExecutor.cpp}::get_agg_storage_stats(), Catalog_Namespace::Catalog::getTableDataDirectories(), getTableEpoch(), TableArchiver::restoreTable(), and setTableEpoch().

528  {
529  File_Namespace::GlobalFileMgr* global_file_mgr{nullptr};
530  global_file_mgr =
531  dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
532  CHECK(global_file_mgr);
533  return global_file_mgr;
534 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:528
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

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

Definition at line 304 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.

304  {
305  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
306 
307  std::vector<MemoryInfo> mem_info;
308  if (memLevel == MemoryLevel::CPU_LEVEL) {
309  Buffer_Namespace::CpuBufferMgr* cpu_buffer =
310  dynamic_cast<Buffer_Namespace::CpuBufferMgr*>(
312  CHECK(cpu_buffer);
313  MemoryInfo mi;
314 
315  mi.pageSize = cpu_buffer->getPageSize();
316  mi.maxNumPages = cpu_buffer->getMaxSize() / mi.pageSize;
317  mi.isAllocationCapped = cpu_buffer->isAllocationCapped();
318  mi.numPageAllocated = cpu_buffer->getAllocated() / mi.pageSize;
319 
320  const auto& slab_segments = cpu_buffer->getSlabSegments();
321  for (size_t slab_num = 0; slab_num < slab_segments.size(); ++slab_num) {
322  for (auto segment : slab_segments[slab_num]) {
323  MemoryData md;
324  md.slabNum = slab_num;
325  md.startPage = segment.start_page;
326  md.numPages = segment.num_pages;
327  md.touch = segment.last_touched;
328  md.memStatus = segment.mem_status;
329  md.chunk_key.insert(
330  md.chunk_key.end(), segment.chunk_key.begin(), segment.chunk_key.end());
331  mi.nodeMemoryData.push_back(md);
332  }
333  }
334  mem_info.push_back(mi);
335  } else if (hasGpus_) {
336  int numGpus = cudaMgr_->getDeviceCount();
337  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
339  dynamic_cast<Buffer_Namespace::GpuCudaBufferMgr*>(
341  CHECK(gpu_buffer);
342  MemoryInfo mi;
343 
344  mi.pageSize = gpu_buffer->getPageSize();
345  mi.maxNumPages = gpu_buffer->getMaxSize() / mi.pageSize;
346  mi.isAllocationCapped = gpu_buffer->isAllocationCapped();
347  mi.numPageAllocated = gpu_buffer->getAllocated() / mi.pageSize;
348 
349  const auto& slab_segments = gpu_buffer->getSlabSegments();
350  for (size_t slab_num = 0; slab_num < slab_segments.size(); ++slab_num) {
351  for (auto segment : slab_segments[slab_num]) {
352  MemoryData md;
353  md.slabNum = slab_num;
354  md.startPage = segment.start_page;
355  md.numPages = segment.num_pages;
356  md.touch = segment.last_touched;
357  md.chunk_key.insert(
358  md.chunk_key.end(), segment.chunk_key.begin(), segment.chunk_key.end());
359  md.memStatus = segment.mem_status;
360  mi.nodeMemoryData.push_back(md);
361  }
362  }
363  mem_info.push_back(mi);
364  }
365  }
366  return mem_info;
367 }
size_t getAllocated() override
Definition: BufferMgr.cpp:494
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< MemoryData > nodeMemoryData
Definition: DataMgr.h:65
Buffer_Namespace::MemStatus memStatus
Definition: DataMgr.h:57
size_t getMaxSize() override
Definition: BufferMgr.cpp:489
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
bool isAllocationCapped() override
Definition: BufferMgr.cpp:499
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:239
const std::vector< BufferList > & getSlabSegments()
Definition: BufferMgr.cpp:874
#define CHECK(condition)
Definition: Logger.h:197
std::vector< int32_t > chunk_key
Definition: DataMgr.h:56

+ Here is the call graph for this function:

PersistentStorageMgr * Data_Namespace::DataMgr::getPersistentStorageMgr ( ) const

Definition at line 551 of file DataMgr.cpp.

References bufferMgrs_.

551  {
552  return dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0]);
553 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
DataMgr::SystemMemoryUsage Data_Namespace::DataMgr::getSystemMemoryUsage ( ) const

Definition at line 85 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.

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

References bufferMgrs_, CHECK, and getGlobalFileMgr().

521  {
522  File_Namespace::GlobalFileMgr* gfm{nullptr};
523  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
524  CHECK(gfm);
525  return gfm->getTableEpoch(db_id, tb_id);
526 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:528
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

size_t Data_Namespace::DataMgr::getTotalSystemMemory ( )
static

Definition at line 142 of file DataMgr.cpp.

Referenced by populateMgrs().

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

+ Here is the caller graph for this function:

bool Data_Namespace::DataMgr::gpusPresent ( )
inline

Definition at line 201 of file DataMgr.h.

References hasGpus_.

Referenced by get_available_gpus().

201 { 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 404 of file DataMgr.cpp.

References buffer_access_mutex_, and bufferMgrs_.

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

406  {
407  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
408  return bufferMgrs_[memLevel][deviceId]->isBufferOnDevice(key);
409 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238

+ Here is the caller graph for this function:

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

Definition at line 180 of file DataMgr.cpp.

References bufferMgrs_, SystemParameters::cpu_buffer_mem_bytes, PersistentStorageMgr::createPersistentStorageMgr(), cudaMgr_, dataDir_, getTotalSystemMemory(), 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 resetPersistentStorage().

182  {
183  // no need for locking, as this is only called in the constructor
184  bufferMgrs_.resize(2);
186  dataDir_, userSpecifiedNumReaderThreads, cache_config));
187 
188  levelSizes_.push_back(1);
189  size_t page_size{512};
190  size_t cpuBufferSize = system_parameters.cpu_buffer_mem_bytes;
191  if (cpuBufferSize == 0) { // if size is not specified
192  const auto total_system_memory = getTotalSystemMemory();
193  VLOG(1) << "Detected " << (float)total_system_memory / (1024 * 1024)
194  << "M of total system memory.";
195  cpuBufferSize = total_system_memory *
196  0.8; // should get free memory instead of this ugly heuristic
197  }
198  size_t minCpuSlabSize = std::min(system_parameters.min_cpu_slab_size, cpuBufferSize);
199  minCpuSlabSize = (minCpuSlabSize / page_size) * page_size;
200  size_t maxCpuSlabSize = std::min(system_parameters.max_cpu_slab_size, cpuBufferSize);
201  maxCpuSlabSize = (maxCpuSlabSize / page_size) * page_size;
202  LOG(INFO) << "Min CPU Slab Size is " << (float)minCpuSlabSize / (1024 * 1024) << "MB";
203  LOG(INFO) << "Max CPU Slab Size is " << (float)maxCpuSlabSize / (1024 * 1024) << "MB";
204  LOG(INFO) << "Max memory pool size for CPU is " << (float)cpuBufferSize / (1024 * 1024)
205  << "MB";
206  if (hasGpus_ || cudaMgr_) {
207  LOG(INFO) << "Reserved GPU memory is " << (float)reservedGpuMem_ / (1024 * 1024)
208  << "MB includes render buffer allocation";
209  bufferMgrs_.resize(3);
210  bufferMgrs_[1].push_back(new Buffer_Namespace::CpuBufferMgr(0,
211  cpuBufferSize,
212  cudaMgr_.get(),
213  minCpuSlabSize,
214  maxCpuSlabSize,
215  page_size,
216  bufferMgrs_[0][0]));
217  levelSizes_.push_back(1);
218  int numGpus = cudaMgr_->getDeviceCount();
219  for (int gpuNum = 0; gpuNum < numGpus; ++gpuNum) {
220  size_t gpuMaxMemSize =
221  system_parameters.gpu_buffer_mem_bytes != 0
222  ? system_parameters.gpu_buffer_mem_bytes
223  : (cudaMgr_->getDeviceProperties(gpuNum)->globalMem) - (reservedGpuMem_);
224  size_t minGpuSlabSize =
225  std::min(system_parameters.min_gpu_slab_size, gpuMaxMemSize);
226  minGpuSlabSize = (minGpuSlabSize / page_size) * page_size;
227  size_t maxGpuSlabSize =
228  std::min(system_parameters.max_gpu_slab_size, gpuMaxMemSize);
229  maxGpuSlabSize = (maxGpuSlabSize / page_size) * page_size;
230  LOG(INFO) << "Min GPU Slab size for GPU " << gpuNum << " is "
231  << (float)minGpuSlabSize / (1024 * 1024) << "MB";
232  LOG(INFO) << "Max GPU Slab size for GPU " << gpuNum << " is "
233  << (float)maxGpuSlabSize / (1024 * 1024) << "MB";
234  LOG(INFO) << "Max memory pool size for GPU " << gpuNum << " is "
235  << (float)gpuMaxMemSize / (1024 * 1024) << "MB";
236  bufferMgrs_[2].push_back(new Buffer_Namespace::GpuCudaBufferMgr(gpuNum,
237  gpuMaxMemSize,
238  cudaMgr_.get(),
239  minGpuSlabSize,
240  maxGpuSlabSize,
241  page_size,
242  bufferMgrs_[1][0]));
243  }
244  levelSizes_.push_back(numGpus);
245  } else {
246  bufferMgrs_[1].push_back(new Buffer_Namespace::CpuBufferMgr(0,
247  cpuBufferSize,
248  cudaMgr_.get(),
249  minCpuSlabSize,
250  maxCpuSlabSize,
251  page_size,
252  bufferMgrs_[0][0]));
253  levelSizes_.push_back(1);
254  }
255 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
std::vector< int > levelSizes_
Definition: DataMgr.h:210
#define LOG(tag)
Definition: Logger.h:188
static size_t getTotalSystemMemory()
Definition: DataMgr.cpp:142
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cudaMgr_
Definition: DataMgr.h:239
static PersistentStorageMgr * createPersistentStorageMgr(const std::string &data_dir, const size_t num_reader_threads, const DiskCacheConfig &disk_cache_config)
#define VLOG(n)
Definition: Logger.h:291
std::string dataDir_
Definition: DataMgr.h:240

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

References buffer_access_mutex_, and bufferMgrs_.

509  {
510  std::lock_guard<std::mutex> buffer_lock(buffer_access_mutex_);
511  bufferMgrs_[0][0]->removeTableRelatedDS(db_id, tb_id);
512 }
std::mutex buffer_access_mutex_
Definition: DataMgr.h:243
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
void Data_Namespace::DataMgr::resetPersistentStorage ( const DiskCacheConfig cache_config,
const size_t  num_reader_threads,
const SystemParameters sys_params 
)

Definition at line 166 of file DataMgr.cpp.

References bufferMgrs_, createTopLevelMetadata(), and populateMgrs().

168  {
169  int numLevels = bufferMgrs_.size();
170  for (int level = numLevels - 1; level >= 0; --level) {
171  for (size_t device = 0; device < bufferMgrs_[level].size(); device++) {
172  delete bufferMgrs_[level][device];
173  }
174  }
175  bufferMgrs_.clear();
176  populateMgrs(sys_params, num_reader_threads, cache_config);
178 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
void populateMgrs(const SystemParameters &system_parameters, const size_t userSpecifiedNumReaderThreads, const DiskCacheConfig &cache_config)
Definition: DataMgr.cpp:180
void createTopLevelMetadata() const
Definition: DataMgr.cpp:288

+ Here is the call graph for this function:

void Data_Namespace::DataMgr::setTableEpoch ( const int  db_id,
const int  tb_id,
const int  start_epoch 
)

Definition at line 514 of file DataMgr.cpp.

References bufferMgrs_, CHECK, and getGlobalFileMgr().

514  {
515  File_Namespace::GlobalFileMgr* gfm{nullptr};
516  gfm = dynamic_cast<PersistentStorageMgr*>(bufferMgrs_[0][0])->getGlobalFileMgr();
517  CHECK(gfm);
518  gfm->setTableEpoch(db_id, tb_id, start_epoch);
519 }
std::vector< std::vector< AbstractBufferMgr * > > bufferMgrs_
Definition: DataMgr.h:238
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:528
#define CHECK(condition)
Definition: Logger.h:197

+ 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.

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 239 of file DataMgr.h.

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

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

Definition at line 240 of file DataMgr.h.

Referenced by populateMgrs().

bool Data_Namespace::DataMgr::hasGpus_
private

Definition at line 241 of file DataMgr.h.

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

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

Definition at line 210 of file DataMgr.h.

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

size_t Data_Namespace::DataMgr::reservedGpuMem_
private

Definition at line 242 of file DataMgr.h.

Referenced by populateMgrs().


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