@@ -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;
0 commit comments