Skip to content

Commit a3f7f49

Browse files
pbhandar2meta-codesync[bot]
authored andcommitted
Add configuration to enable access time map
Summary: Add config to enable accessTimeMap in Navy config. Reviewed By: byahn0996 Differential Revision: D94727548 fbshipit-source-id: a0eaace3f3899c77adab5278279ff25e55a99583
1 parent 5e3917a commit a3f7f49

7 files changed

Lines changed: 60 additions & 2 deletions

File tree

cachelib/allocator/nvmcache/NavyConfig.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,8 @@ class NavyConfig {
899899
uint64_t getMaxParcelMemoryMB() const { return maxParcelMemoryMB_; }
900900
bool getUseEstimatedWriteSize() const { return useEstimatedWriteSize_; }
901901
size_t getNumShards() const { return numShards_; }
902+
bool getEnableAccessTimeMap() const { return enableAccessTimeMap_; }
903+
size_t getAccessTimeMapMaxSize() const { return accessTimeMapMaxSize_; }
902904

903905
// Setters:
904906
// Enable "dynamic_random" admission policy.
@@ -1042,6 +1044,12 @@ class NavyConfig {
10421044
useEstimatedWriteSize_ = useEstimatedWriteSize;
10431045
}
10441046
void setNumShards(size_t numShards) noexcept { numShards_ = numShards; }
1047+
void setEnableAccessTimeMap(bool enable) noexcept {
1048+
enableAccessTimeMap_ = enable;
1049+
}
1050+
void setAccessTimeMapMaxSize(size_t maxSize) noexcept {
1051+
accessTimeMapMaxSize_ = maxSize;
1052+
}
10451053

10461054
const std::vector<EnginesConfig>& enginesConfigs() const {
10471055
return enginesConfigs_;
@@ -1139,6 +1147,10 @@ class NavyConfig {
11391147
bool enableFDP_{false};
11401148
// Number of nvm lock shards
11411149
size_t numShards_{8192};
1150+
// Whether to enable the AccessTimeMap for tracking NVM item access times.
1151+
bool enableAccessTimeMap_{false};
1152+
// Maximum number of entries in the AccessTimeMap. 0 means unbounded.
1153+
size_t accessTimeMapMaxSize_{0};
11421154
};
11431155
} // namespace navy
11441156
} // namespace cachelib

cachelib/allocator/nvmcache/NvmCache.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <stdexcept>
2929
#include <vector>
3030

