]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/BitmapAllocator.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / os / bluestore / BitmapAllocator.cc
CommitLineData
a8e16298
TL
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
11BitmapAllocator::BitmapAllocator(CephContext* _cct,
12 int64_t capacity,
eafe8130 13 int64_t alloc_unit,
20effc67 14 std::string_view name) :
f67539c2 15 Allocator(name, capacity, alloc_unit),
a8e16298
TL
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
23int64_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;
81eedcae 28 size_t old_size = extents->size();
a8e16298
TL
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 }
20effc67
TL
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 }
a8e16298
TL
47 }
48 return int64_t(allocated);
49}
50
51void BitmapAllocator::release(
52 const interval_set<uint64_t>& release_set)
53{
20effc67
TL
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 }
a8e16298
TL
60 }
61 _free_l2(release_set);
62 ldout(cct, 10) << __func__ << " done" << dendl;
63}
64
65
66void 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();
11fdf7f2
TL
72 uint64_t offs = round_up_to(offset, mas);
73 uint64_t l = p2align(offset + length - offs, mas);
20effc67 74 ceph_assert(offs + l <= (uint64_t)device_size);
a8e16298
TL
75
76 _mark_free(offs, l);
77 ldout(cct, 10) << __func__ << " done" << dendl;
78}
79void 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();
11fdf7f2
TL
84 uint64_t offs = round_up_to(offset, mas);
85 uint64_t l = p2align(offset + length - offs, mas);
20effc67 86 ceph_assert(offs + l <= (uint64_t)device_size);
a8e16298
TL
87 _mark_allocated(offs, l);
88 ldout(cct, 10) << __func__ << " done" << dendl;
89}
90
91void BitmapAllocator::shutdown()
92{
93 ldout(cct, 1) << __func__ << dendl;
94 _shutdown();
95}
96
97void 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}
eafe8130
TL
112
113void BitmapAllocator::dump(std::function<void(uint64_t offset, uint64_t length)> notify)
114{
115 size_t alloc_size = get_min_alloc_size();
116 auto multiply_by_alloc_size = [alloc_size, notify](size_t off, size_t len) {
117 notify(off * alloc_size, len * alloc_size);
118 };
119 std::lock_guard lck(lock);
120 l1.dump(multiply_by_alloc_size);
121}