]>
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 const std::string
& name
) :
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 for (auto i
= old_size
; i
< extents
->size(); ++i
) {
40 auto& e
= (*extents
)[i
];
41 ldout(cct
, 10) << __func__
42 << " extent: 0x" << std::hex
<< e
.offset
<< "~" << e
.length
43 << "/" << alloc_unit
<< "," << max_alloc_size
<< "," << hint
46 return int64_t(allocated
);
49 void BitmapAllocator::release(
50 const interval_set
<uint64_t>& release_set
)
52 for (auto r
: release_set
) {
53 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< r
.first
<< "~" << r
.second
56 _free_l2(release_set
);
57 ldout(cct
, 10) << __func__
<< " done" << dendl
;
61 void BitmapAllocator::init_add_free(uint64_t offset
, uint64_t length
)
63 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< offset
<< "~" << length
66 auto mas
= get_min_alloc_size();
67 uint64_t offs
= round_up_to(offset
, mas
);
68 uint64_t l
= p2align(offset
+ length
- offs
, mas
);
71 ldout(cct
, 10) << __func__
<< " done" << dendl
;
73 void BitmapAllocator::init_rm_free(uint64_t offset
, uint64_t length
)
75 ldout(cct
, 10) << __func__
<< " 0x" << std::hex
<< offset
<< "~" << length
77 auto mas
= get_min_alloc_size();
78 uint64_t offs
= round_up_to(offset
, mas
);
79 uint64_t l
= p2align(offset
+ length
- offs
, mas
);
80 _mark_allocated(offs
, l
);
81 ldout(cct
, 10) << __func__
<< " done" << dendl
;
84 void BitmapAllocator::shutdown()
86 ldout(cct
, 1) << __func__
<< dendl
;
90 void BitmapAllocator::dump()
92 // bin -> interval count
93 std::map
<size_t, size_t> bins_overall
;
94 collect_stats(bins_overall
);
95 auto it
= bins_overall
.begin();
96 while (it
!= bins_overall
.end()) {
97 ldout(cct
, 0) << __func__
98 << " bin " << it
->first
99 << "(< " << byte_u_t((1 << (it
->first
+ 1)) * get_min_alloc_size()) << ")"
100 << " : " << it
->second
<< " extents"
106 void BitmapAllocator::dump(std::function
<void(uint64_t offset
, uint64_t length
)> notify
)
108 size_t alloc_size
= get_min_alloc_size();
109 auto multiply_by_alloc_size
= [alloc_size
, notify
](size_t off
, size_t len
) {
110 notify(off
* alloc_size
, len
* alloc_size
);
112 std::lock_guard
lck(lock
);
113 l1
.dump(multiply_by_alloc_size
);