Skip to content

Commit 4c408b4

Browse files
committed
- Change the cache size calculation to use getCacheSize()
- Switch to isUsingPosixShm() method
1 parent 08051fa commit 4c408b4

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ CacheAllocator<CacheTrait>::CacheAllocator(
5454
: config.memMonitoringEnabled()},
5555
config_(config.validate()),
5656
tempShm_(type == InitMemType::kNone && isOnShm_
57-
? std::make_unique<TempShmMapping>(config_.size)
57+
? std::make_unique<TempShmMapping>(config_.getCacheSize())
5858
: nullptr),
5959
shmManager_(type != InitMemType::kNone
6060
? std::make_unique<ShmManager>(config_.cacheDir,
61-
config_.usePosixShm)
61+
config_.isUsingPosixShm())
6262
: nullptr),
6363
deserializer_(type == InitMemType::kMemAttach ? createDeserializer()
6464
: nullptr),
@@ -122,10 +122,10 @@ CacheAllocator<CacheTrait>::createNewMemoryAllocator() {
122122
return std::make_unique<MemoryAllocator>(
123123
getAllocatorConfig(config_),
124124
shmManager_
125-
->createShm(detail::kShmCacheName, config_.size,
125+
->createShm(detail::kShmCacheName, config_.getCacheSize(),
126126
config_.slabMemoryBaseAddr, createShmCacheOpts())
127127
.addr,
128-
config_.size);
128+
config_.getCacheSize());
129129
}
130130

131131
template <typename CacheTrait>
@@ -137,7 +137,7 @@ CacheAllocator<CacheTrait>::restoreMemoryAllocator() {
137137
->attachShm(detail::kShmCacheName, config_.slabMemoryBaseAddr,
138138
createShmCacheOpts())
139139
.addr,
140-
config_.size,
140+
config_.getCacheSize(),
141141
config_.disableFullCoredump);
142142
}
143143

@@ -243,10 +243,10 @@ std::unique_ptr<MemoryAllocator> CacheAllocator<CacheTrait>::initAllocator(
243243
if (type == InitMemType::kNone) {
244244
if (isOnShm_ == true) {
245245
return std::make_unique<MemoryAllocator>(
246-
getAllocatorConfig(config_), tempShm_->getAddr(), config_.size);
246+
getAllocatorConfig(config_), tempShm_->getAddr(), config_.getCacheSize());
247247
} else {
248248
return std::make_unique<MemoryAllocator>(getAllocatorConfig(config_),
249-
config_.size);
249+
config_.getCacheSize());
250250
}
251251
} else if (type == InitMemType::kMemNew) {
252252
return createNewMemoryAllocator();
@@ -2251,7 +2251,7 @@ PoolEvictionAgeStats CacheAllocator<CacheTrait>::getPoolEvictionAgeStats(
22512251
template <typename CacheTrait>
22522252
CacheMetadata CacheAllocator<CacheTrait>::getCacheMetadata() const noexcept {
22532253
return CacheMetadata{kCachelibVersion, kCacheRamFormatVersion,
2254-
kCacheNvmFormatVersion, config_.size};
2254+
kCacheNvmFormatVersion, config_.getCacheSize()};
22552255
}
22562256

22572257
template <typename CacheTrait>

cachelib/allocator/CacheAllocatorConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ std::map<std::string, std::string> CacheAllocatorConfig<T>::serialize() const {
10851085

10861086
configMap["size"] = std::to_string(size);
10871087
configMap["cacheDir"] = cacheDir;
1088-
configMap["posixShm"] = usePosixShm ? "set" : "empty";
1088+
configMap["posixShm"] = isUsingPosixShm() ? "set" : "empty";
10891089

10901090
configMap["defaultAllocSizes"] = "";
10911091
// Stringify std::set

cachelib/allocator/memory/SlabAllocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
using namespace facebook::cachelib;
4141

4242
namespace {
43-
size_t roundDownToSlabSize(size_t size) { return size - (size % sizeof(Slab)); }
43+
static inline size_t roundDownToSlabSize(size_t size) { return size - (size % sizeof(Slab)); }
4444
} // namespace
4545

4646
// definitions to avoid ODR violation.

0 commit comments

Comments
 (0)