Skip to content

Commit 1034076

Browse files
authored
Merge pull request ceph#64063 from tchaikov/wip-ec-cache-refactor
osd/ECExtentCache: cleanup and optimization
2 parents 012193a + f4118f8 commit 1034076

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

src/osd/ECExtentCache.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "ECExtentCache.h"
55
#include "ECUtil.h"
66

7+
#include <mutex>
78
#include <ranges>
89

910
using namespace std;
@@ -369,41 +370,37 @@ void ECExtentCache::LRU::add(const Line &line) {
369370

370371
shared_ptr<shard_extent_map_t> cache = line.cache;
371372

372-
mutex.lock();
373+
std::lock_guard lock{mutex};
373374
ceph_assert(!map.contains(k));
374375
auto i = lru.insert(lru.end(), k);
375376
auto j = make_pair(std::move(i), std::move(cache));
376377
map.insert(std::pair(std::move(k), std::move(j)));
377378
size += line.size; // This is already accounted for in mempool.
378379
free_maybe();
379-
mutex.unlock();
380380
}
381381

382382
shared_ptr<shard_extent_map_t> ECExtentCache::LRU::find(
383383
const hobject_t &oid, uint64_t offset) {
384-
Key k(offset, oid);
385384
shared_ptr<shard_extent_map_t> cache = nullptr;
386-
mutex.lock();
387-
if (map.contains(k)) {
388-
auto &&[lru_iter, c] = map.at(k);
385+
std::lock_guard lock{mutex};
386+
if (auto found = map.find({offset, oid}); found != map.end()) {
387+
auto &&[lru_iter, c] = found->second;
389388
cache = c;
390389
auto it = lru_iter; // Intentional copy.
391390
erase(it, false);
392391
}
393-
mutex.unlock();
394392
return cache;
395393
}
396394

397395
void ECExtentCache::LRU::remove_object(const hobject_t &oid) {
398-
mutex.lock();
396+
std::lock_guard lock{mutex};
399397
for (auto it = lru.begin(); it != lru.end();) {
400398
if (it->oid == oid) {
401399
it = erase(it, true);
402400
} else {
403401
++it;
404402
}
405403
}
406-
mutex.unlock();
407404
}
408405

409406
void ECExtentCache::LRU::free_maybe() {
@@ -414,12 +411,11 @@ void ECExtentCache::LRU::free_maybe() {
414411
}
415412

416413
void ECExtentCache::LRU::discard() {
417-
mutex.lock();
414+
std::lock_guard lock{mutex};
418415
lru.clear();
419416
update_mempool(0 - map.size(), 0 - size);
420417
map.clear();
421418
size = 0;
422-
mutex.unlock();
423419
}
424420

425421
const extent_set ECExtentCache::Op::get_pin_eset(uint64_t alignment) const {

src/osd/ECExtentCache.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,10 @@ class ECExtentCache {
104104

105105
class LRU {
106106
public:
107-
class Key {
108-
public:
107+
struct Key {
109108
uint64_t offset;
110109
hobject_t oid;
111-
112-
Key(uint64_t offset, const hobject_t &oid) : offset(offset), oid(oid) {};
113-
114-
friend bool operator==(const Key &lhs, const Key &rhs) {
115-
return lhs.offset == rhs.offset
116-
&& lhs.oid == rhs.oid;
117-
}
118-
119-
friend bool operator!=(const Key &lhs, const Key &rhs) {
120-
return !(lhs == rhs);
121-
}
110+
bool operator==(const Key&) const = default;
122111
};
123112

124113
struct KeyHash {

0 commit comments

Comments
 (0)