31+
#include "cachelib/allocator/nvmcache/AccessTimeMap.h"
3132
#include "cachelib/allocator/nvmcache/CacheApiWrapper.h"
3233
#include "cachelib/allocator/nvmcache/InFlightPuts.h"
3334
#include "cachelib/allocator/nvmcache/NavyConfig.h"
@@ -589,6 +590,18 @@ class NvmCache {
589590
// finished.
590591
std::vector<folly::F14FastSet<std::string>> itemRemoved_;
591592

593+
// Tracks the most recent DRAM last-access timestamp for items in NVM.
594+
// It is best offered and not updated on every DRAM access so could sometime
595+
// have stale value which represents the promotion timestamp.
596+
// Populated on DRAM eviction of NvmClean BlockCache items;
597+
// consumed during BlockCache region reclaim to write fresh timestamps.
598+
std::unique_ptr<AccessTimeMap> accessTimeMap_;
599+
600+
// BigHash small-item threshold from NavyConfig. Items with
601+
// key.size() + nvmBufferSize <= this threshold go to BigHash.
602+
// 0 means BigHash is not configured and all items go to BlockCache.
603+
const uint64_t smallItemMaxSize_;
604+
592605
std::unique_ptr<cachelib::navy::AbstractCache> navyCache_;
593606

594607
friend class tests::NvmCacheTest;
@@ -1058,7 +1071,15 @@ NvmCache<C>::NvmCache(C& c,
10581071
tombstones_(numShards_),
10591072
itemDestructor_(itemDestructor),
10601073
itemDestructorMutex_(numShards_),
1061-
itemRemoved_(numShards_) {
1074+
itemRemoved_(numShards_),
1075+
accessTimeMap_(
1076+
config_.navyConfig.getEnableAccessTimeMap()
1077+
? std::make_unique<AccessTimeMap>(
1078+
numShards_, config_.navyConfig.getAccessTimeMapMaxSize())
1079+
: nullptr),
1080+
smallItemMaxSize_(config_.navyConfig.isBigHashEnabled()
1081+
? config_.navyConfig.bigHash().getSmallItemMaxSize()
1082+
: 0) {
10621083
navyCache_ = createNavyCache(
10631084
config_.navyConfig,
10641085
checkExpired_,
@@ -1644,6 +1665,9 @@ template <typename C>
16441665
util::StatsMap NvmCache<C>::getStatsMap() const {
16451666
util::StatsMap statsMap;
16461667
navyCache_->getCounters(statsMap.createCountVisitor());
1668+
if (accessTimeMap_) {
1669+
accessTimeMap_->getCounters(statsMap.createCountVisitor());
1670+
}
16471671
statsMap.insertCount("items_tracked_for_destructor", getNvmItemRemovedSize());
16481672
return statsMap;
16491673
}

cachelib/allocator/nvmcache/tests/NvmCacheTests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,16 @@ TEST_F(NvmCacheTest, NavyStats) {
18931893
// item destructor
18941894
EXPECT_TRUE(cs("items_tracked_for_destructor"));
18951895

1896+
// AccessTimeMap stats
1897+
EXPECT_TRUE(cs("navy_atm_sets"));
1898+
EXPECT_TRUE(cs("navy_atm_gets"));
1899+
EXPECT_TRUE(cs("navy_atm_get_and_removes"));
1900+
EXPECT_TRUE(cs("navy_atm_removes"));
1901+
EXPECT_TRUE(cs("navy_atm_hits"));
1902+
EXPECT_TRUE(cs("navy_atm_misses"));
1903+
EXPECT_TRUE(cs("navy_atm_evictions"));
1904+
EXPECT_TRUE(cs("navy_atm_size"));
1905+
18961906
// there should be no additional stats
18971907
if (nvmStats.size()) {
18981908
for (auto kv : nvmStats) {

cachelib/allocator/tests/NvmTestUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ inline NavyConfig getNvmTestConfig(const std::string& cacheDir) {
3636
.setSizePctAndMaxItemSize(50, 100)
3737
.setBucketSize(1024)
3838
.setBucketBfSize(8);
39+
config.setEnableAccessTimeMap(true);
3940
return config;
4041
}
4142

cachelib/cachebench/cache/Cache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ Cache<Allocator>::Cache(const CacheConfig& config,
717717
}
718718
nvmConfig.navyConfig.setMaxConcurrentInserts(
719719
config_.navyMaxConcurrentInserts);
720+
nvmConfig.navyConfig.setEnableAccessTimeMap(
721+
config_.navyEnableAccessTimeMap);
722+
nvmConfig.navyConfig.setAccessTimeMapMaxSize(
723+
config_.navyAccessTimeMapMaxSize);
720724

721725
nvmConfig.truncateItemToOriginalAllocSizeInNvm =
722726
config_.truncateItemToOriginalAllocSizeInNvm;

cachelib/cachebench/util/CacheConfig.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
8888
JSONSetVal(configJson, navyEncryption);
8989
JSONSetVal(configJson, deviceMaxWriteSize);
9090
JSONSetVal(configJson, deviceEnableFDP);
91+
JSONSetVal(configJson, navyEnableAccessTimeMap);
92+
JSONSetVal(configJson, navyAccessTimeMapMaxSize);
9193

9294
JSONSetVal(configJson, memoryOnlyTTL);
9395

@@ -112,7 +114,7 @@ CacheConfig::CacheConfig(const folly::dynamic& configJson) {
112114
// if you added new fields to the configuration, update the JSONSetVal
113115
// to make them available for the json configs and increment the size
114116
// below
115-
checkCorrectSize<CacheConfig, 792>();
117+
checkCorrectSize<CacheConfig, 800>();
116118

117119
if (numPools != poolSizes.size()) {
118120
throw std::invalid_argument(folly::sformat(

cachelib/cachebench/util/CacheConfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ struct CacheConfig : public JSONConfig {
246246
// Enable the FDP Data placement mode in the device, if it is capable.
247247
bool deviceEnableFDP{false};
248248

249+
// Whether to enable the AccessTimeMap for tracking NVM item access times.
250+
bool navyEnableAccessTimeMap{false};
251+
// Maximum entries in the AccessTimeMap. 0 means unbounded.
252+
size_t navyAccessTimeMapMaxSize{0};
253+
249254
// Don't write to flash if cache TTL is smaller than this value.
250255
// Not used when its value is 0. In seconds.
251256
uint32_t memoryOnlyTTL{0};

0 commit comments

Comments
 (0)