Skip to content

Commit ffec15f

Browse files
committed
made code clang-format compliant
1 parent e94e694 commit ffec15f

14 files changed

+129
-135
lines changed

cachelib/allocator/CacheAllocator-inl.h

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
6767
config_.accessConfig.getNumBuckets()),
6868
nullptr,
6969
ShmSegmentOpts(config_.accessConfig.getPageSize(),
70-
false, config_.usePosixShm))
70+
false,
71+
config_.usePosixShm))
7172
.addr,
7273
compressor_,
7374
[this](Item* it) -> ItemHandle { return acquire(it); })),
@@ -79,7 +80,8 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
7980
config_.chainedItemAccessConfig.getNumBuckets()),
8081
nullptr,
8182
ShmSegmentOpts(config_.accessConfig.getPageSize(),
82-
false, config_.usePosixShm))
83+
false,
84+
config_.usePosixShm))
8385
.addr,
8486
compressor_,
8587
[this](Item* it) -> ItemHandle { return acquire(it); })),
@@ -90,7 +92,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemNewT, Config config)
9092
config_.isNvmCacheTruncateAllocSizeEnabled()} {
9193
initCommon(false);
9294
shmManager_->removeShm(detail::kShmInfoName,
93-
PosixSysVSegmentOpts(config_.usePosixShm));
95+
PosixSysVSegmentOpts(config_.usePosixShm));
9496
}
9597

9698
template <typename CacheTrait>
@@ -108,15 +110,19 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
108110
accessContainer_(std::make_unique<AccessContainer>(
109111
deserializer_->deserialize<AccessSerializationType>(),
110112
config_.accessConfig,
111-
shmManager_->attachShm(detail::kShmHashTableName, nullptr,
112-
ShmSegmentOpts(PageSizeT::NORMAL, false, config_.usePosixShm)),
113+
shmManager_->attachShm(
114+
detail::kShmHashTableName,
115+
nullptr,
116+
ShmSegmentOpts(PageSizeT::NORMAL, false, config_.usePosixShm)),
113117
compressor_,
114118
[this](Item* it) -> ItemHandle { return acquire(it); })),
115119
chainedItemAccessContainer_(std::make_unique<AccessContainer>(
116120
deserializer_->deserialize<AccessSerializationType>(),
117121
config_.chainedItemAccessConfig,
118-
shmManager_->attachShm(detail::kShmChainedItemHashTableName, nullptr,
119-
ShmSegmentOpts(PageSizeT::NORMAL, false, config_.usePosixShm)),
122+
shmManager_->attachShm(
123+
detail::kShmChainedItemHashTableName,
124+
nullptr,
125+
ShmSegmentOpts(PageSizeT::NORMAL, false, config_.usePosixShm)),
120126
compressor_,
121127
[this](Item* it) -> ItemHandle { return acquire(it); })),
122128
chainedItemLocks_(config_.chainedItemsLockPower,
@@ -134,7 +140,7 @@ CacheAllocator<CacheTrait>::CacheAllocator(SharedMemAttachT, Config config)
134140
// this info shm segment here and the new info shm segment's size is larger
135141
// than this one, creating new one will fail.
136142
shmManager_->removeShm(detail::kShmInfoName,
137-
PosixSysVSegmentOpts(config_.usePosixShm));
143+
PosixSysVSegmentOpts(config_.usePosixShm));
138144
}
139145

