Skip to content

Commit b0cb41a

Browse files
committed
os/bluestore: get rid off resulting lba alignment in allocators
Fixes: https://tracker.ceph.com/issues/62815 Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
1 parent 334e7fa commit b0cb41a

8 files changed

Lines changed: 151 additions & 103 deletions

File tree

src/os/bluestore/AvlAllocator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uint64_t AvlAllocator::_pick_block_after(uint64_t *cursor,
3939
uint64_t search_bytes = 0;
4040
auto rs_start = range_tree.lower_bound(range_t{*cursor, size}, compare);
4141
for (auto rs = rs_start; rs != range_tree.end(); ++rs) {
42-
uint64_t offset = p2roundup(rs->start, align);
42+
uint64_t offset = rs->start;
4343
*cursor = offset + size;
4444
if (offset + size <= rs->end) {
4545
return offset;
@@ -59,7 +59,7 @@ uint64_t AvlAllocator::_pick_block_after(uint64_t *cursor,
5959
}
6060
// If we reached end, start from beginning till cursor.
6161
for (auto rs = range_tree.begin(); rs != rs_start; ++rs) {
62-
uint64_t offset = p2roundup(rs->start, align);
62+
uint64_t offset = rs->start;
6363
*cursor = offset + size;
6464
if (offset + size <= rs->end) {
6565
return offset;
@@ -82,7 +82,7 @@ uint64_t AvlAllocator::_pick_block_fits(uint64_t size,
8282
const auto compare = range_size_tree.key_comp();
8383
auto rs_start = range_size_tree.lower_bound(range_t{0, size}, compare);
8484
for (auto rs = rs_start; rs != range_size_tree.end(); ++rs) {
85-
uint64_t offset = p2roundup(rs->start, align);
85+
uint64_t offset = rs->start;
8686
if (offset + size <= rs->end) {
8787
return offset;
8888
}

src/os/bluestore/BtreeAllocator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ uint64_t BtreeAllocator::_pick_block_after(uint64_t *cursor,
2525
{
2626
auto rs_start = range_tree.lower_bound(*cursor);
2727
for (auto rs = rs_start; rs != range_tree.end(); ++rs) {
28-
uint64_t offset = p2roundup(rs->first, align);
28+
uint64_t offset = rs->first;
2929
if (offset + size <= rs->second) {
3030
*cursor = offset + size;
3131
return offset;
@@ -37,7 +37,7 @@ uint64_t BtreeAllocator::_pick_block_after(uint64_t *cursor,
3737
}
3838
// If we reached end, start from beginning till cursor.
3939
for (auto rs = range_tree.begin(); rs != rs_start; ++rs) {
40-
uint64_t offset = p2roundup(rs->first, align);
40+
uint64_t offset = rs->first;
4141
if (offset + size <= rs->second) {
4242
*cursor = offset + size;
4343
return offset;
@@ -53,7 +53,7 @@ uint64_t BtreeAllocator::_pick_block_fits(uint64_t size,
5353
// the needs
5454
auto rs_start = range_size_tree.lower_bound(range_value_t{0,size});
5555
for (auto rs = rs_start; rs != range_size_tree.end(); ++rs) {
56-
uint64_t offset = p2roundup(rs->start, align);
56+
uint64_t offset = rs->start;
5757
if (offset + size <= rs->start + rs->size) {
5858
return offset;
5959
}

src/os/bluestore/StupidAllocator.cc

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ void StupidAllocator::_insert_free(uint64_t off, uint64_t len)
5252
}
5353
}
5454

55-
/// return the effective length of the extent if we align to alloc_unit
56-
uint64_t StupidAllocator::_aligned_len(
57-
StupidAllocator::interval_set_t::iterator p,
58-
uint64_t alloc_unit)
59-
{
60-
uint64_t skew = p.get_start() % alloc_unit;
61-
if (skew)
62-
skew = alloc_unit - skew;
63-
if (skew > p.get_len())
64-
return 0;
65-
else
66-
return p.get_len() - skew;
67-
}
68-
6955
int64_t StupidAllocator::allocate_int(
7056
uint64_t want_size, uint64_t alloc_unit, int64_t hint,
7157
uint64_t *offset, uint32_t *length)
@@ -89,7 +75,7 @@ int64_t StupidAllocator::allocate_int(
8975
for (bin = orig_bin; bin < (int)free.size(); ++bin) {
9076
p = free[bin].lower_bound(hint);
9177
while (p != free[bin].end()) {
92-
if (_aligned_len(p, alloc_unit) >= want_size) {
78+
if (p.get_len() >= want_size) {
9379
goto found;
9480
}
9581
++p;
@@ -102,7 +88,7 @@ int64_t StupidAllocator::allocate_int(
10288
p = free[bin].begin();
10389
auto end = hint ? free[bin].lower_bound(hint) : free[bin].end();
10490
while (p != end) {
105-
if (_aligned_len(p, alloc_unit) >= want_size) {
91+
if (p.get_len() >= want_size) {
10692
goto found;
10793
}
10894
++p;
@@ -114,7 +100,7 @@ int64_t StupidAllocator::allocate_int(
114100
for (bin = orig_bin; bin >= 0; --bin) {
115101
p = free[bin].lower_bound(hint);
116102
while (p != free[bin].end()) {
117-
if (_aligned_len(p, alloc_unit) >= alloc_unit) {
103+
if (p.get_len() >= alloc_unit) {
118104
goto found;
119105
}
120106
++p;
@@ -127,7 +113,7 @@ int64_t StupidAllocator::allocate_int(
127113
p = free[bin].begin();
128114
auto end = hint ? free[bin].lower_bound(hint) : free[bin].end();
129115
while (p != end) {
130-
if (_aligned_len(p, alloc_unit) >= alloc_unit) {
116+
if (p.get_len() >= alloc_unit) {
131117
goto found;
132118
}
133119
++p;
@@ -137,11 +123,9 @@ int64_t StupidAllocator::allocate_int(
137123
return -ENOSPC;
138124

139125
found:
140-
uint64_t skew = p.get_start() % alloc_unit;
141-
if (skew)
142-
skew = alloc_unit - skew;
143-
*offset = p.get_start() + skew;
144-
*length = std::min(std::max(alloc_unit, want_size), p2align((p.get_len() - skew), alloc_unit));
126+
*offset = p.get_start();
127+
*length = std::min(std::max(alloc_unit, want_size), p2align(p.get_len(), alloc_unit));
128+
145129
if (cct->_conf->bluestore_debug_small_allocations) {
146130
uint64_t max =
147131
alloc_unit * (rand() % cct->_conf->bluestore_debug_small_allocations);
@@ -158,7 +142,7 @@ int64_t StupidAllocator::allocate_int(
158142

159143
free[bin].erase(*offset, *length);
160144
uint64_t off, len;
161-
if (*offset && free[bin].contains(*offset - skew - 1, &off, &len)) {
145+
if (*offset && free[bin].contains(*offset - 1, &off, &len)) {
162146
int newbin = _choose_bin(len);
163147
if (newbin != bin) {
164148
ldout(cct, 30) << __func__ << " demoting 0x" << std::hex << off << "~" << len

src/os/bluestore/StupidAllocator.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class StupidAllocator : public Allocator {
3131
unsigned _choose_bin(uint64_t len);
3232
void _insert_free(uint64_t offset, uint64_t len);
3333

34-
uint64_t _aligned_len(
35-
interval_set_t::iterator p,
36-
uint64_t alloc_unit);
37-
3834
public:
3935
StupidAllocator(CephContext* cct,
4036
int64_t size,

src/os/bluestore/fastbmap_allocator_impl.cc

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@ uint64_t AllocatorLevel::l2_allocs = 0;
1717

1818
inline interval_t _align2units(uint64_t offset, uint64_t len, uint64_t min_length)
1919
{
20-
interval_t res;
21-
if (len >= min_length) {
22-
res.offset = p2roundup(offset, min_length);
23-
auto delta_off = res.offset - offset;
24-
if (len > delta_off) {
25-
res.length = len - delta_off;
26-
res.length = p2align<uint64_t>(res.length, min_length);
27-
if (res.length) {
28-
return res;
29-
}
30-
}
31-
}
32-
return interval_t();
20+
return len >= min_length ?
21+
interval_t(offset, p2align<uint64_t>(len, min_length)) :
22+
interval_t();
3323
}
3424

3525
interval_t AllocatorLevel01Loose::_get_longest_from_l0(uint64_t pos0,

src/test/objectstore/Allocator_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ TEST_P(AllocTest, test_alloc_47883)
587587
PExtentVector extents;
588588
auto need = 0x3f980000;
589589
auto got = alloc->allocate(need, 0x10000, 0, (int64_t)0, &extents);
590-
EXPECT_GT(got, 0);
591-
EXPECT_EQ(got, 0x630000);
590+
EXPECT_GE(got, 0x630000);
592591
}
593592

594593
TEST_P(AllocTest, test_alloc_50656_best_fit)

0 commit comments

Comments
 (0)