Skip to content

Commit

Permalink
More fixes to anti-cache NVM backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebrabant committed Oct 6, 2013
1 parent b9b2a68 commit 8cf939d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
33 changes: 24 additions & 9 deletions src/ee/anticache/AntiCacheDB.cpp
Expand Up @@ -100,6 +100,8 @@ void AntiCacheDB::initializeNVM() {


strcpy(nvm_file_name, m_dbDir.c_str()); strcpy(nvm_file_name, m_dbDir.c_str());
strcat(nvm_file_name, "/anticache.nvm"); strcat(nvm_file_name, "/anticache.nvm");
nvm_file = fopen(nvm_file_name, "w");
fclose(nvm_file);
nvm_file = fopen(nvm_file_name, "rw+"); nvm_file = fopen(nvm_file_name, "rw+");


if(nvm_file == NULL) if(nvm_file == NULL)
Expand All @@ -125,13 +127,20 @@ void AntiCacheDB::initializeNVM() {
} }


m_NVMBlocks = (char*)mmap(NULL, NVM_FILE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, nvm_fd, 0); m_NVMBlocks = (char*)mmap(NULL, NVM_FILE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, nvm_fd, 0);

//m_NVMBlocks = new char[NVM_FILE_SIZE];

if(m_NVMBlocks == MAP_FAILED) if(m_NVMBlocks == MAP_FAILED)
{ {
VOLT_ERROR("Anti-Cache initialization error."); VOLT_ERROR("Anti-Cache initialization error.");
VOLT_ERROR("Failed to mmap PMFS file %s: %s", nvm_file_name, strerror(errno)); VOLT_ERROR("Failed to mmap PMFS file %s: %s", nvm_file_name, strerror(errno));
throwFatalException("Failed to initialize anti-cache PMFS file in directory %s.", m_dbDir.c_str()); throwFatalException("Failed to initialize anti-cache PMFS file in directory %s.", m_dbDir.c_str());
} }

// write out NULL characters to ensure entire file has been fetchted from memory
for(int i = 0; i < NVM_FILE_SIZE; i++)
{
m_NVMBlocks[i] = '\0';
}
} }


void AntiCacheDB::shutdownBerkeleyDB() { void AntiCacheDB::shutdownBerkeleyDB() {
Expand Down Expand Up @@ -162,7 +171,6 @@ void AntiCacheDB::shutdownNVM()
{ {
} }



AntiCacheDB::~AntiCacheDB() { AntiCacheDB::~AntiCacheDB() {


#ifdef ANTICACHE_NVM #ifdef ANTICACHE_NVM
Expand Down Expand Up @@ -232,7 +240,7 @@ void AntiCacheDB::writeBlockNVM(const std::string tableName,
//m_NVMBlocks[m_totalBlocks] = new char[size]; //m_NVMBlocks[m_totalBlocks] = new char[size];
//memcpy(m_NVMBlocks[m_totalBlocks], data, size); //memcpy(m_NVMBlocks[m_totalBlocks], data, size);


VOLT_DEBUG("Writing NVM Block: ID = %d, index = %d, size = %ld", blockId, index, size); VOLT_INFO("Writing NVM Block: ID = %d, index = %d, size = %ld", blockId, index, size);
m_blockMap.insert(std::pair<int16_t, std::pair<int, long> >(blockId, std::pair<int, long>(index, size))); m_blockMap.insert(std::pair<int16_t, std::pair<int, long> >(blockId, std::pair<int, long>(index, size)));
} }


Expand All @@ -249,7 +257,7 @@ AntiCacheBlock AntiCacheDB::readBlockNVM(std::string tableName, int16_t blockId)
} }


int blockIndex = itr->second.first; int blockIndex = itr->second.first;
VOLT_DEBUG("Reading NVM block: ID = %d, index = %d, size = %ld.", blockId, blockIndex, itr->second.second); VOLT_INFO("Reading NVM block: ID = %d, index = %d, size = %ld.", blockId, blockIndex, itr->second.second);


char* block_ptr = getNVMBlock(blockIndex); char* block_ptr = getNVMBlock(blockIndex);
AntiCacheBlock block(blockId, empty, block_ptr, itr->second.second); AntiCacheBlock block(blockId, empty, block_ptr, itr->second.second);
Expand Down Expand Up @@ -280,21 +288,28 @@ AntiCacheBlock AntiCacheDB::readBlock(std::string tableName, int16_t blockId) {
} }