140146
template <typename CacheTrait>
@@ -275,8 +281,9 @@ void CacheAllocator<CacheTrait>::initWorkers() {
275281

276282
template <typename CacheTrait>
277283
std::unique_ptr<Deserializer> CacheAllocator<CacheTrait>::createDeserializer() {
278-
auto infoAddr = shmManager_->attachShm(detail::kShmInfoName, nullptr,
279-
ShmSegmentOpts(PageSizeT::NORMAL, false, config_.usePosixShm));
284+
auto infoAddr = shmManager_->attachShm(
285+
detail::kShmInfoName, nullptr,
286+
ShmSegmentOpts(PageSizeT::NORMAL, false, config_.usePosixShm));
280287
return std::make_unique<Deserializer>(
281288
reinterpret_cast<uint8_t*>(infoAddr.addr),
282289
reinterpret_cast<uint8_t*>(infoAddr.addr) + infoAddr.size);
@@ -3141,8 +3148,10 @@ void CacheAllocator<CacheTrait>::saveRamCache() {
31413148
ShmSegmentOpts opts;
31423149
opts.typeOpts = PosixSysVSegmentOpts(config_.usePosixShm);
31433150

3144-
void* infoAddr = shmManager_->createShm(detail::kShmInfoName, ioBuf->length(),
3145-
nullptr, opts).addr;
3151+
void* infoAddr =
3152+
shmManager_
3153+
->createShm(detail::kShmInfoName, ioBuf->length(), nullptr, opts)
3154+
.addr;
31463155
Serializer serializer(reinterpret_cast<uint8_t*>(infoAddr),
31473156
reinterpret_cast<uint8_t*>(infoAddr) + ioBuf->length());
31483157
serializer.writeToBuffer(std::move(ioBuf));
@@ -3492,8 +3501,8 @@ bool CacheAllocator<CacheTrait>::stopReaper(std::chrono::seconds timeout) {
34923501
}
34933502

34943503
template <typename CacheTrait>
3495-
bool CacheAllocator<CacheTrait>::cleanupStrayShmSegments(
3496-
const std::string& cacheDir, bool posix /*TODO(SHM_FILE): const std::vector<CacheMemoryTierConfig>& config */) {
3504+
bool CacheAllocator<
3505+
CacheTrait>::cleanupStrayShmSegments(const std::string& cacheDir, bool posix /*TODO(SHM_FILE): const std::vector<CacheMemoryTierConfig>& config */) {
34973506
if (util::getStatIfExists(cacheDir, nullptr) && util::isDir(cacheDir)) {
34983507
try {
34993508
// cache dir exists. clean up only if there are no other processes
@@ -3516,7 +3525,8 @@ bool CacheAllocator<CacheTrait>::cleanupStrayShmSegments(
35163525
// TODO(SHM_FILE): try to nuke segments of differente types (which require
35173526
// extra info)
35183527
// for (auto &tier : config) {
3519-
// ShmManager::removeByName(cacheDir, tierShmName, config_.memoryTiers[i].opts);
3528+
// ShmManager::removeByName(cacheDir, tierShmName,
3529+
// config_.memoryTiers[i].opts);
35203530
// }
35213531
}
35223532
return true;

cachelib/allocator/CacheAllocator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,9 @@ class CacheAllocator : public CacheBase {
11911191
// returns true if there was no error in trying to cleanup the segment
11921192
// because another process was attached. False if the user tried to clean up
11931193
// and the cache was actually attached.
1194-
static bool cleanupStrayShmSegments(const std::string& cacheDir, bool posix
1195-
/*TODO: const std::vector<CacheMemoryTierConfig>& config = {} */);
1194+
static bool cleanupStrayShmSegments(
1195+
const std::string& cacheDir, bool posix
1196+
/*TODO: const std::vector<CacheMemoryTierConfig>& config = {} */);
11961197

11971198
// gives a relative offset to a pointer within the cache.
11981199
uint64_t getItemPtrAsOffset(const void* ptr);

cachelib/allocator/TempShmMapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TempShmMapping::~TempShmMapping() {
3535
try {
3636
if (addr_) {
3737
shmManager_->removeShm(detail::kTempShmCacheName.str(),
38-
PosixSysVSegmentOpts(false /* posix */));
38+
PosixSysVSegmentOpts(false /* posix */));
3939
}
4040
if (shmManager_) {
4141
shmManager_.reset();
@@ -79,7 +79,7 @@ void* TempShmMapping::createShmMapping(ShmManager& shmManager,
7979
} catch (...) {
8080
if (shmAddr) {
8181
shmManager.removeShm(detail::kTempShmCacheName.str(),
82-
PosixSysVSegmentOpts(false /* posix */));
82+
PosixSysVSegmentOpts(false /* posix */));
8383
} else {
8484
munmap(addr, size);
8585
}

cachelib/shm/FileShmSegment.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@ namespace facebook {
2828
namespace cachelib {
2929

3030
FileShmSegment::FileShmSegment(ShmAttachT,
31-
const std::string& name,
32-
ShmSegmentOpts opts)
33-
: ShmBase(std::move(opts), name),
34-
fd_(getExisting(getPath(), opts_)) {
31+
const std::string& name,
32+
ShmSegmentOpts opts)
33+
: ShmBase(std::move(opts), name), fd_(getExisting(getPath(), opts_)) {
3534
XDCHECK_NE(fd_, kInvalidFD);
3635
markActive();
3736
createReferenceMapping();
3837
}
3938

4039
FileShmSegment::FileShmSegment(ShmNewT,
41-
const std::string& name,
42-
size_t size,
43-
ShmSegmentOpts opts)
44-
: ShmBase(std::move(opts), name),
45-
fd_(createNewSegment(getPath())) {
40+
const std::string& name,
41+
size_t size,
42+
ShmSegmentOpts opts)
43+
: ShmBase(std::move(opts), name), fd_(createNewSegment(getPath())) {
4644
markActive();
4745
resize(size);
4846
XDCHECK(isActive());
@@ -79,7 +77,7 @@ int FileShmSegment::createNewSegment(const std::string& name) {
7977
}
8078

8179
int FileShmSegment::getExisting(const std::string& name,
82-
const ShmSegmentOpts& opts) {
80+
const ShmSegmentOpts& opts) {
8381
int flags = opts.readOnly ? O_RDONLY : O_RDWR;
8482
detail::open_func_t open_func = std::bind(open, name.c_str(), flags);
8583
return detail::openImpl(open_func, flags);

cachelib/shm/FileShmSegment.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,16 @@ class FileShmSegment : public ShmBase {
4747
//
4848
// @param name Name of the segment
4949
// @param opts the options for attaching to the segment.
50-
FileShmSegment(ShmAttachT,
51-
const std::string& name,
52-
ShmSegmentOpts opts = {});
50+
FileShmSegment(ShmAttachT, const std::string& name, ShmSegmentOpts opts = {});
5351

5452
// create a new segment
5553
// @param name The name of the segment
5654
// @param size The size of the segment. This will be rounded up to the
5755
// nearest page size.
5856
FileShmSegment(ShmNewT,
59-
const std::string& name,
60-
size_t size,
61-
ShmSegmentOpts opts = {});
57+
const std::string& name,
58+
size_t size,
59+
ShmSegmentOpts opts = {});
6260

6361
// destructor
6462
~FileShmSegment() override;

cachelib/shm/PosixShmSegment.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ PosixShmSegment::~PosixShmSegment() {
7676

7777
int PosixShmSegment::createNewSegment(const std::string& name) {
7878
constexpr static int createFlags = O_RDWR | O_CREAT | O_EXCL;
79-
detail::open_func_t open_func = std::bind(shm_open, name.c_str(), createFlags, kRWMode);
79+
detail::open_func_t open_func =
80+
std::bind(shm_open, name.c_str(), createFlags, kRWMode);
8081
return detail::openImpl(open_func, createFlags);
8182
}
8283

8384
int PosixShmSegment::getExisting(const std::string& name,
8485
const ShmSegmentOpts& opts) {
8586
int flags = opts.readOnly ? O_RDONLY : O_RDWR;
86-
detail::open_func_t open_func = std::bind(shm_open, name.c_str(), flags, kRWMode);
87+
detail::open_func_t open_func =
88+
std::bind(shm_open, name.c_str(), flags, kRWMode);
8789
return detail::openImpl(open_func, flags);
8890
}
8991

cachelib/shm/Shm.h

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,34 @@ class ShmSegment {
4848
// @param name name of the segment
4949
// @param size size of the segment.
5050
// @param opts the options for the segment.
51-
ShmSegment(ShmNewT,
52-
std::string name,
53-
size_t size,
54-
ShmSegmentOpts opts = {}) {
55-
if (auto *v = std::get_if<FileShmSegmentOpts>(&opts.typeOpts)) {
56-
segment_ = std::make_unique<FileShmSegment>(
57-
ShmNew, std::move(name), size, opts);
58-
} else if (auto *v = std::get_if<PosixSysVSegmentOpts>(&opts.typeOpts)) {
51+
ShmSegment(ShmNewT, std::string name, size_t size, ShmSegmentOpts opts = {}) {
52+
if (auto* v = std::get_if<FileShmSegmentOpts>(&opts.typeOpts)) {
53+
segment_ =
54+
std::make_unique<FileShmSegment>(ShmNew, std::move(name), size, opts);
55+
} else if (auto* v = std::get_if<PosixSysVSegmentOpts>(&opts.typeOpts)) {
5956
if (v->usePosix)
60-
segment_ = std::make_unique<PosixShmSegment>(
61-
ShmNew, std::move(name), size, opts);
57+
segment_ = std::make_unique<PosixShmSegment>(ShmNew, std::move(name),
58+
size, opts);
6259
else
63-
segment_ = std::make_unique<SysVShmSegment>(
64-
ShmNew, std::move(name), size, opts);
60+
segment_ = std::make_unique<SysVShmSegment>(ShmNew, std::move(name),
61+
size, opts);
6562
}
6663
}
6764

6865
// attach to an existing segment with the given key
6966
// @param name name of the segment
7067
// @param opts the options for the segment.
71-
ShmSegment(ShmAttachT,
72-
std::string name,
73-
ShmSegmentOpts opts = {}) {
68+
ShmSegment(ShmAttachT, std::string name, ShmSegmentOpts opts = {}) {
7469
if (std::get_if<FileShmSegmentOpts>(&opts.typeOpts)) {
75-
segment_ = std::make_unique<FileShmSegment>(
76-
ShmAttach, std::move(name), opts);
77-
} else if (auto *v = std::get_if<PosixSysVSegmentOpts>(&opts.typeOpts)) {
70+
segment_ =
71+
std::make_unique<FileShmSegment>(ShmAttach, std::move(name), opts);
72+
} else if (auto* v = std::get_if<PosixSysVSegmentOpts>(&opts.typeOpts)) {
7873
if (v->usePosix)
79-
segment_ = std::make_unique<PosixShmSegment>(
80-
ShmAttach, std::move(name), opts);
74+
segment_ =
75+
std::make_unique<PosixShmSegment>(ShmAttach, std::move(name), opts);
8176
else
82-
segment_ = std::make_unique<SysVShmSegment>(
83-
ShmAttach, std::move(name), opts);
77+
segment_ =
78+
std::make_unique<SysVShmSegment>(ShmAttach, std::move(name), opts);
8479
}
8580
}
8681

cachelib/shm/ShmCommon.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <folly/Range.h>
2222
#include <folly/String.h>
2323
#include <folly/logging/xlog.h>
24-
#include <sys/types.h>
2524
#include <sys/mman.h>
25+
#include <sys/types.h>
2626

2727
namespace facebook {
2828
namespace cachelib {
@@ -245,7 +245,8 @@ void fstatImpl(int fd, stat_t* buf) {
245245
}
246246
}
247247

248-
void* mmapImpl(void* addr, size_t length, int prot, int flags, int fd, off_t offset) {
248+
void* mmapImpl(
249+
void* addr, size_t length, int prot, int flags, int fd, off_t offset) {
249250
void* ret = mmap(addr, length, prot, flags, fd, offset);
250251
if (ret != MAP_FAILED) {
251252
return ret;

cachelib/shm/ShmCommon.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ enum PageSizeT {
7878
};
7979

8080
struct FileShmSegmentOpts {
81-
FileShmSegmentOpts(std::string path = ""): path(path) {}
81+
FileShmSegmentOpts(std::string path = "") : path(path) {}
8282
std::string path;
8383
};
8484

8585
struct PosixSysVSegmentOpts {
86-
PosixSysVSegmentOpts(bool usePosix = false): usePosix(usePosix) {}
86+
PosixSysVSegmentOpts(bool usePosix = false) : usePosix(usePosix) {}
8787
bool usePosix;
8888
};
8989

@@ -92,17 +92,15 @@ using ShmTypeOpts = std::variant<FileShmSegmentOpts, PosixSysVSegmentOpts>;
9292
struct ShmSegmentOpts {
9393
PageSizeT pageSize{PageSizeT::NORMAL};
9494
bool readOnly{false};
95-
size_t alignment{1}; // alignment for mapping.
95+
size_t alignment{1}; // alignment for mapping.
9696
ShmTypeOpts typeOpts{}; // opts specific to segment type
9797

9898
explicit ShmSegmentOpts(PageSizeT p) : pageSize(p) {}
9999
explicit ShmSegmentOpts(PageSizeT p, bool ro) : pageSize(p), readOnly(ro) {}
100-
explicit ShmSegmentOpts(PageSizeT p, bool ro, const std::string& path) :
101-
pageSize(p), readOnly(ro),
102-
typeOpts(path) {}
103-
explicit ShmSegmentOpts(PageSizeT p, bool ro, bool posix) :
104-
pageSize(p), readOnly(ro),
105-
typeOpts(posix) {}
100+
explicit ShmSegmentOpts(PageSizeT p, bool ro, const std::string& path)
101+
: pageSize(p), readOnly(ro), typeOpts(path) {}
102+
explicit ShmSegmentOpts(PageSizeT p, bool ro, bool posix)
103+
: pageSize(p), readOnly(ro), typeOpts(posix) {}
106104
ShmSegmentOpts() : pageSize(PageSizeT::NORMAL) {}
107105
};
108106

@@ -195,7 +193,8 @@ void ftruncateImpl(int fd, size_t size);
195193
void fstatImpl(int fd, stat_t* buf);
196194

197195
// @throw std::invalid_argument if there is an error
198-
void* mmapImpl(void* addr, size_t length, int prot, int flags, int fd, off_t offset);
196+
void* mmapImpl(
197+
void* addr, size_t length, int prot, int flags, int fd, off_t offset);
199198

200199
// @throw std::invalid_argument if there is an error
201200
void munmapImpl(void* addr, size_t length);

0 commit comments

Comments
 (0)