@@ -207,15 +207,15 @@ class CacheAllocatorConfig {
207
207
// cachePersistence().
208
208
CacheAllocatorConfig& usePosixForShm ();
209
209
210
- // Configures cache memory tiers. Accepts vector of MemoryTierCacheConfig.
211
- // Each vector element describes configuration for a single memory cache tier .
212
- // @throw std::invalid_argument if:
213
- // - the size of configs is 0
214
- // - memory tiers use both size and ratio parameters
210
+ // Configures cache memory tiers. Each tier represents a cache region inside
211
+ // byte-addressable memory such as DRAM, Pmem, CXLmem .
212
+ // Accepts vector of MemoryTierCacheConfig. Each vector element describes
213
+ // configuration for a single memory cache tier. Tier sizes are specified as
214
+ // ratios, the number of parts of total cache size each tier would occupy.
215
215
CacheAllocatorConfig& configureMemoryTiers (const MemoryTierConfigs& configs);
216
216
217
- // Return vector of memory tier configs .
218
- MemoryTierConfigs getMemoryTierConfigs () const ;
217
+ // Return reference to MemoryTierCacheConfigs .
218
+ const MemoryTierConfigs& getMemoryTierConfigs () const ;
219
219
220
220
// This turns on a background worker that periodically scans through the
221
221
// access container and look for expired items and remove them.
@@ -369,7 +369,7 @@ class CacheAllocatorConfig {
369
369
370
370
const std::string& getCacheName () const noexcept { return cacheName; }
371
371
372
- size_t getCacheSize () const noexcept ;
372
+ size_t getCacheSize () const noexcept { return size; }
373
373
374
374
bool isUsingPosixShm () const noexcept { return usePosixShm; }
375
375
@@ -391,8 +391,7 @@ class CacheAllocatorConfig {
391
391
std::map<std::string, std::string> serialize () const ;
392
392
393
393
// The max number of memory cache tiers
394
- // TODO: increase this number when multi-tier configs are enabled
395
- inline static const size_t kMaxCacheMemoryTiers = 1 ;
394
+ inline static const size_t kMaxCacheMemoryTiers = 2 ;
396
395
397
396
// Cache name for users to indentify their own cache.
398
397
std::string cacheName{" " };
@@ -608,8 +607,6 @@ class CacheAllocatorConfig {
608
607
friend CacheT;
609
608
610
609
private:
611
- void validateMemoryTiersWithSize (const MemoryTierConfigs&, size_t ) const ;
612
-
613
610
// Configuration for memory tiers.
614
611
MemoryTierConfigs memoryTierConfigs{
615
612
{MemoryTierCacheConfig::fromShm ().setRatio (1 )}
@@ -642,8 +639,6 @@ CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::setCacheName(
642
639
643
640
template <typename T>
644
641
CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::setCacheSize(size_t _size) {
645
- validateMemoryTiersWithSize (this ->memoryTierConfigs , _size);
646
-
647
642
size = _size;
648
643
constexpr size_t maxCacheSizeWithCoredump = 64'424'509'440 ; // 60GB
649
644
if (size <= maxCacheSizeWithCoredump) {
@@ -897,57 +892,24 @@ CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::enableItemReaperInBackground(
897
892
898
893
template <typename T>
899
894
CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::configureMemoryTiers(
900
- const MemoryTierConfigs& config) {
901
- if (!config.size ()) {
902
- throw std::invalid_argument (" There must be at least one memory tier." );
895
+ const MemoryTierConfigs& config) {
896
+ if (config.size () > kMaxCacheMemoryTiers ) {
897
+ throw std::invalid_argument (folly::sformat (
898
+ " Too many memory tiers. The number of supported tiers is {}." ,
899
+ kMaxCacheMemoryTiers ));
903
900
}
904
-
905
- for (auto tier_config: config) {
906
- auto tier_size = tier_config.getSize ();
907
- auto tier_ratio = tier_config.getRatio ();
908
- if ((!tier_size and !tier_ratio) || (tier_size and tier_ratio)) {
909
- throw std::invalid_argument (
910
- " For each memory tier either size or ratio must be set." );
911
- }
901
+ if (!config.size ()) {
902
+ throw std::invalid_argument (
903
+ " There must be at least one memory tier config." );
912
904
}
913
-
914
- validateMemoryTiersWithSize (config, this ->size );
915
-
916
905
memoryTierConfigs = config;
917
-
918
906
return *this ;
919
907
}
920
908
921
909
template <typename T>
922
- typename CacheAllocatorConfig<T>::MemoryTierConfigs
910
+ const typename CacheAllocatorConfig<T>::MemoryTierConfigs&
923
911
CacheAllocatorConfig<T>::getMemoryTierConfigs() const {
924
- MemoryTierConfigs config = memoryTierConfigs;
925
- size_t sum_ratios = 0 ;
926
-
927
- for (auto &tier_config: config) {
928
- if (auto *v = std::get_if<PosixSysVSegmentOpts>(&tier_config.shmOpts )) {
929
- v->usePosix = usePosixShm;
930
- }
931
-
932
- sum_ratios += tier_config.getRatio ();
933
- }
934
-
935
- if (sum_ratios == 0 )
936
- return config;
937
-
938
- // if ratios are used, size must be specified
939
- XDCHECK (size);
940
-
941
- // Convert ratios to sizes, size must be non-zero
942
- size_t sum_sizes = 0 ;
943
- size_t partition_size = size / sum_ratios;
944
- for (auto & tier_config: config) {
945
- tier_config.setSize (partition_size * tier_config.getRatio ());
946
- tier_config.setRatio (0 );
947
- sum_sizes += tier_config.getSize ();
948
- }
949
-
950
- return config;
912
+ return memoryTierConfigs;
951
913
}
952
914
953
915
template <typename T>
@@ -1079,46 +1041,6 @@ CacheAllocatorConfig<T>::setSkipPromoteChildrenWhenParentFailed() {
1079
1041
return *this ;
1080
1042
}
1081
1043
1082
- template <typename T>
1083
- size_t CacheAllocatorConfig<T>::getCacheSize() const noexcept {
1084
- if (size)
1085
- return size;
1086
-
1087
- size_t sum_sizes = 0 ;
1088
- for (const auto &tier_config : getMemoryTierConfigs ()) {
1089
- sum_sizes += tier_config.getSize ();
1090
- }
1091
-
1092
- return sum_sizes;
1093
- }
1094
-
1095
- template <typename T>
1096
- void CacheAllocatorConfig<T>::validateMemoryTiersWithSize(
1097
- const MemoryTierConfigs &config, size_t size) const {
1098
- size_t sum_ratios = 0 ;
1099
- size_t sum_sizes = 0 ;
1100
-
1101
- for (const auto &tier_config: config) {
1102
- sum_ratios += tier_config.getRatio ();
1103
- sum_sizes += tier_config.getSize ();
1104
- }
1105
-
1106
- if (sum_ratios && sum_sizes) {
1107
- throw std::invalid_argument (" Cannot mix ratios and sizes." );
1108
- } else if (sum_sizes) {
1109
- if (size && sum_sizes != size) {
1110
- throw std::invalid_argument (
1111
- " Sum of tier sizes doesn't match total cache size. "
1112
- " Setting of cache total size is not required when per-tier "
1113
- " sizes are specified - it is calculated as sum of tier sizes." );
1114
- }
1115
- } else if (!sum_ratios && !sum_sizes) {
1116
- throw std::invalid_argument (
1117
- " Either sum of all memory tiers sizes or sum of all ratios "
1118
- " must be greater than 0." );
1119
- }
1120
- }
1121
-
1122
1044
template <typename T>
1123
1045
const CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::validate() const {
1124
1046
// we can track tail hits only if MMType is MM2Q
@@ -1143,23 +1065,7 @@ const CacheAllocatorConfig<T>& CacheAllocatorConfig<T>::validate() const {
1143
1065
" It's not allowed to enable both RemoveCB and ItemDestructor." );
1144
1066
}
1145
1067
1146
- size_t sum_ratios = 0 ;
1147
- for (auto tier_config: memoryTierConfigs) {
1148
- sum_ratios += tier_config.getRatio ();
1149
- }
1150
-
1151
- if (sum_ratios) {
1152
- if (!size) {
1153
- throw std::invalid_argument (
1154
- " Total cache size must be specified when size ratios are "
1155
- " used to specify memory tier sizes." );
1156
- } else if (size < sum_ratios) {
1157
- throw std::invalid_argument (
1158
- " Sum of all tier size ratios is greater than total cache size." );
1159
- }
1160
- }
1161
-
1162
- return *this ;
1068
+ return validateMemoryTiers ();
1163
1069
}
1164
1070
1165
1071
template <typename T>
0 commit comments