void AntiCacheDB::flushBlocks() { void AntiCacheDB::flushBlocks() {
m_db->sync(0);
#ifdef ANTICACHE_NVM

#else
m_db->sync(0);
#endif
} }


char* AntiCacheDB::getNVMBlock(int index) { char* AntiCacheDB::getNVMBlock(int index) {


char* nvm_block = new char[NVM_BLOCK_SIZE]; //char* nvm_block = new char[NVM_BLOCK_SIZE];
memcpy(nvm_block, m_NVMBlocks+(index*NVM_BLOCK_SIZE), NVM_BLOCK_SIZE); //memcpy(nvm_block, m_NVMBlocks+(index*NVM_BLOCK_SIZE), NVM_BLOCK_SIZE);


return nvm_block; //return nvm_block;
return (m_NVMBlocks+(index*NVM_BLOCK_SIZE));
} }


int AntiCacheDB::getFreeNVMBlockIndex() int AntiCacheDB::getFreeNVMBlockIndex()
{ {
int free_index = 0; int free_index = 0;
if(m_NVMBlockFreeList.size() > 0) //if(m_NVMBlockFreeList.size() > 0)
if(false)
{ {
free_index = m_NVMBlockFreeList.back(); free_index = m_NVMBlockFreeList.back();
} }
Expand Down
2 changes: 1 addition & 1 deletion src/ee/anticache/AntiCacheDB.h
Expand Up @@ -117,7 +117,7 @@ class AntiCacheDB {
* NVM constants * NVM constants
*/ */
static const off_t NVM_FILE_SIZE = 1073741824; static const off_t NVM_FILE_SIZE = 1073741824;
static const int NVM_BLOCK_SIZE = 4096; static const int NVM_BLOCK_SIZE = 524288 * 2;


ExecutorContext *m_executorContext; ExecutorContext *m_executorContext;
string m_dbDir; string m_dbDir;
Expand Down
2 changes: 1 addition & 1 deletion src/ee/storage/persistenttable.cpp
Expand Up @@ -465,7 +465,7 @@ bool PersistentTable::mergeUnevictedTuples()


m_unevictedBlocks.clear(); m_unevictedBlocks.clear();
m_mergeTupleOffset.clear(); m_mergeTupleOffset.clear();
m_unevictedBlockIDs.clear(); // if we uncomment this the benchmark won't end //m_unevictedBlockIDs.clear(); // if we uncomment this the benchmark won't end


#ifdef VOLT_INFO_ENABLED #ifdef VOLT_INFO_ENABLED
VOLT_INFO("Active Tuple Count: %d -- %d", (int)active_tuple_count, (int)activeTupleCount()); VOLT_INFO("Active Tuple Count: %d -- %d", (int)active_tuple_count, (int)activeTupleCount());
Expand Down
4 changes: 2 additions & 2 deletions src/ee/storage/persistenttable.h
Expand Up @@ -340,8 +340,8 @@ class PersistentTable : public Table {
std::vector<char*> m_unevictedBlocks; std::vector<char*> m_unevictedBlocks;
std::vector<int32_t> m_mergeTupleOffset; std::vector<int32_t> m_mergeTupleOffset;


std::map<int, int> m_unevictedTuplesPerBlocks; std::map<int, int> m_unevictedTuplesPerBlocks;

char* m_unevictedTuples; char* m_unevictedTuples;
int m_numUnevictedTuples; int m_numUnevictedTuples;


Expand Down

0 comments on commit 8cf939d

Please sign in to comment.