tr_cache * tr_cacheNew (int64_t max_bytes) { tr_cache * cache = tr_new0 (tr_cache, 1); cache->blocks = TR_PTR_ARRAY_INIT; cache->max_bytes = max_bytes; cache->max_blocks = getMaxBlocks (max_bytes); return cache; }
int tr_cacheSetLimit (tr_cache * cache, int64_t max_bytes) { char buf[128]; cache->max_bytes = max_bytes; cache->max_blocks = getMaxBlocks (max_bytes); tr_formatter_mem_B (buf, cache->max_bytes, sizeof (buf)); tr_logAddNamedDbg (MY_NAME, "Maximum cache size set to %s (%d blocks)", buf, cache->max_blocks); return cacheTrim (cache); }
uint32_t NVMAntiCacheDB::getFreeNVMBlockIndex() { uint32_t free_index = 0; if(m_NVMBlockFreeList.size() > 0) { free_index = m_NVMBlockFreeList.back(); VOLT_DEBUG("popping %u from list of size: %d", free_index, (int)m_NVMBlockFreeList.size()); m_NVMBlockFreeList.pop_back(); } else { if (m_nextFreeBlock == getMaxBlocks()) { VOLT_WARN("Backing store full m_nextFreeBlock %d == max %d", m_nextFreeBlock, getMaxBlocks()); throw FullBackingStoreException(0, m_nextFreeBlock); } else { free_index = m_nextFreeBlock; VOLT_DEBUG("no reusable blocks (size: %d), using index %u", (int)m_NVMBlockFreeList.size(), free_index); ++m_nextFreeBlock; } } //int free_index = m_blockIndex++; return free_index; }