Skip to content

Poc #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions cachelib/allocator/CacheAllocator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,30 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
return handle;
}

template <typename CacheTrait>
typename CacheAllocator<CacheTrait>::TierId
CacheAllocator<CacheTrait>::getTargetTierForItem(PoolId pid,
typename Item::Key key,
uint32_t size,
uint32_t creationTime,
uint32_t expiryTime) {
// TODO, also look at size and other things (depending on policy?)
// if (memUsage > highAllocationWatermark) return 1;
// else if (memUsage < highAllocationWatermark) return 0;
// else return random() % 2;

return 0;
}

template <typename CacheTrait>
typename CacheAllocator<CacheTrait>::WriteHandle
CacheAllocator<CacheTrait>::allocateInternal(PoolId pid,
typename Item::Key key,
uint32_t size,
uint32_t creationTime,
uint32_t expiryTime) {
auto tid = 0; /* TODO: consult admission policy */
for(TierId tid = 0; tid < numTiers_; ++tid) {
auto tid = getTargetTierForItem(pid, key, size, creationTime, expiryTime);
for(; tid < numTiers_; ++tid) {
auto handle = allocateInternalTier(tid, pid, key, size, creationTime, expiryTime);
if (handle) return handle;
}
Expand Down Expand Up @@ -1849,7 +1864,13 @@ bool CacheAllocator<CacheTrait>::recordAccessInMMContainer(Item& item,
}

auto& mmContainer = getMMContainer(tid, allocInfo.poolId, allocInfo.classId);
return mmContainer.recordAccess(item, mode);

// TODO: it would be better to have this hidden inside recordAccess perhaps
// Ideally, we can have different MMContainers for different tiers
if (tid == 0 || folly::rand32() % 128 < config_.markUsefulChance)
return mmContainer.recordAccess(item, mode);

return true;
}

template <typename CacheTrait>
Expand Down
2 changes: 2 additions & 0 deletions cachelib/allocator/CacheAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,8 @@ class CacheAllocator : public CacheBase {
// indicates if the shutdown of cache is in progress or not
std::atomic<bool> shutDownInProgress_{false};

std::ACStats

// END private members

// Make this friend to give access to acquire and release
Expand Down
15 changes: 15 additions & 0 deletions cachelib/allocator/CacheAllocatorConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,21 @@ class CacheAllocatorConfig {
// skip promote children items in chained when parent fail to promote
bool skipPromoteChildrenWhenParentFailed{false};

std::string admissionPolicy{"random"}; // where to put allocated item, used when free mem between lowAllocationWatermark and highAllocationWatermark
std::string evictionPolicy{""}; // where to put evicted item (where in MMContainer?)
std::string promotionPolicy{""}; // which item to promote
uint64_t markUsefulChance{128}; // how to mark items as useful on lower tier (0-128)
// TODO: this should be part of MMContainer configuration
// TODO: we should allow having different memory containers
// for different tiers (for PMEM, we could use MM2Q)
double lowAllocationWatermark{100.0}; // if occupied space below, only allocate in upper tier
// if occupied space between, consult admission policy
// right now, random is supported
double highAllocationWatermark{100.0}; // if occupied space above, only allocate in lower tier
// we can still move items from PMEM to DRAM here
double evictionWatermark{0.0}; // starts eviction if below
uint64_t allowedDuplicatedItems{0}; // how many items can be in multiple tiers

friend CacheT;

private:
Expand Down
9 changes: 9 additions & 0 deletions cachelib/cachebench/cache/Cache-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ Cache<Allocator>::Cache(const CacheConfig& config,

allocatorConfig_.cacheName = "cachebench";

allocatorConfig_.admissionPolicy = config_.admissionPolicy;
allocatorConfig_.evictionPolicy = config_.evictionPolicy;
allocatorConfig_.promotionPolicy = config_.promotionPolicy;
allocatorConfig_.markUsefulChance = config_.markUsefulChance;
allocatorConfig_.lowAllocationWatermark = config_.lowAllocationWatermark;
allocatorConfig_.highAllocationWatermark = config_.highAllocationWatermark;
allocatorConfig_.evictionWatermark = config_.evictionWatermark;
allocatorConfig_.allowedDuplicatedItems = config_.allowedDuplicatedItems;

if (!allocatorConfig_.cacheDir.empty()) {
cache_ =
std::make_unique<Allocator>(Allocator::SharedMemNew, allocatorConfig_);
Expand Down
9 changes: 9 additions & 0 deletions cachelib/cachebench/util/CacheConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
memoryTierConfigs.push_back(MemoryTierConfig(it).getMemoryTierCacheConfig());
}
}

JSONSetVal(configJson, admissionPolicy);
JSONSetVal(configJson, evictionPolicy);
JSONSetVal(configJson, promotionPolicy);
JSONSetVal(configJson, markUsefulChance);
JSONSetVal(configJson, lowAllocationWatermark);
JSONSetVal(configJson, highAllocationWatermark);
JSONSetVal(configJson, evictionWatermark);
JSONSetVal(configJson, allowedDuplicatedItems);

// if you added new fields to the configuration, update the JSONSetVal
// to make them available for the json configs and increment the size
Expand Down
15 changes: 15 additions & 0 deletions cachelib/cachebench/util/CacheConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ struct CacheConfig : public JSONConfig {
// this verifies whether the feature affects throughputs.
bool enableItemDestructor{false};

std::string admissionPolicy; // where to put allocated item
std::string evictionPolicy; // where to put evicted item (where in MMContainer?)
std::string promotionPolicy; // which item to promote
uint64_t markUsefulChance; // how to mark items as useful on lower tier
// TODO: this should be part of MMContainer configuration
// TODO: we should allow having different memory containers
// for different tiers (for PMEM, we could use MM2Q)
double lowAllocationWatermark; // if occupied space below, only allocate in upper tier
// if occupied space between, consult admission policy
// right now, random is supported
double highAllocationWatermark; // if occupied space above, only allocate in lower tier
// we can still move items from PMEM to DRAM here
double evictionWatermark; // starts eviction if below
uint64_t allowedDuplicatedItems; // how many items can be in multiple tiers

explicit CacheConfig(const folly::dynamic& configJson);

CacheConfig() {}
Expand Down