Skip to content

Commit 496959e

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

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 9 additions & 10 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>
@@ -135,9 +135,8 @@ CacheAllocator<CacheTrait>::restoreMemoryAllocator() {
135135
deserializer_->deserialize<MemoryAllocator::SerializationType>(),
136136
shmManager_
137137
->attachShm(detail::kShmCacheName, config_.slabMemoryBaseAddr,
138-
createShmCacheOpts())
139-
.addr,
140-
config_.size,
138+
createShmCacheOpts()).addr,
139+
config_.getCacheSize(),
141140
config_.disableFullCoredump);
142141
}
143142

@@ -243,10 +242,10 @@ std::unique_ptr<MemoryAllocator> CacheAllocator<CacheTrait>::initAllocator(
243242
if (type == InitMemType::kNone) {
244243
if (isOnShm_ == true) {
245244
return std::make_unique<MemoryAllocator>(
246-
getAllocatorConfig(config_), tempShm_->getAddr(), config_.size);
245+
getAllocatorConfig(config_), tempShm_->getAddr(), config_.getCacheSize());
247246
} else {
248247
return std::make_unique<MemoryAllocator>(getAllocatorConfig(config_),
249-
config_.size);
248+
config_.getCacheSize());
250249
}
251250
} else if (type == InitMemType::kMemNew) {
252251
return createNewMemoryAllocator();
@@ -2251,7 +2250,7 @@ PoolEvictionAgeStats CacheAllocator<CacheTrait>::getPoolEvictionAgeStats(
22512250
template <typename CacheTrait>
22522251
CacheMetadata CacheAllocator<CacheTrait>::getCacheMetadata() const noexcept {
22532252
return CacheMetadata{kCachelibVersion, kCacheRamFormatVersion,
2254-
kCacheNvmFormatVersion, config_.size};
2253+
kCacheNvmFormatVersion, config_.getCacheSize()};
22552254
}
22562255

22572256
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)