Skip to content

Commit 07ca327

Browse files
committed
updates per comments (still outstanding on the todos)
1 parent 829ad42 commit 07ca327

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

Diff for: cachelib/allocator/Cache.h

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class CacheBase {
9090
virtual const std::string getCacheName() const = 0;
9191

9292
// Get the reference to a memory pool, for stats purposes
93+
// uses the top most memory tier by default
9394
//
9495
// @param poolId The pool id to query
9596
virtual const MemoryPool& getPool(PoolId poolId) const = 0;

Diff for: cachelib/allocator/CacheAllocator-inl.h

+12-19
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
372372
typename Item::Key key,
373373
uint32_t size,
374374
uint32_t creationTime,
375-
uint32_t expiryTime,
376-
bool fromEvictorThread) {
375+
uint32_t expiryTime) {
377376
util::LatencyTracker tracker{stats().allocateLatency_};
378377

379378
SCOPE_FAIL { stats_.invalidAllocs.inc(); };
@@ -403,7 +402,7 @@ CacheAllocator<CacheTrait>::allocateInternalTier(TierId tid,
403402
}
404403

405404
// TODO: Today disableEviction means do not evict from memory (DRAM).
406-
// Should we support eviction between memory tiers (e.g. from DRAM to PMEM)?
405+
// Should we support eviction between memory tiers (e.g. from DRAM to next tier)?
407406
if (memory == nullptr && !config_.disableEviction) {
408407
memory = findEviction(tid, pid, cid);
409408
}
@@ -475,7 +474,7 @@ CacheAllocator<CacheTrait>::getTargetTierForItem(PoolId pid,
475474
if (freePercentage <= config_.minAcAllocationWatermark)
476475
return defaultTargetTier + 1;
477476

478-
// TODO: we can even think about creating different allocation classes for PMEM
477+
// TODO: we can even think about creating different allocation classes for different tiers
479478
// and we could look at possible fragmentation when deciding where to put the item
480479
if (config_.sizeThresholdPolicy)
481480
return requiredSize < config_.sizeThresholdPolicy ? defaultTargetTier : defaultTargetTier + 1;
@@ -506,10 +505,9 @@ CacheAllocator<CacheTrait>::allocateInternal(PoolId pid,
506505
typename Item::Key key,
507506
uint32_t size,
508507
uint32_t creationTime,
509-
uint32_t expiryTime,
510-
bool fromEvictorThread) {
508+
uint32_t expiryTime) {
511509
auto tid = getTargetTierForItem(pid, key, size, creationTime, expiryTime);
512-
return allocateInternalTier(tid, pid, key, size, creationTime, expiryTime, fromEvictorThread);
510+
return allocateInternalTier(tid, pid, key, size, creationTime, expiryTime);
513511
}
514512

515513
template <typename CacheTrait>
@@ -1680,17 +1678,13 @@ template <typename CacheTrait>
16801678
bool CacheAllocator<CacheTrait>::shouldEvictToNextMemoryTier(
16811679
TierId sourceTierId, TierId targetTierId, PoolId pid, Item& item)
16821680
{
1683-
if (config_.disableEvictionToMemory)
1684-
return false;
1685-
1686-
// TODO: implement more advanced admission policies for memory tiers
1687-
return true;
1681+
return !(config_.disableEvictionToMemory);
16881682
}
16891683

16901684
template <typename CacheTrait>
16911685
typename CacheAllocator<CacheTrait>::WriteHandle
16921686
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
1693-
TierId tid, PoolId pid, Item& item, bool fromEvictorThread) {
1687+
TierId tid, PoolId pid, Item& item) {
16941688
if(item.isExpired()) return acquire(&item);
16951689

16961690
TierId nextTier = tid;
@@ -1703,8 +1697,7 @@ CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
17031697
item.getKey(),
17041698
item.getSize(),
17051699
item.getCreationTime(),
1706-
item.getExpiryTime(),
1707-
fromEvictorThread);
1700+
item.getExpiryTime());
17081701

