From: Joshua Blanch Date: Tue, 3 Mar 2026 05:44:00 +0000 (+0000) Subject: os/bluestore: make Allocator::device_size atomic and protect BitmapAllocator::expand X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=36d005e02d29a6b42840d46bb3b6170a81b38328;p=ceph.git os/bluestore: make Allocator::device_size atomic and protect BitmapAllocator::expand Signed-off-by: Joshua Blanch --- diff --git a/src/os/bluestore/Allocator.h b/src/os/bluestore/Allocator.h index df563764330..000c7471ef8 100644 --- a/src/os/bluestore/Allocator.h +++ b/src/os/bluestore/Allocator.h @@ -13,6 +13,7 @@ #ifndef CEPH_OS_BLUESTORE_ALLOCATOR_H #define CEPH_OS_BLUESTORE_ALLOCATOR_H +#include #include #include #include "include/ceph_assert.h" @@ -84,19 +85,19 @@ public: virtual const std::string& get_name() const = 0; int64_t get_capacity() const { - return device_size; + return device_size.load(); } int64_t get_block_size() const { return block_size; } virtual void expand(int64_t new_size){ - ceph_assert(new_size >= device_size); - device_size = new_size; + ceph_assert(new_size >= device_size.load()); + device_size.store(new_size); } protected: - int64_t device_size = 0; + std::atomic device_size{0}; const int64_t block_size = 0; }; diff --git a/src/os/bluestore/BitmapAllocator.cc b/src/os/bluestore/BitmapAllocator.cc index 8c59c2b1dd0..09cc78f2eed 100644 --- a/src/os/bluestore/BitmapAllocator.cc +++ b/src/os/bluestore/BitmapAllocator.cc @@ -57,7 +57,7 @@ void BitmapAllocator::release( for (auto& [offset, len] : release_set) { ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << len << std::dec << dendl; - ceph_assert(offset + len <= (uint64_t)device_size); + ceph_assert(offset + len <= (uint64_t)device_size.load()); } } _free_l2(release_set); @@ -73,7 +73,7 @@ void BitmapAllocator::init_add_free(uint64_t offset, uint64_t length) auto mas = get_min_alloc_size(); uint64_t offs = round_up_to(offset, mas); uint64_t l = p2align(offset + length - offs, mas); - ceph_assert(offs + l <= (uint64_t)device_size); + ceph_assert(offs + l <= (uint64_t)device_size.load()); _mark_free(offs, l); ldout(cct, 10) << __func__ << " done" << dendl; @@ -85,13 +85,14 @@ void BitmapAllocator::init_rm_free(uint64_t offset, uint64_t length) auto mas = get_min_alloc_size(); uint64_t offs = round_up_to(offset, mas); uint64_t l = p2align(offset + length - offs, mas); - ceph_assert(offs + l <= (uint64_t)device_size); + ceph_assert(offs + l <= (uint64_t)device_size.load()); _mark_allocated(offs, l); ldout(cct, 10) << __func__ << " done" << dendl; } void BitmapAllocator::expand(int64_t new_size) { + std::lock_guard l(expand_lock); int64_t old_size = get_capacity(); ceph_assert(new_size >= old_size); diff --git a/src/os/bluestore/BitmapAllocator.h b/src/os/bluestore/BitmapAllocator.h index 65976eb3c8a..3961af228f6 100644 --- a/src/os/bluestore/BitmapAllocator.h +++ b/src/os/bluestore/BitmapAllocator.h @@ -16,6 +16,7 @@ class BitmapAllocator : public AllocatorBase, public AllocatorLevel02 { CephContext* cct; + ceph::mutex expand_lock = ceph::make_mutex("BitmapAllocator::expand_lock"); public: BitmapAllocator(CephContext* _cct, int64_t capacity, int64_t alloc_unit, std::string_view name);