]>
git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/BitmapAllocator.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "BitmapAllocator.h"
6 #define dout_context cct
7 #define dout_subsys ceph_subsys_bluestore
9 #define dout_prefix *_dout << "fbmap_alloc " << this << " "
11 BitmapAllocator::BitmapAllocator(CephContext
* _cct
,
14 std::string_view name
) :
15 Allocator(name
, capacity
, alloc_unit
),
18 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< capacity
<< "/"
19 << alloc_unit
<< std::dec
<< dendl
;
20 _init(capacity
, alloc_unit
, false);
23 int64_t BitmapAllocator::allocate(
24 uint64_t want_size
, uint64_t alloc_unit
, uint64_t max_alloc_size
,
25 int64_t hint
, PExtentVector
*extents
)
27 uint64_t allocated
= 0;
28 size_t old_size
= extents
->size();
29 ldout(cct
, 10) << __func__
<< std::hex
<< " 0x" << want_size
30 << "/" << alloc_unit
<< "," << max_alloc_size
<< "," << hint
34 _allocate_l2(want_size
, alloc_unit
, max_alloc_size
, hint
,
39 if (cct
->_conf
->subsys
.should_gather
<dout_subsys
, 10>()) {
40 for (auto i
= old_size
; i
< extents
->size(); ++i
) {
41 auto& e
= (*extents
)[i
];
42 ldout(cct
, 10) << __func__
43 << " extent: 0x" << std::hex
<< e
.offset
<< "~" << e
.length
44 << "/" << alloc_unit
<< "," << max_alloc_size
<< "," << hint
48 return int64_t(allocated
);
51 void BitmapAllocator::release(
52 const interval_set
<uint64_t>& release_set
)
54 if (cct
->_conf
->subsys
.should_gather
<dout_subsys
, 10>()) {
55 for (auto& [offset
, len
] : release_set
) {
56 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< offset
<< "~" << len
58 ceph_assert(offset
+ len
<= (uint64_t)device_size
);
61 _free_l2(release_set
);
62 ldout(cct
, 10) << __func__
<< " done" << dendl
;
66 void BitmapAllocator::init_add_free(uint64_t offset
, uint64_t length
)
68 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< offset
<< "~" << length
71 auto mas
= get_min_alloc_size();
72 uint64_t offs
= round_up_to(offset
, mas
);
73 uint64_t l
= p2align(offset
+ length
- offs
, mas
);
74 ceph_assert(offs
+ l
<= (uint64_t)device_size
);
77 ldout(cct
, 10) << __func__
<< " done" << dendl
;
79 void BitmapAllocator::init_rm_free(uint64_t offset
, uint64_t length
)
81 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< offset
<< "~" << length
83 auto mas
= get_min_alloc_size();
84 uint64_t offs
= round_up_to(offset
, mas
);
85 uint64_t l
= p2align(offset
+ length
- offs
, mas
);
86 ceph_assert(offs
+ l
<= (uint64_t)device_size
);
87 _mark_allocated(offs
, l
);
88 ldout(cct
, 10) << __func__
<< " done" << dendl
;
91 void BitmapAllocator::shutdown()
93 ldout(cct
, 1) << __func__
<< dendl
;
97 void BitmapAllocator::dump()
99 // bin -> interval count
100 std::map
<size_t, size_t> bins_overall
;
101 collect_stats(bins_overall
);
102 auto it
= bins_overall
.begin();
103 while (it
!= bins_overall
.end()) {
104 ldout(cct
, 0) << __func__
105 << " bin " << it
->first
106 << "(< " << byte_u_t((1 << (it
->first
+ 1)) * get_min_alloc_size()) << ")"
107 << " : " << it
->second
<< " extents"