Skip to content

Commit 9187ab7

Browse files
committed
- Change the cache size calculation to use getCacheSize()
- Switch to isUsingPosixShm() method
1 parent db52315 commit 9187ab7

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 10 additions & 9 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

@@ -242,11 +242,12 @@ std::unique_ptr<MemoryAllocator> CacheAllocator<CacheTrait>::initAllocator(
242242
InitMemType type) {
243243
if (type == InitMemType::kNone) {
244244
if (isOnShm_ == true) {
245-
return std::make_unique<MemoryAllocator>(
246-
getAllocatorConfig(config_), tempShm_->getAddr(), config_.size);
245+
return std::make_unique<MemoryAllocator>(getAllocatorConfig(config_),
246+
tempShm_->getAddr(),
247+
config_.getCacheSize());
247248
} else {
248249
return std::make_unique<MemoryAllocator>(getAllocatorConfig(config_),
249-
config_.size);
250+
config_.getCacheSize());
250251
}
251252
} else if (type == InitMemType::kMemNew) {
252253
return createNewMemoryAllocator();
@@ -2259,7 +2260,7 @@ PoolEvictionAgeStats CacheAllocator<CacheTrait>::getPoolEvictionAgeStats(
22592260
template <typename CacheTrait>
22602261
CacheMetadata CacheAllocator<CacheTrait>::getCacheMetadata() const noexcept {
22612262
return CacheMetadata{kCachelibVersion, kCacheRamFormatVersion,
2262-
kCacheNvmFormatVersion, config_.size};
2263+
kCacheNvmFormatVersion, config_.getCacheSize()};
22632264
}
22642265

22652266
template <typename CacheTrait>

cachelib/allocator/CacheAllocatorConfig.h

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

10931093
configMap["size"] = std::to_string(size);
10941094
configMap["cacheDir"] = cacheDir;
1095-
configMap["posixShm"] = usePosixShm ? "set" : "empty";
1095+
configMap["posixShm"] = isUsingPosixShm() ? "set" : "empty";
10961096

10971097
configMap["defaultAllocSizes"] = "";
10981098
// Stringify std::set

cachelib/allocator/memory/SlabAllocator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
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) {
44+
return size - (size % sizeof(Slab));
45+
}
4446
} // namespace
4547

4648
// definitions to avoid ODR violation.

0 commit comments

Comments
 (0)