Skip to content

Commit fa83b90

Browse files
authored
Merge pull request ceph#57015 from liangmingyuanneo/wip-bluefs-max-alloc-size
bluefs: bluefs alloc unit should only be shrink Reviewed-by: Igor Fedotov <[email protected]>
2 parents 6893bac + eed0312 commit fa83b90

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

src/os/bluestore/BlueFS.cc

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,27 @@ void BlueFS::_init_alloc()
712712
{
713713
dout(20) << __func__ << dendl;
714714

715+
// 'changed' should keep its previous value if no actual modification occurred
716+
auto change_alloc_size = [this](uint64_t& max_alloc_size,
717+
uint64_t new_alloc, bool& changed) {
718+
if (max_alloc_size == 0 ||
719+
(max_alloc_size > new_alloc && ((new_alloc & (new_alloc -1)) == 0))) {
720+
max_alloc_size = new_alloc;
721+
changed = true;
722+
dout(5) << " changed alloc_size to 0x" << std::hex << new_alloc << dendl;
723+
} else if (max_alloc_size != new_alloc) {
724+
derr << " can not change current alloc_size 0x" << std::hex
725+
<< max_alloc_size << " to new alloc_size 0x" << new_alloc << dendl;
726+
}
727+
};
728+
729+
bool alloc_size_changed = false;
715730
size_t wal_alloc_size = 0;
716731
if (bdev[BDEV_WAL]) {
717732
wal_alloc_size = cct->_conf->bluefs_alloc_size;
718733
alloc_size[BDEV_WAL] = wal_alloc_size;
734+
change_alloc_size(super.bluefs_max_alloc_size[BDEV_WAL],
735+
wal_alloc_size, alloc_size_changed);
719736
}
720737
logger->set(l_bluefs_wal_alloc_unit, wal_alloc_size);
721738

@@ -731,25 +748,46 @@ void BlueFS::_init_alloc()
731748
if (bdev[BDEV_SLOW]) {
732749
alloc_size[BDEV_DB] = cct->_conf->bluefs_alloc_size;
733750
alloc_size[BDEV_SLOW] = shared_alloc_size;
751+
change_alloc_size(super.bluefs_max_alloc_size[BDEV_DB],
752+
cct->_conf->bluefs_alloc_size, alloc_size_changed);
753+
change_alloc_size(super.bluefs_max_alloc_size[BDEV_SLOW],
754+
shared_alloc_size, alloc_size_changed);
734755
} else {
735756
alloc_size[BDEV_DB] = shared_alloc_size;
736757
alloc_size[BDEV_SLOW] = 0;
758+
change_alloc_size(super.bluefs_max_alloc_size[BDEV_DB],
759+
shared_alloc_size, alloc_size_changed);
737760
}
738761
logger->set(l_bluefs_db_alloc_unit, alloc_size[BDEV_DB]);
739762
logger->set(l_bluefs_slow_alloc_unit, alloc_size[BDEV_SLOW]);
740763
// new wal and db devices are never shared
741764
if (bdev[BDEV_NEWWAL]) {
742765
alloc_size[BDEV_NEWWAL] = cct->_conf->bluefs_alloc_size;
766+
change_alloc_size(super.bluefs_max_alloc_size[BDEV_NEWWAL],
767+
cct->_conf->bluefs_alloc_size, alloc_size_changed);
743768
}
769+
if (alloc_size_changed) {
770+
dout(1) << __func__ << " alloc_size changed, the new super is:" << super << dendl;
771+
_write_super(BDEV_DB);
772+
}
773+
774+
alloc_size_changed = false;
744775
if (bdev[BDEV_NEWDB]) {
745776
alloc_size[BDEV_NEWDB] = cct->_conf->bluefs_alloc_size;
777+
change_alloc_size(super.bluefs_max_alloc_size[BDEV_NEWDB],
778+
cct->_conf->bluefs_alloc_size, alloc_size_changed);
779+
}
780+
if (alloc_size_changed) {
781+
dout(1) << __func__ << " alloc_size changed, the new super is:" << super << dendl;
782+
_write_super(BDEV_NEWDB);
746783
}
747784

748785
for (unsigned id = 0; id < bdev.size(); ++id) {
749786
if (!bdev[id]) {
750787
continue;
751788
}
752789
ceph_assert(bdev[id]->get_size());
790+
ceph_assert(super.bluefs_max_alloc_size[id]);
753791
if (is_shared_alloc(id)) {
754792
dout(1) << __func__ << " shared, id " << id << std::hex
755793
<< ", capacity 0x" << bdev[id]->get_size()
@@ -769,10 +807,11 @@ void BlueFS::_init_alloc()
769807
<< ", capacity 0x" << bdev[id]->get_size()
770808
<< ", reserved 0x" << block_reserved[id]
771809
<< ", block size 0x" << alloc_size[id]
810+
<< ", max alloc size 0x" << super.bluefs_max_alloc_size[id]
772811
<< std::dec << dendl;
773812
alloc[id] = Allocator::create(cct, cct->_conf->bluefs_allocator,
774813
bdev[id]->get_size(),
775-
alloc_size[id],
814+
super.bluefs_max_alloc_size[id],
776815
name);
777816
alloc[id]->init_add_free(
778817
block_reserved[id],
@@ -992,6 +1031,7 @@ int BlueFS::mount()
9921031

9931032
_init_alloc();
9941033

1034+
dout(5) << __func__ << " super: " << super << dendl;
9951035
r = _replay(false, false);
9961036
if (r < 0) {
9971037
derr << __func__ << " failed to replay log: " << cpp_strerror(r) << dendl;

src/os/bluestore/bluefs_types.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <algorithm>
55
#include "bluefs_types.h"
6+
#include "BlueFS.h"
67
#include "common/Formatter.h"
78
#include "include/denc.h"
89
#include "include/uuid.h"
@@ -74,22 +75,26 @@ void bluefs_layout_t::generate_test_instances(list<bluefs_layout_t*>& ls)
7475
}
7576

7677
// bluefs_super_t
78+
bluefs_super_t::bluefs_super_t() : version(0), block_size(4096) {
79+
bluefs_max_alloc_size.resize(BlueFS::MAX_BDEV, 0);
80+
}
7781

7882
void bluefs_super_t::encode(bufferlist& bl) const
7983
{
80-
ENCODE_START(2, 1, bl);
84+
ENCODE_START(3, 1, bl);
8185
encode(uuid, bl);
8286
encode(osd_uuid, bl);
8387
encode(version, bl);
8488
encode(block_size, bl);
8589
encode(log_fnode, bl);
8690
encode(memorized_layout, bl);
91+
encode(bluefs_max_alloc_size, bl);
8792
ENCODE_FINISH(bl);
8893
}
8994

9095
void bluefs_super_t::decode(bufferlist::const_iterator& p)
9196
{
92-
DECODE_START(2, p);
97+
DECODE_START(3, p);
9398
decode(uuid, p);
9499
decode(osd_uuid, p);
95100
decode(version, p);
@@ -98,6 +103,11 @@ void bluefs_super_t::decode(bufferlist::const_iterator& p)
98103
if (struct_v >= 2) {
99104
decode(memorized_layout, p);
100105
}
106+
if (struct_v >= 3) {
107+
decode(bluefs_max_alloc_size, p);
108+
} else {
109+
std::fill(bluefs_max_alloc_size.begin(), bluefs_max_alloc_size.end(), 0);
110+
}
101111
DECODE_FINISH(p);
102112
}
103113

@@ -108,6 +118,8 @@ void bluefs_super_t::dump(Formatter *f) const
108118
f->dump_unsigned("version", version);
109119
f->dump_unsigned("block_size", block_size);
110120
f->dump_object("log_fnode", log_fnode);
121+
for (auto& p : bluefs_max_alloc_size)
122+
f->dump_unsigned("max_alloc_size", p);
111123
}
112124

113125
void bluefs_super_t::generate_test_instances(list<bluefs_super_t*>& ls)
@@ -125,6 +137,7 @@ ostream& operator<<(ostream& out, const bluefs_super_t& s)
125137
<< " v " << s.version
126138
<< " block_size 0x" << std::hex << s.block_size
127139
<< " log_fnode 0x" << s.log_fnode
140+
<< " max_alloc_size " << s.bluefs_max_alloc_size
128141
<< std::dec << ")";
129142
}
130143

src/os/bluestore/bluefs_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ struct bluefs_super_t {
219219

220220
std::optional<bluefs_layout_t> memorized_layout;
221221

222-
bluefs_super_t()
223-
: version(0),
224-
block_size(4096) { }
222+
std::vector<uint64_t> bluefs_max_alloc_size;
223+
224+
bluefs_super_t();
225225

226226
uint64_t block_mask() const {
227227
return ~((uint64_t)block_size - 1);

0 commit comments

Comments
 (0)