Skip to content

Commit 64ebfc8

Browse files
zhscnMatan-B
authored andcommitted
crimson/os/seastore/BtreeLBAManager: cleanup alloc_mapping_info_t
Signed-off-by: Zhang Song <[email protected]> (cherry picked from commit 20f2ed8)
1 parent e0f19f5 commit 64ebfc8

File tree

4 files changed

+73
-73
lines changed

4 files changed

+73
-73
lines changed

src/crimson/os/seastore/lba_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class LBAManager {
7777
Transaction &t,
7878
laddr_t hint,
7979
LogicalChildNode &nextent,
80-
extent_ref_count_t refcount = EXTENT_DEFAULT_REF_COUNT) = 0;
80+
extent_ref_count_t refcount) = 0;
8181

8282
using alloc_extents_ret = alloc_extent_iertr::future<
8383
std::vector<LBAMappingRef>>;

src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.cc

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ BtreeLBAManager::alloc_extents_ret
279279
BtreeLBAManager::_alloc_extents(
280280
Transaction &t,
281281
laddr_t hint,
282-
std::vector<alloc_mapping_info_t> &alloc_infos,
283-
extent_ref_count_t refcount)
282+
std::vector<alloc_mapping_info_t> &alloc_infos)
284283
{
285284
ceph_assert(hint != L_ADDR_NULL);
286285
extent_len_t total_len = 0;
@@ -291,16 +290,16 @@ BtreeLBAManager::_alloc_extents(
291290
assert((info.key == L_ADDR_NULL) == (laddr_null));
292291
if (!laddr_null) {
293292
assert(info.key >= last_end);
294-
last_end = (info.key + info.len).checked_to_laddr();
293+
last_end = (info.key + info.value.len).checked_to_laddr();
295294
}
296295
}
297296
#endif
298297
if (alloc_infos.front().key == L_ADDR_NULL) {
299298
for (auto &info : alloc_infos) {
300-
total_len += info.len;
299+
total_len += info.value.len;
301300
}
302301
} else {
303-
auto end = alloc_infos.back().key + alloc_infos.back().len;
302+
auto end = alloc_infos.back().key + alloc_infos.back().value.len;
304303
total_len = end.get_byte_distance<extent_len_t>(hint);
305304
}
306305

@@ -314,21 +313,21 @@ BtreeLBAManager::_alloc_extents(
314313
};
315314

316315
LOG_PREFIX(BtreeLBAManager::_alloc_extents);
317-
TRACET("{}~{}, hint={}, num of extents: {}, refcount={}",
318-
t, alloc_infos.front().val, total_len, hint, alloc_infos.size(), refcount);
316+
TRACET("{}~{}, hint={}, num of extents: {}",
317+
t, alloc_infos.front().value.pladdr, total_len, hint, alloc_infos.size());
319318

320319
auto c = get_context(t);
321320
stats.num_alloc_extents += alloc_infos.size();
322321
auto lookup_attempts = stats.num_alloc_extents_iter_nexts;
323322
return seastar::do_with(
324323
std::vector<LBAMappingRef>(),
325324
[this, FNAME, &alloc_infos, hint, &t, total_len, c,
326-
lookup_attempts, refcount](auto &rets) {
325+
lookup_attempts](auto &rets) {
327326
return crimson::os::seastore::with_btree_state<LBABtree, state_t>(
328327
cache,
329328
c,
330329
hint,
331-
[this, c, hint, total_len, addr=alloc_infos.front().val, &rets, refcount,
330+
[this, c, hint, total_len, addr=alloc_infos.front().value.pladdr.get_paddr(), &rets,
332331
lookup_attempts, &t, &alloc_infos, FNAME](auto &btree, auto &state) {
333332
return LBABtree::iterate_repeat(
334333
c,
@@ -367,7 +366,7 @@ BtreeLBAManager::_alloc_extents(
367366
seastar::stop_iteration::no);
368367
}
369368
}).si_then([c, addr, hint, &btree, &state, &alloc_infos,
370-
total_len, &rets, refcount, FNAME] {
369+
total_len, &rets, FNAME] {
371370
return trans_intr::do_for_each(
372371
alloc_infos,
373372
[c, addr, hint, &btree, &state, FNAME,
@@ -379,11 +378,7 @@ BtreeLBAManager::_alloc_extents(
379378
c,
380379
*state.insert_iter,
381380
state.last_end,
382-
lba_map_val_t{
383-
alloc_info.len,
384-
pladdr_t(alloc_info.val),
385-
refcount,
386-
alloc_info.checksum}
381+
alloc_info.value
387382
).si_then([&state, c, addr, total_len, hint, FNAME,
388383
&alloc_info, &rets](auto &&p) {
389384
auto [iter, inserted] = std::move(p);
@@ -395,9 +390,9 @@ BtreeLBAManager::_alloc_extents(
395390
TRACET("{}~{}, hint={}, inserted at {}",
396391
c.trans, addr, total_len, hint, state.last_end);
397392
if (is_valid_child_ptr(alloc_info.extent)) {
398-
ceph_assert(alloc_info.val.is_paddr());
399-
assert(alloc_info.val == iter.get_val().pladdr);
400-
assert(alloc_info.len == iter.get_val().len);
393+
ceph_assert(alloc_info.value.pladdr.is_paddr());
394+
assert(alloc_info.value.pladdr == iter.get_val().pladdr);
395+
assert(alloc_info.value.len == iter.get_val().len);
401396
assert(alloc_info.extent->is_logical());
402397
if (alloc_info.extent->has_laddr()) {
403398
// see TM::remap_pin()
@@ -414,7 +409,7 @@ BtreeLBAManager::_alloc_extents(
414409
return iter.next(c).si_then([&state, &alloc_info](auto it) {
415410
state.insert_iter = it;
416411
if (alloc_info.key == L_ADDR_NULL) {
417-
state.last_end = (state.last_end + alloc_info.len).checked_to_laddr();
412+
state.last_end = (state.last_end + alloc_info.value.len).checked_to_laddr();
418413
}
419414
});
420415
});

src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.h

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -69,44 +69,6 @@ class BtreeLBAManager : public LBAManager {
6969
Transaction &t,
7070
laddr_t offset) final;
7171

72-
struct alloc_mapping_info_t {
73-
laddr_t key = L_ADDR_NULL; // once assigned, the allocation to
74-
// key must be exact and successful
75-
extent_len_t len = 0;
76-
pladdr_t val;
77-
uint32_t checksum = 0;
78-
LogicalChildNode* extent = nullptr;
79-
80-
static alloc_mapping_info_t create_zero(extent_len_t len) {
81-
return {
82-
L_ADDR_NULL,
83-
len,
84-
P_ADDR_ZERO,
85-
0,
86-
static_cast<LogicalChildNode*>(get_reserved_ptr<LBALeafNode, laddr_t>())};
87-
}
88-
static alloc_mapping_info_t create_indirect(
89-
laddr_t laddr,
90-
extent_len_t len,
91-
laddr_t intermediate_key) {
92-
return {
93-
laddr,
94-
len,
95-
intermediate_key,
96-
0, // crc will only be used and checked with LBA direct mappings
97-
// also see pin_to_extent(_by_type)
98-
static_cast<LogicalChildNode*>(get_reserved_ptr<LBALeafNode, laddr_t>())};
99-
}
100-
static alloc_mapping_info_t create_direct(
101-
laddr_t laddr,
102-
extent_len_t len,
103-
paddr_t paddr,
104-
uint32_t checksum,
105-
LogicalChildNode& extent) {
106-
return {laddr, len, paddr, checksum, &extent};
107-
}
108-
};
109-
11072
alloc_extent_ret reserve_region(
11173
Transaction &t,
11274
laddr_t hint,
@@ -120,8 +82,7 @@ class BtreeLBAManager : public LBAManager {
12082
return _alloc_extents(
12183
t,
12284
hint,
123-
alloc_infos,
124-
EXTENT_DEFAULT_REF_COUNT
85+
alloc_infos
12586
).si_then([](auto mappings) {
12687
assert(mappings.size() == 1);
12788
auto mapping = std::move(mappings.front());
@@ -169,7 +130,7 @@ class BtreeLBAManager : public LBAManager {
169130
Transaction &t,
170131
laddr_t hint,
171132
LogicalChildNode &ext,
172-
extent_ref_count_t refcount = EXTENT_DEFAULT_REF_COUNT) final
133+
extent_ref_count_t refcount) final
173134
{
174135
// The real checksum will be updated upon transaction commit
175136
assert(ext.get_last_committed_crc() == 0);
@@ -179,6 +140,7 @@ class BtreeLBAManager : public LBAManager {
179140
L_ADDR_NULL,
180141
ext.get_length(),
181142
ext.get_paddr(),
143+
refcount,
182144
ext.get_last_committed_crc(),
183145
ext)};
184146
return seastar::do_with(
@@ -187,8 +149,7 @@ class BtreeLBAManager : public LBAManager {
187149
return _alloc_extents(
188150
t,
189151
hint,
190-
alloc_infos,
191-
refcount
152+
alloc_infos
192153
).si_then([](auto mappings) {
193154
assert(mappings.size() == 1);
194155
auto mapping = std::move(mappings.front());
@@ -211,13 +172,14 @@ class BtreeLBAManager : public LBAManager {
211172
extent->has_laddr() ? extent->get_laddr() : L_ADDR_NULL,
212173
extent->get_length(),
213174
extent->get_paddr(),
175+
refcount,
214176
extent->get_last_committed_crc(),
215177
*extent));
216178
}
217179
return seastar::do_with(
218180
std::move(alloc_infos),
219-
[this, &t, hint, refcount](auto &alloc_infos) {
220-
return _alloc_extents(t, hint, alloc_infos, refcount);
181+
[this, &t, hint](auto &alloc_infos) {
182+
return _alloc_extents(t, hint, alloc_infos);
221183
});
222184
}
223185

@@ -396,6 +358,49 @@ class BtreeLBAManager : public LBAManager {
396358
uint64_t num_alloc_extents_iter_nexts = 0;
397359
} stats;
398360

361+
struct alloc_mapping_info_t {
362+
laddr_t key = L_ADDR_NULL; // once assigned, the allocation to
363+
// key must be exact and successful
364+
lba_map_val_t value;
365+
LogicalChildNode* extent = nullptr;
366+
367+
static alloc_mapping_info_t create_zero(extent_len_t len) {
368+
return {
369+
L_ADDR_NULL,
370+
{
371+
len,
372+
pladdr_t(P_ADDR_ZERO),
373+
EXTENT_DEFAULT_REF_COUNT,
374+
0
375+
},
376+
static_cast<LogicalChildNode*>(get_reserved_ptr<LBALeafNode, laddr_t>())};
377+
}
378+
static alloc_mapping_info_t create_indirect(
379+
laddr_t laddr,
380+
extent_len_t len,
381+
laddr_t intermediate_key) {
382+
return {
383+
laddr,
384+
{
385+
len,
386+
pladdr_t(intermediate_key),
387+
EXTENT_DEFAULT_REF_COUNT,
388+
0 // crc will only be used and checked with LBA direct mappings
389+
// also see pin_to_extent(_by_type)
390+
},
391+
static_cast<LogicalChildNode*>(get_reserved_ptr<LBALeafNode, laddr_t>())};
392+
}
393+
static alloc_mapping_info_t create_direct(
394+
laddr_t laddr,
395+
extent_len_t len,
396+
paddr_t paddr,
397+
extent_ref_count_t refcount,
398+
checksum_t checksum,
399+
LogicalChildNode& extent) {
400+
return {laddr, {len, pladdr_t(paddr), refcount, checksum}, &extent};
401+
}
402+
};
403+
399404
op_context_t get_context(Transaction &t) {
400405
return op_context_t{cache, t};
401406
}
@@ -445,8 +450,7 @@ class BtreeLBAManager : public LBAManager {
445450
alloc_extents_ret _alloc_extents(
446451
Transaction &t,
447452
laddr_t hint,
448-
std::vector<alloc_mapping_info_t> &alloc_infos,
449-
extent_ref_count_t refcount);
453+
std::vector<alloc_mapping_info_t> &alloc_infos);
450454

451455
ref_ret _incref_extent(
452456
Transaction &t,
@@ -466,7 +470,8 @@ class BtreeLBAManager : public LBAManager {
466470
{
467471
#ifndef NDEBUG
468472
for (auto &alloc_info : alloc_infos) {
469-
assert(alloc_info.val.get_laddr() != L_ADDR_NULL);
473+
assert(alloc_info.value.pladdr.get_laddr() != L_ADDR_NULL);
474+
assert(alloc_info.value.refcount == EXTENT_DEFAULT_REF_COUNT);
470475
}
471476
#endif
472477
return seastar::do_with(
@@ -475,8 +480,7 @@ class BtreeLBAManager : public LBAManager {
475480
return _alloc_extents(
476481
t,
477482
laddr,
478-
alloc_infos,
479-
EXTENT_DEFAULT_REF_COUNT
483+
alloc_infos
480484
).si_then([&alloc_infos](auto mappings) {
481485
assert(alloc_infos.size() == mappings.size());
482486
std::vector<BtreeLBAMappingRef> rets;
@@ -487,8 +491,8 @@ class BtreeLBAManager : public LBAManager {
487491
[[maybe_unused]] auto &alloc_info = *ait;
488492
assert(mapping->get_key() == alloc_info.key);
489493
assert(mapping->get_raw_val().get_laddr() ==
490-
alloc_info.val.get_laddr());
491-
assert(mapping->get_length() == alloc_info.len);
494+
alloc_info.value.pladdr.get_laddr());
495+
assert(mapping->get_length() == alloc_info.value.len);
492496
rets.emplace_back(mapping);
493497
}
494498
return rets;

src/crimson/os/seastore/transaction_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ class TransactionManager : public ExtentCallbackInterface {
402402
return lba_manager->alloc_extent(
403403
t,
404404
laddr_hint,
405-
*ext
405+
*ext,
406+
EXTENT_DEFAULT_REF_COUNT
406407
).si_then([ext=std::move(ext), &t, FNAME](auto &&) mutable {
407408
SUBDEBUGT(seastore_tm, "allocated {}", t, *ext);
408409
return alloc_extent_iertr::make_ready_future<TCachedExtentRef<T>>(

0 commit comments

Comments
 (0)