]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/BitmapAllocator.cc
update ceph source to reef 18.1.2
[ceph.git] / 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
3
4 #include "BitmapAllocator.h"
5
6 #define dout_context cct
7 #define dout_subsys ceph_subsys_bluestore
8 #undef dout_prefix
9 #define dout_prefix *_dout << "fbmap_alloc " << this << " "
10
11 BitmapAllocator::BitmapAllocator(CephContext* _cct,
12 int64_t capacity,
13 int64_t alloc_unit,
14 std::string_view name) :
15 Allocator(name, capacity, alloc_unit),
16 cct(_cct)
17 {
18 ldout(cct, 10) << __func__ << " 0x" << std::hex << capacity << "/"
19 << alloc_unit << std::dec << dendl;
20 _init(capacity, alloc_unit, false);
21 }
22
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)
26 {
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
31 << std::dec << dendl;
32
33
34 _allocate_l2(want_size, alloc_unit, max_alloc_size, hint,
35 &allocated, extents);
36 if (!allocated) {
37 return -ENOSPC;
38 }
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
45 << std::dec << dendl;
46 }
47 }
48 return int64_t(allocated);
49 }
50
51 void BitmapAllocator::release(
52 const interval_set<uint64_t>& release_set)
53 {
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
57 << std::dec << dendl;
58 ceph_assert(offset + len <= (uint64_t)device_size);
59 }
60 }
61 _free_l2(release_set);
62 ldout(cct, 10) << __func__ << " done" << dendl;
63 }
64
65
66 void BitmapAllocator::init_add_free(uint64_t offset, uint64_t length)
67 {
68 ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
69 << std::dec << dendl;
70
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);
75
76 _mark_free(offs, l);
77 ldout(cct, 10) << __func__ << " done" << dendl;
78 }
79 void BitmapAllocator::init_rm_free(uint64_t offset, uint64_t length)
80 {
81 ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
82 << std::dec << dendl;
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;
89 }
90
91 void BitmapAllocator::shutdown()
92 {
93 ldout(cct, 1) << __func__ << dendl;
94 _shutdown();
95 }
96
97 void BitmapAllocator::dump()
98 {
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"
108 << dendl;
109 ++it;
110 }
111 }