17091702
if (newItemHdl) {
17101703
XDCHECK_EQ(newItemHdl->getSize(), item.getSize());
@@ -1717,10 +1710,10 @@ CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(
17171710

17181711
template <typename CacheTrait>
17191712
typename CacheAllocator<CacheTrait>::WriteHandle
1720-
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(Item& item, bool fromEvictorThread) {
1713+
CacheAllocator<CacheTrait>::tryEvictToNextMemoryTier(Item& item) {
17211714
auto tid = getTierId(item);
17221715
auto pid = allocator_[tid]->getAllocInfo(item.getMemory()).poolId;
1723-
return tryEvictToNextMemoryTier(tid, pid, item, fromEvictorThread);
1716+
return tryEvictToNextMemoryTier(tid, pid, item);
17241717
}
17251718

17261719
template <typename CacheTrait>
@@ -3047,14 +3040,14 @@ void CacheAllocator<CacheTrait>::evictForSlabRelease(
30473040
template <typename CacheTrait>
30483041
typename CacheAllocator<CacheTrait>::ItemHandle
30493042
CacheAllocator<CacheTrait>::evictNormalItem(Item& item,
3050-
bool skipIfTokenInvalid, bool fromEvictorThread) {
3043+
bool skipIfTokenInvalid) {
30513044
XDCHECK(item.isMoving());
30523045

30533046
if (item.isOnlyMoving()) {
30543047
return ItemHandle{};
30553048
}
30563049

3057-
auto evictHandle = tryEvictToNextMemoryTier(item, fromEvictorThread);
3050+
auto evictHandle = tryEvictToNextMemoryTier(item);
30583051
if(evictHandle) return evictHandle;
30593052

30603053
auto predicate = [](const Item& it) { return it.getRefCount() == 0; };

Diff for: cachelib/allocator/CacheAllocator.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <folly/Format.h>
3737
#include <folly/Range.h>
3838
#pragma GCC diagnostic pop
39+
3940
#include "cachelib/allocator/CCacheManager.h"
4041
#include "cachelib/allocator/Cache.h"
4142
#include "cachelib/allocator/CacheAllocatorConfig.h"
@@ -1334,8 +1335,7 @@ class CacheAllocator : public CacheBase {
13341335
Key key,
13351336
uint32_t size,
13361337
uint32_t creationTime,
1337-
uint32_t expiryTime,
1338-
bool fromEvictorThread);
1338+
uint32_t expiryTime);
13391339

13401340
// create a new cache allocation on specific memory tier.
13411341
// For description see allocateInternal.
@@ -1346,8 +1346,7 @@ class CacheAllocator : public CacheBase {
13461346
Key key,
13471347
uint32_t size,
13481348
uint32_t creationTime,
1349-
uint32_t expiryTime,
1350-
bool fromEvictorThread);
1349+
uint32_t expiryTime);
13511350

13521351
// Allocate a chained item
13531352
//
@@ -1588,15 +1587,15 @@ class CacheAllocator : public CacheBase {
15881587
//
15891588
// @return valid handle to the item. This will be the last
15901589
// handle to the item. On failure an empty handle.
1591-
WriteHandle tryEvictToNextMemoryTier(TierId tid, PoolId pid, Item& item, bool fromEvictorThread);
1590+
WriteHandle tryEvictToNextMemoryTier(TierId tid, PoolId pid, Item& item);
15921591

15931592
// Try to move the item down to the next memory tier
15941593
//
15951594
// @param item the item to evict
15961595
//
15971596
// @return valid handle to the item. This will be the last
15981597
// handle to the item. On failure an empty handle.
1599-
WriteHandle tryEvictToNextMemoryTier(Item& item, bool fromEvictorThread);
1598+
WriteHandle tryEvictToNextMemoryTier(Item& item);
16001599

16011600
bool shouldEvictToNextMemoryTier(TierId sourceTierId,
16021601
TierId targetTierId, PoolId pid, Item& item);
@@ -1728,7 +1727,7 @@ class CacheAllocator : public CacheBase {
17281727
//
17291728
// @return last handle for corresponding to item on success. empty handle on
17301729
// failure. caller can retry if needed.
1731-
ItemHandle evictNormalItem(Item& item, bool skipIfTokenInvalid = false, bool fromEvictorThread = false);
1730+
ItemHandle evictNormalItem(Item& item, bool skipIfTokenInvalid = false);
17321731

17331732
// Helper function to evict a child item for slab release
17341733
// As a side effect, the parent item is also evicted

Diff for: cachelib/allocator/CacheAllocatorConfig.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,12 @@ class CacheAllocatorConfig {
587587

588588
bool disableEvictionToMemory{false};
589589

590-
double minAcAllocationWatermark{0.0};
591-
double maxAcAllocationWatermark{0.0};
592-
double acTopTierEvictionWatermark{0.0}; // TODO: make it per TIER?
593-
uint64_t sizeThresholdPolicy{0};
594-
double defaultTierChancePercentage{50.0};
595-
uint64_t forceAllocationTier{UINT64_MAX};
590+
double minAcAllocationWatermark{0.0}; //if % free in AC is <= then try to allocate in next tier
591+
double maxAcAllocationWatermark{0.0}; //if % free in AC is >= then allocate in default target tier
592+
double acTopTierEvictionWatermark{0.0}; // evict from 1st tier if % free is < watermark
593+
uint64_t sizeThresholdPolicy{0}; // only allow items < threshold in top tier
594+
double defaultTierChancePercentage{50.0}; //randomly allocate items among top and bottom tiers
595+
uint64_t forceAllocationTier{UINT64_MAX}; //force allocations to happen in this tier
596596

597597
friend CacheT;
598598

0 commit comments

Comments
 (0)